ssl-test 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21729c3237468056d754aef8e94254d88385a81d
4
+ data.tar.gz: 8d8f3b8ff9f3dbae8bac6d5342af42ed7ba39bd2
5
+ SHA512:
6
+ metadata.gz: 52f5e5b81041aff3c33c97582f2163e3f72052fd541765dd8ec27d37900570109afc6d7f1a496fc95086bbccd7eb6828e86e3a1b127bb6652e9963f625dd423e
7
+ data.tar.gz: 2bb85576cffb6265f3e4b16f846137968ae8ad74fdeda1da9f61a589dfcff26e8d8920f0ed8e69386e3e6c854f4fc4dfec98309e938f0ffc27c9ea1934b60b65
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ssl-test.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Adrien Jarthon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ # SSLTest
2
+
3
+ A small tool to help you test a website's SSL certificate.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ssl-test'
11
+ ```
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install ssl-test
16
+
17
+ ## Usage
18
+
19
+ Simply call the `SSLTest.test` method and it'll return 3 values:
20
+ 1. the validity of the certificate
21
+ 2. the error message (if any)
22
+ 3. the certificate itself
23
+
24
+ Example with good cert:
25
+ ```ruby
26
+ valid, error, cert = SSLTest.test "https://google.com"
27
+ valid # => true
28
+ error # => nil
29
+ cert # => #<OpenSSL::X509::Certificate...>
30
+ ```
31
+
32
+ Example with bad certificate:
33
+ ```ruby
34
+ valid, error, cert = SSLTest.test "https://testssl-expire.disig.sk"
35
+ valid # => false
36
+ error # => "error code 10: certificate has expired"
37
+ cert # => #<OpenSSL::X509::Certificate...>
38
+ ```
39
+
40
+ If the request fails and we're unable to detemine the validity, here are the returned values:
41
+ ```ruby
42
+ valid, error, cert = SSLTest.test "https://thisisdefinitelynotawebsite.com"
43
+ valid # => nil
44
+ error # => "SSL certificate test failed: getaddrinfo: Name or service not known"
45
+ cert # => nil
46
+ ```
47
+
48
+ ## How it works
49
+
50
+ SSLTester simply performs a HEAD request using ruby `net/https` library and verifies the SSL status. It also hooks into the validation process to intercept the raw certificate for you.
51
+
52
+ ### What kind of errors will SSLTest detect
53
+
54
+ Pretty much the same errors `curl` will:
55
+ - Expired certificates
56
+ - Incomplete certificate chain (missing intermediary)
57
+ - Self signed certificates
58
+ - Valid certs used with incorect hostname
59
+
60
+ ### GOTCHA: errors SSLTest will NOT detect
61
+
62
+ There is a spefic kind or error this code will *NOT* detect: *revoked certificates*. This is much more complex to handle because it needs an up to date database of revoked certs to check with. This is implemented in most modern browsers but the results vary greatly (chrome ignores this for example).
63
+
64
+ Here is an example of website with a revoked certificate: https://revoked.grc.com/
65
+
66
+ Any contribution to add this feature is greatly appreciated :)
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it ( https://github.com/[my-github-username]/ssl-test/fork )
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create a new Pull Request
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "test/*_test.rb"
6
+ end
7
+
8
+ desc "Open an irb session preloaded with ssl-test"
9
+ task :console do
10
+ sh "irb -rubygems -I lib -r ssl_test.rb"
11
+ end
12
+
13
+ task default: :test
@@ -0,0 +1,32 @@
1
+ require "net/https"
2
+
3
+ module SSLTest
4
+ VERSION = "0.0.1"
5
+
6
+ def self.test url
7
+ uri = URI.parse(url)
8
+ return if uri.scheme != 'https'
9
+ cert = failed_cert_reason = nil
10
+
11
+ http = Net::HTTP.new(uri.host, uri.port)
12
+ http.use_ssl = true
13
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
14
+ http.verify_callback = -> (verify_ok, store_context) {
15
+ cert = store_context.current_cert
16
+ failed_cert_reason = [store_context.error, store_context.error_string] if !verify_ok
17
+ verify_ok
18
+ }
19
+
20
+ req = Net::HTTP::Head.new('/')
21
+ begin
22
+ res = http.start { http.request(req) }
23
+ return [true, nil, cert]
24
+ rescue OpenSSL::SSL::SSLError => e
25
+ error = e.message
26
+ error = "error code %d: %s" % failed_cert_reason if failed_cert_reason
27
+ return [false, error, cert]
28
+ rescue => e
29
+ return [nil, "SSL certificate test failed: #{e.message}"]
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ssl_test'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ssl-test"
8
+ spec.version = SSLTest::VERSION
9
+ spec.authors = ["Adrien Jarthon"]
10
+ spec.email = ["jobs@adrienjarthon.com"]
11
+ spec.summary = %q{Test website SSL certificate validity}
12
+ spec.homepage = "https://github.com/jarthod/ssl-test"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,50 @@
1
+ require "ssl_test"
2
+ require "minitest/autorun"
3
+
4
+ describe SSLTest do
5
+
6
+ describe '.test' do
7
+ it "returns no error on valid SNI website" do
8
+ valid, error, cert = SSLTest.test("https://www.mycs.com")
9
+ valid.must_equal true
10
+ error.must_be_nil
11
+ cert.must_be_instance_of OpenSSL::X509::Certificate
12
+ end
13
+
14
+ it "returns error on self signed certificate" do
15
+ valid, error, cert = SSLTest.test("https://kernelcoffee.org")
16
+ valid.must_equal false
17
+ error.must_equal "error code 18: self signed certificate"
18
+ cert.must_be_instance_of OpenSSL::X509::Certificate
19
+ end
20
+
21
+ it "returns error on invalid host" do
22
+ valid, error, cert = SSLTest.test("https://staging.updown.io")
23
+ valid.must_equal false
24
+ error.must_equal 'hostname "staging.updown.io" does not match the server certificate'
25
+ cert.must_be_instance_of OpenSSL::X509::Certificate
26
+ end
27
+
28
+ it "returns error on expired cert" do
29
+ valid, error, cert = SSLTest.test("https://testssl-expire.disig.sk")
30
+ valid.must_equal false
31
+ error.must_equal "error code 10: certificate has expired"
32
+ cert.must_be_instance_of OpenSSL::X509::Certificate
33
+ end
34
+
35
+ it "returns undetermined state on unhandled error" do
36
+ valid, error, cert = SSLTest.test("https://pijoinlrfgind.com")
37
+ valid.must_be_nil
38
+ error.must_equal "SSL certificate test failed: getaddrinfo: Name or service not known"
39
+ cert.must_be_nil
40
+ end
41
+
42
+ # Not implemented yet
43
+ # it "returns error on revoked cert" do
44
+ # valid, error, cert = SSLTest.test("https://revoked.grc.com")
45
+ # valid.must_equal false
46
+ # error.must_equal "error code XX: certificate has been revoked"
47
+ # cert.must_be_instance_of OpenSSL::X509::Certificate
48
+ # end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssl-test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adrien Jarthon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - jobs@adrienjarthon.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/ssl_test.rb
54
+ - ssl-test.gemspec
55
+ - test/ssl_test_test.rb
56
+ homepage: https://github.com/jarthod/ssl-test
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Test website SSL certificate validity
80
+ test_files:
81
+ - test/ssl_test_test.rb
82
+ has_rdoc: