sslcheck 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/acceptance/client_spec.rb +42 -1
- data/lib/sslcheck/client.rb +34 -12
- data/lib/sslcheck/validators/errors.rb +1 -0
- data/lib/sslcheck/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d4251f26088c6cda3ea58337487f6a775a840f1
|
4
|
+
data.tar.gz: d881012a9c13e3d11e62ac9febba24b4fd6c214d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 085c88e749846da6c9fe93d4e916a12ba96a1b56ba3ab48d64063fdd897f5043a8cda94d8182cdfcf1d8a7a283186839690319168ee06039d396ed3bc26940f8
|
7
|
+
data.tar.gz: ab57c766f1868f5beaaa875cf8079e1ef14f59b2f9c788377a8ead127566be904d1c38929c423d00d31e59a5d63ab7a0b8992ef61a94840caf8b0c435c2e4eae
|
data/README.md
CHANGED
@@ -48,6 +48,18 @@ Are there any errors?
|
|
48
48
|
=> []
|
49
49
|
```
|
50
50
|
|
51
|
+
## Timeouts
|
52
|
+
|
53
|
+
By default, connections to verify a certificate will timeout after 30 seconds. To
|
54
|
+
change this behavior, specify your own timeout, in seconds, on the `SSLCheck::Client`
|
55
|
+
class.
|
56
|
+
|
57
|
+
```
|
58
|
+
SSLCheck::Client.timeout_seconds = 10 # A 10 second timeout
|
59
|
+
check = SSLCheck::Check.new
|
60
|
+
check.check("github.com")
|
61
|
+
```
|
62
|
+
|
51
63
|
What are the details of the certificate?
|
52
64
|
|
53
65
|
The peer certificate found during the check is available with a rich
|
data/acceptance/client_spec.rb
CHANGED
@@ -3,6 +3,10 @@ require 'spec_helper'
|
|
3
3
|
module SSLCheck
|
4
4
|
describe 'Client' do
|
5
5
|
context "Getting Certificates" do
|
6
|
+
before do
|
7
|
+
Client.timeout_seconds = 1
|
8
|
+
end
|
9
|
+
|
6
10
|
context "When Things Go Well" do
|
7
11
|
it 'should have the host name' do
|
8
12
|
sut = Client.new
|
@@ -41,9 +45,10 @@ module SSLCheck
|
|
41
45
|
|
42
46
|
context "When the URL is not a real TLD or gTLD" do
|
43
47
|
it 'should raise a connection error' do
|
48
|
+
Client.timeout_seconds = 1
|
44
49
|
sut = Client.new
|
45
50
|
response = sut.get("https://www.domain.does.not.exist.aljdahkqhb")
|
46
|
-
expect(response.errors.first).to be_a(SSLCheck::Errors::Connection::
|
51
|
+
expect(response.errors.first).to be_a(SSLCheck::Errors::Connection::Timeout)
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
@@ -71,5 +76,41 @@ module SSLCheck
|
|
71
76
|
end
|
72
77
|
end
|
73
78
|
end
|
79
|
+
describe 'Timeout' do
|
80
|
+
before do
|
81
|
+
Client.timeout_seconds = 30
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should use the timeout value when making connections' do
|
85
|
+
expect(Timeout).to receive(:timeout).with(30)
|
86
|
+
sut = Client.new
|
87
|
+
sut.get('https://www.sslinsight.com')
|
88
|
+
end
|
89
|
+
context 'When the timeout is not set' do
|
90
|
+
it 'should default to 30 seconds' do
|
91
|
+
expect(SSLCheck::Client.timeout_seconds).to eq(30)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
context 'overriding the default timeout' do
|
95
|
+
it 'should use the supplied timeout value' do
|
96
|
+
SSLCheck::Client.timeout_seconds = 10
|
97
|
+
expect(SSLCheck::Client.timeout_seconds).to eq(10)
|
98
|
+
end
|
99
|
+
it 'should use the timeout value when making connections' do
|
100
|
+
SSLCheck::Client.timeout_seconds = 10
|
101
|
+
expect(Timeout).to receive(:timeout).with(10)
|
102
|
+
sut = Client.new
|
103
|
+
sut.get('https://www.sslinsight.com')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
context 'When the timeout expires' do
|
107
|
+
it 'should raise a connection error' do
|
108
|
+
SSLCheck::Client.timeout_seconds = 1
|
109
|
+
sut = Client.new
|
110
|
+
response = sut.get("https://www.domain.does.not.exist.aljdahkqhb")
|
111
|
+
expect(response.errors.first).to be_a(SSLCheck::Errors::Connection::Timeout)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
74
115
|
end
|
75
116
|
end
|
data/lib/sslcheck/client.rb
CHANGED
@@ -4,6 +4,16 @@ require 'openssl'
|
|
4
4
|
|
5
5
|
module SSLCheck
|
6
6
|
class Client
|
7
|
+
@@timeout_seconds = 30
|
8
|
+
|
9
|
+
def self.timeout_seconds
|
10
|
+
@@timeout_seconds
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.timeout_seconds=(seconds)
|
14
|
+
@@timeout_seconds = seconds
|
15
|
+
end
|
16
|
+
|
7
17
|
class Response
|
8
18
|
attr_accessor :host_name, :errors
|
9
19
|
|
@@ -34,21 +44,33 @@ module SSLCheck
|
|
34
44
|
|
35
45
|
def get(url)
|
36
46
|
begin
|
37
|
-
|
47
|
+
Timeout::timeout(Client.timeout_seconds) {
|
48
|
+
uri = determine_uri(url)
|
49
|
+
|
50
|
+
sock = TCPSocket.new(uri.host, 443)
|
51
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
52
|
+
ctx.set_params(
|
53
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
54
|
+
:timeout => Client.timeout_seconds,
|
55
|
+
:ssl_timeout => Client.timeout_seconds,
|
56
|
+
)
|
57
|
+
|
58
|
+
ctx.timeout = Client.timeout_seconds
|
59
|
+
ctx.ssl_timeout = Client.timeout_seconds
|
38
60
|
|
39
|
-
|
40
|
-
|
41
|
-
|
61
|
+
@socket = OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |socket|
|
62
|
+
socket.sync_close = true
|
63
|
+
socket.connect
|
64
|
+
@response.host_name = uri.host
|
65
|
+
@response.raw_peer_cert = OpenSSL::X509::Certificate.new(socket.peer_cert)
|
66
|
+
@response.raw_peer_cert_chain = socket.peer_cert_chain
|
67
|
+
end
|
42
68
|
|
43
|
-
|
44
|
-
socket.sync_close = true
|
45
|
-
socket.connect
|
46
|
-
@response.host_name = uri.host
|
47
|
-
@response.raw_peer_cert = OpenSSL::X509::Certificate.new(socket.peer_cert)
|
48
|
-
@response.raw_peer_cert_chain = socket.peer_cert_chain
|
49
|
-
end
|
69
|
+
@socket.sysclose
|
50
70
|
|
51
|
-
|
71
|
+
}
|
72
|
+
rescue Timeout::Error, Errno::ETIMEDOUT
|
73
|
+
@response.errors << SSLCheck::Errors::Connection::Timeout.new({:name => "Timeout Error", :type => :timeout_error, :message => "The connection to #{url} took too long."})
|
52
74
|
rescue SocketError
|
53
75
|
@response.errors << SSLCheck::Errors::Connection::SocketError.new({:name => "Connection Error", :type => :socket_error, :message => "The connection to #{url} failed."})
|
54
76
|
rescue URI::InvalidURIError
|
data/lib/sslcheck/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sslcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clayton Lengel-Zigich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|