0

In Bash I'd just:

$ openssl s_client -connect www.example.com:443 </dev/null 2>/dev/null | grep 'subject'

But I want to do it elegantly in ruby.

Thanks,

Amir Mehler
  • 4,140
  • 3
  • 27
  • 36

1 Answers1

1

You can accomplish what you are trying to do with the built-in OpenSSL Ruby module.

Specifically you can use the SSLSocket class to retrieve the certificate as a X509:Certificate object, which has an accessor for subject.

The example code found here is very close to what you are trying to do.

bkan
  • 1,183
  • 12
  • 14
  • This works great! unless the server is using unsupported TLS versions, but that's another matter, discussed here: http://stackoverflow.com/questions/25814210/opensslsslsslerror-ssl-connect-syscall-returned-5-errno-0-state-sslv3-read – Amir Mehler Aug 17 '15 at 13:52