I couldn’t find any examples of reading a SSL certificate from a socket connection, so I thought I’d share my approach here. Ultimately, I just wanted to get the X509 certificate information for a few websites that have HTTPS - which this bit of code will do.
The last line creates a hash that contains when the cert became valid, when it will become invalid, who issued it, and whether or not it actually is valid.