I have created a simple script that allows me to retrieve information on a target, however, I would also like to retrieve the elliptic curves supported.
My current script :
require 'openssl'
def connect(sock, ctx, url)
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
ssl.hostname = url
begin
ssl.connect_nonblock
rescue IO::WaitReadable
return nil unless IO.select([ssl], nil, nil, 10)
retry
rescue IO::WaitWritable
return nil unless IO.select(nil, [ssl], nil, 10)
retry
end
ssl
end
ctx = OpenSSL::SSL::SSLContext.new
ctx.max_version = :TLS1_2
hostname = 'www.google.com'
sock = Socket.tcp(hostname, 443, connect_timeout: 10)
connection = connect(sock, ctx, hostname)
return unless connection
puts "Version : #{connection.ssl_version}"
puts "Cipher : #{connection.cipher[0]}"
puts "Ephemeral Key : #{connection.tmp_key.oid}"
In this case, for www.google.com the Ephemeral Key is X25519which corresponds to what I am looking for.
But for some hosts like amazon.com I get the following result :
Version : TLSv1.2
Cipher : ECDHE-RSA-AES128-GCM-SHA256
Ephemeral Key : id-ecPublicKey
While via an SSL analysis on some specialized sites like ssllabs I find well the supported elliptic curve :
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f) ECDH secp256r1 (eq. 3072 bits RSA)
Regards