Last active
January 9, 2017 22:49
-
-
Save Sudrien/36d47d68671949e75cb51e35f8bbf19f to your computer and use it in GitHub Desktop.
Test https certificates in ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#all variables are strings, not files. | |
# private server key (ssl_server_key) | |
# maybe with passcode (ssl_passcode) | |
begin | |
if ssl_passcode.blank? | |
OpenSSL::PKey::RSA.new(ssl_server_key) | |
else | |
OpenSSL::PKey::RSA.new(ssl_server_key, ssl_passcode) | |
end | |
return "Server key valid." | |
rescue => e | |
return e.message | |
end | |
#intermediate certificate (ssl_intermediate) | |
begin | |
OpenSSL::X509::Certificate.new(ssl_intermediate) | |
return "Intermediate Certificate valid" | |
rescue => e | |
return e.message | |
end | |
#public certificate stack (ssl_crt) | |
begin | |
d = OpenSSL::X509::Certificate.new(ssl_crt) | |
OpenSSL::X509::Store.new.tap { |store| | |
store.set_default_paths | |
store.add_cert OpenSSL::X509::Certificate.new(ssl_intermediate) | |
}.verify(d) | |
return "Certificate valid" | |
rescue => e | |
return e.message | |
end | |
#public certificate stack WITH Private server key | |
begin | |
d = OpenSSL::X509::Certificate.new(ssl_crt) | |
OpenSSL::X509::Store.new.tap { |store| | |
store.set_default_paths | |
store.add_cert OpenSSL::X509::Certificate.new(ssl_intermediate) | |
} | |
???? | |
return "All Certificates valid" | |
rescue => e | |
return e.message | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment