How to get certificate issuer name in Ruby

Viewed 188

I am trying to figure out how to correctly get the issuer name of er.lazada.sg as reflected in google chrome as shown in the screenshot below: enter image description here

I have attempted to use the ruby code below, but its output is not identical. It shows GlobalSign instead of Encryption Everywhere.

# Get OpenSSL context
ctx = OpenSSL::SSL::SSLContext.new

# Get remote TCP socket
sock = TCPSocket.new('er.lazada.sg', 443)

# pass that socket to OpenSSL
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)

# establish connection, if possible
ssl.connect

# get peer certificate and do things with it
cert = ssl.peer_cert
cert.version
cert.issuer

# The output is #<OpenSSL::X509::Name CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE>

I have attempted to get the issuer name via python and it successfully got "Encryption Everywhere".

import ssl, socket

hostname = 'er.lazada.sg'

ctx = ssl.create_default_context()

with ctx.wrap_socket(socket.socket(), server_hostname=hostname) as s:
    s.connect((hostname, 443))
    cert = s.getpeercert()

subject = dict(x[0] for x in cert['subject'])

issued_to = subject['commonName']

issuer = dict(x[0] for x in cert['issuer'])

issued_by = issuer['commonName']

# The output is {'countryName': 'US', 'organizationName': 'DigiCert Inc', 'organizationalUnitName': 'www.digicert.com', 'commonName': 'Encryption Everywhere DV TLS CA - G1'}

I am wondering why the result is different in the two languages and how can I get the correct issuer name in Ruby...

1 Answers

You need to set the server hostname used for SNI.

ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
ssl.hostname = 'er.lazada.sg' # Add this line
Related