Module: OpenSSL::SSL
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
|
Classes:
| |
|
Exceptions:
| |
| Defined in: | ext/openssl/ossl_ssl.c, ext/openssl/lib/openssl/ssl.rb |
Overview
Use SSLContext to set up the parameters for a TLS (former SSL)
connection. Both client and server TLS connections are supported.
SSLSocket may be used in conjunction with a TCPServer and an instance
of SSLContext to set up connections.
Constant Summary
-
OP_ALL =
# File 'ext/openssl/ossl_ssl.c', line 3446UINT64T2NUM(SSL_OP_ALL)
-
OP_ALLOW_CLIENT_RENEGOTIATION =
# File 'ext/openssl/ossl_ssl.c', line 3463UINT64T2NUM(SSL_OP_ALLOW_CLIENT_RENEGOTIATION)
-
OP_ALLOW_NO_DHE_KEX =
# File 'ext/openssl/ossl_ssl.c', line 3469UINT64T2NUM(SSL_OP_ALLOW_NO_DHE_KEX)
-
OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION =
# File 'ext/openssl/ossl_ssl.c', line 3475UINT64T2NUM(SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)
-
OP_CIPHER_SERVER_PREFERENCE =
# File 'ext/openssl/ossl_ssl.c', line 3493UINT64T2NUM(SSL_OP_CIPHER_SERVER_PREFERENCE)
-
OP_CISCO_ANYCONNECT =
# File 'ext/openssl/ossl_ssl.c', line 3531UINT64T2NUM(SSL_OP_CISCO_ANYCONNECT)
-
OP_CLEANSE_PLAINTEXT =
# File 'ext/openssl/ossl_ssl.c', line 3451UINT64T2NUM(SSL_OP_CLEANSE_PLAINTEXT)
-
OP_COOKIE_EXCHANGE =
# File 'ext/openssl/ossl_ssl.c', line 3530UINT64T2NUM(SSL_OP_COOKIE_EXCHANGE)
-
OP_CRYPTOPRO_TLSEXT_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3498UINT64T2NUM(SSL_OP_CRYPTOPRO_TLSEXT_BUG)
-
OP_DISABLE_TLSEXT_CA_NAMES =
# File 'ext/openssl/ossl_ssl.c', line 3466UINT64T2NUM(SSL_OP_DISABLE_TLSEXT_CA_NAMES)
-
OP_DONT_INSERT_EMPTY_FRAGMENTS =
# File 'ext/openssl/ossl_ssl.c', line 3471UINT64T2NUM(SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)
-
OP_ECH_GREASE =
# File 'ext/openssl/ossl_ssl.c', line 3515UINT64T2NUM(SSL_OP_ECH_GREASE)
-
OP_ECH_GREASE_RETRY_CONFIG =
# File 'ext/openssl/ossl_ssl.c', line 3524UINT64T2NUM(SSL_OP_ECH_GREASE_RETRY_CONFIG)
-
OP_ECH_IGNORE_CID =
# File 'ext/openssl/ossl_ssl.c', line 3521UINT64T2NUM(SSL_OP_ECH_IGNORE_CID)
-
OP_ECH_TRIALDECRYPT =
# File 'ext/openssl/ossl_ssl.c', line 3518UINT64T2NUM(SSL_OP_ECH_TRIALDECRYPT)
-
OP_ENABLE_KTLS =
# File 'ext/openssl/ossl_ssl.c', line 3455UINT64T2NUM(SSL_OP_ENABLE_KTLS)
-
OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE =
# File 'ext/openssl/ossl_ssl.c', line 3506UINT64T2NUM(SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE)
-
OP_ENABLE_MIDDLEBOX_COMPAT =
# File 'ext/openssl/ossl_ssl.c', line 3480UINT64T2NUM(SSL_OP_ENABLE_MIDDLEBOX_COMPAT)
-
OP_EPHEMERAL_RSA =
# File 'ext/openssl/ossl_ssl.c', line 3557
Deprecated in
::OpenSSL1.0.1k and 1.0.2.UINT64T2NUM(SSL_OP_EPHEMERAL_RSA)
-
OP_IGNORE_UNEXPECTED_EOF =
# File 'ext/openssl/ossl_ssl.c', line 3460UINT64T2NUM(SSL_OP_IGNORE_UNEXPECTED_EOF)
-
OP_LEGACY_EC_POINT_FORMATS =
# File 'ext/openssl/ossl_ssl.c', line 3512UINT64T2NUM(SSL_OP_LEGACY_EC_POINT_FORMATS)
-
OP_LEGACY_SERVER_CONNECT =
# File 'ext/openssl/ossl_ssl.c', line 3453UINT64T2NUM(SSL_OP_LEGACY_SERVER_CONNECT)
-
OP_MICROSOFT_BIG_SSLV3_BUFFER =
# File 'ext/openssl/ossl_ssl.c', line 3543
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
-
OP_MICROSOFT_SESS_ID_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3535
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_MICROSOFT_SESS_ID_BUG)
-
OP_MSIE_SSLV2_RSA_PADDING =
# File 'ext/openssl/ossl_ssl.c', line 3545
Deprecated in
::OpenSSL0.9.7h and 0.9.8b.UINT64T2NUM(SSL_OP_MSIE_SSLV2_RSA_PADDING)
-
OP_NETSCAPE_CA_DN_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3565
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_NETSCAPE_CA_DN_BUG)
-
OP_NETSCAPE_CHALLENGE_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3537
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_NETSCAPE_CHALLENGE_BUG)
-
OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3567
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
-
OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3539
Deprecated in
::OpenSSL0.9.8q and 1.0.0c.UINT64T2NUM(SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)
-
OP_NO_ANTI_REPLAY =
# File 'ext/openssl/ossl_ssl.c', line 3486UINT64T2NUM(SSL_OP_NO_ANTI_REPLAY)
-
OP_NO_COMPRESSION =
# File 'ext/openssl/ossl_ssl.c', line 3474UINT64T2NUM(SSL_OP_NO_COMPRESSION)
-
OP_NO_ENCRYPT_THEN_MAC =
# File 'ext/openssl/ossl_ssl.c', line 3477UINT64T2NUM(SSL_OP_NO_ENCRYPT_THEN_MAC)
-
OP_NO_EXTENDED_MASTER_SECRET =
# File 'ext/openssl/ossl_ssl.c', line 3448UINT64T2NUM(SSL_OP_NO_EXTENDED_MASTER_SECRET)
-
OP_NO_QUERY_MTU =
# File 'ext/openssl/ossl_ssl.c', line 3529UINT64T2NUM(SSL_OP_NO_QUERY_MTU)
-
OP_NO_RENEGOTIATION =
# File 'ext/openssl/ossl_ssl.c', line 3496UINT64T2NUM(SSL_OP_NO_RENEGOTIATION)
-
OP_NO_RX_CERTIFICATE_COMPRESSION =
# File 'ext/openssl/ossl_ssl.c', line 3503UINT64T2NUM(SSL_OP_NO_RX_CERTIFICATE_COMPRESSION)
-
OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION =
# File 'ext/openssl/ossl_ssl.c', line 3473UINT64T2NUM(SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)
-
OP_NO_SSLv2 =
# File 'ext/openssl/ossl_ssl.c', line 3559
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_NO_SSLv2)
-
OP_NO_SSLv3 =
# File 'ext/openssl/ossl_ssl.c', line 3488UINT64T2NUM(SSL_OP_NO_SSLv3)
-
OP_NO_TICKET =
# File 'ext/openssl/ossl_ssl.c', line 3472UINT64T2NUM(SSL_OP_NO_TICKET)
-
OP_NO_TLSv1 =
# File 'ext/openssl/ossl_ssl.c', line 3489UINT64T2NUM(SSL_OP_NO_TLSv1)
-
OP_NO_TLSv1_1 =
# File 'ext/openssl/ossl_ssl.c', line 3490UINT64T2NUM(SSL_OP_NO_TLSv1_1)
-
OP_NO_TLSv1_2 =
# File 'ext/openssl/ossl_ssl.c', line 3491UINT64T2NUM(SSL_OP_NO_TLSv1_2)
-
OP_NO_TLSv1_3 =
# File 'ext/openssl/ossl_ssl.c', line 3492UINT64T2NUM(SSL_OP_NO_TLSv1_3)
-
OP_NO_TX_CERTIFICATE_COMPRESSION =
# File 'ext/openssl/ossl_ssl.c', line 3500UINT64T2NUM(SSL_OP_NO_TX_CERTIFICATE_COMPRESSION)
-
OP_PKCS1_CHECK_1 =
# File 'ext/openssl/ossl_ssl.c', line 3561
Deprecated in
::OpenSSL1.0.1.UINT64T2NUM(SSL_OP_PKCS1_CHECK_1)
-
OP_PKCS1_CHECK_2 =
# File 'ext/openssl/ossl_ssl.c', line 3563
Deprecated in
::OpenSSL1.0.1.UINT64T2NUM(SSL_OP_PKCS1_CHECK_2)
-
OP_PREFER_NO_DHE_KEX =
# File 'ext/openssl/ossl_ssl.c', line 3509UINT64T2NUM(SSL_OP_PREFER_NO_DHE_KEX)
-
OP_PRIORITIZE_CHACHA =
# File 'ext/openssl/ossl_ssl.c', line 3483UINT64T2NUM(SSL_OP_PRIORITIZE_CHACHA)
-
OP_SAFARI_ECDHE_ECDSA_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3458UINT64T2NUM(SSL_OP_SAFARI_ECDHE_ECDSA_BUG)
-
OP_SINGLE_DH_USE =
# File 'ext/openssl/ossl_ssl.c', line 3555
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_SINGLE_DH_USE)
-
OP_SINGLE_ECDH_USE =
# File 'ext/openssl/ossl_ssl.c', line 3553
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_SINGLE_ECDH_USE)
-
OP_SSLEAY_080_CLIENT_DH_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3547
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_SSLEAY_080_CLIENT_DH_BUG)
-
OP_SSLREF2_REUSE_CERT_TYPE_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3541
Deprecated in
::OpenSSL1.0.1h and 1.0.2.UINT64T2NUM(SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG)
-
OP_TLSEXT_PADDING =
# File 'ext/openssl/ossl_ssl.c', line 3457UINT64T2NUM(SSL_OP_TLSEXT_PADDING)
-
OP_TLS_BLOCK_PADDING_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3551
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_TLS_BLOCK_PADDING_BUG)
-
OP_TLS_D5_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3549
Deprecated in
::OpenSSL1.1.0.UINT64T2NUM(SSL_OP_TLS_D5_BUG)
-
OP_TLS_ROLLBACK_BUG =
# File 'ext/openssl/ossl_ssl.c', line 3494UINT64T2NUM(SSL_OP_TLS_ROLLBACK_BUG)
-
SSL2_VERSION =
# File 'ext/openssl/ossl_ssl.c', line 3575
SSL2.0INT2NUM(SSL2_VERSION)
-
SSL3_VERSION =
# File 'ext/openssl/ossl_ssl.c', line 3577
SSL3.0INT2NUM(SSL3_VERSION)
-
TLS1_1_VERSION =
# File 'ext/openssl/ossl_ssl.c', line 3581
TLS 1.1
INT2NUM(TLS1_1_VERSION)
-
TLS1_2_VERSION =
# File 'ext/openssl/ossl_ssl.c', line 3583
TLS 1.2
INT2NUM(TLS1_2_VERSION)
-
TLS1_3_VERSION =
# File 'ext/openssl/ossl_ssl.c', line 3585
TLS 1.3
INT2NUM(TLS1_3_VERSION)
-
TLS1_VERSION =
# File 'ext/openssl/ossl_ssl.c', line 3579
TLS 1.0
INT2NUM(TLS1_VERSION)
-
VERIFY_CLIENT_ONCE =
# File 'ext/openssl/ossl_ssl.c', line 3444INT2NUM(SSL_VERIFY_CLIENT_ONCE)
-
VERIFY_FAIL_IF_NO_PEER_CERT =
# File 'ext/openssl/ossl_ssl.c', line 3443INT2NUM(SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
-
VERIFY_NONE =
# File 'ext/openssl/ossl_ssl.c', line 3441INT2NUM(SSL_VERIFY_NONE)
-
VERIFY_PEER =
# File 'ext/openssl/ossl_ssl.c', line 3442INT2NUM(SSL_VERIFY_PEER)
Class Method Summary
- .verify_certificate_identity(cert, hostname) mod_func
- .verify_hostname(hostname, san) mod_func Internal use only
- .verify_wildcard(domain_component, san_component) mod_func Internal use only
Class Method Details
.verify_certificate_identity(cert, hostname) (mod_func)
[ GitHub ]# File 'ext/openssl/lib/openssl/ssl.rb', line 274
def verify_certificate_identity(cert, hostname) should_verify_common_name = true cert.extensions.each{|ext| next if ext.oid != "subjectAltName" ostr = OpenSSL::ASN1.decode(ext.to_der).value.last sequence = OpenSSL::ASN1.decode(ostr.value) sequence.value.each{|san| case san.tag when 2 # dNSName in GeneralName (RFC5280) should_verify_common_name = false return true if verify_hostname(hostname, san.value) when 7 # iPAddress in GeneralName (RFC5280) should_verify_common_name = false if san.value.size == 4 || san.value.size == 16 begin return true if san.value == IPAddr.new(hostname).hton rescue IPAddr::InvalidAddressError end end end } } if should_verify_common_name cert.subject.to_a.each{|oid, value| if oid == "CN" return true if verify_hostname(hostname, value) end } end return false end
.verify_hostname(hostname, san) (mod_func)
# File 'ext/openssl/lib/openssl/ssl.rb', line 307
def verify_hostname(hostname, san) # :nodoc: # RFC 5280, IA5String is limited to the set of ASCII characters return false unless san.ascii_only? return false unless hostname.ascii_only? # See RFC 6125, section 6.4.1 # Matching is case-insensitive. san_parts = san.downcase.split(".") # TODO: this behavior should probably be more strict return san == hostname if san_parts.size < 2 # Matching is case-insensitive. host_parts = hostname.downcase.split(".") # RFC 6125, section 6.4.3, subitem 2. # If the wildcard character is the only character of the left-most # label in the presented identifier, the client SHOULD NOT compare # against anything but the left-most label of the reference # identifier (e.g., *.example.com would match foo.example.com but # not bar.foo.example.com or example.com). return false unless san_parts.size == host_parts.size # RFC 6125, section 6.4.3, subitem 1. # The client SHOULD NOT attempt to match a presented identifier in # which the wildcard character comprises a label other than the # left-most label (e.g., do not match bar.*.example.net). return false unless verify_wildcard(host_parts.shift, san_parts.shift) san_parts.join(".") == host_parts.join(".") end
.verify_wildcard(domain_component, san_component) (mod_func)
# File 'ext/openssl/lib/openssl/ssl.rb', line 340
def verify_wildcard(domain_component, san_component) # :nodoc: parts = san_component.split("*", -1) return false if parts.size > 2 return san_component == domain_component if parts.size <= 1 # RFC 6125, section 6.4.3, subitem 3. # The client SHOULD NOT attempt to match a presented identifier # where the wildcard character is embedded within an A-label or # U-label of an internationalized domain name. return false if domain_component.start_with?("xn--") && san_component != "*" parts[0].length + parts[1].length < domain_component.length && domain_component.start_with?(parts[0]) && domain_component.end_with?(parts[1]) end