Closed gfviegas closed 1 month ago
Broke it into 2 comments to avoid the char limit by Github.
UPDATE: Found out that some ciphers were removed from the default list with OTP 27 in #8250
If anyone finds the same issue, you can override it passing the option ciphers: :ssl.cipher_suites(:all, :"tlsv1.2")
or finding out exactly what cipher is missing in your use case.
Thanks!
Describe the bug
:ssl.connect
is connecting succesfully with OTP 26 but it's not working with the same arguments in OTP 27.Im trying to connect to an external web service requiring TLS 1.2 and digital certificates for authentication. After much debugging I noticed all requests from curl, wget and postman were doing just fine but running from OTP not. Then I noticed the SSL connection in OTP was not working properly. After downgrading to OTP 26 it worked as expected.
To Reproduce I tried a SSL connection to a specific host on 3 different machines (in different networks, Linux and MacOS), with OTP 27 and none would connect to it. When using OTP 26 it did.
Expected behavior SSL connection should not be dropped early in OTP 27
Affected versions Tested with 27.0 and 27.1, both affected.
Additional context Sorry, I'm an Elixir engineer here, so sorry for using Interactive Elixir for testing it out.
Here is the reproduction:
Ran the following steps:
and got a
{:error, :closed}
output{:ok, {:sslsocket, {:gen_tcp, #Port<0.4>, :tls_connection, :undefined}, [#PID<0.147.0>, #PID<0.146.0>]}}
output instead. Note: in the very same directory with the same certs and password.Here is the full breakdown and debug logging for both sessions:
Full iEX session with OTP 27
```elixir Erlang/OTP 27 [erts-15.1.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit] Interactive Elixir (1.17.3) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> :ssl.start :ok iex(2)> :ssl.connect('nfe.prefeitura.sp.gov.br', 443, [certfile: 'priv/static/certificates/cert.crt', keyfile: 'priv/static/certificates/cert.key', password: 'REDACTED', verify: :verify_none, versions: [:"tlsv1.2"], log_level: :debug]) >>> TLS 1.2 Handshake, ClientHello [{client_version,{3,3}}, {random, <<103,4,60,130,104,234,111,209,128,76,165,30,187,2,172,17,53,81,43,206, 247,42,202,105,156,135,6,36,45,244,39,49>>}, {session_id,<<>>}, {cookie,undefined}, {cipher_suites, ["TLS_EMPTY_RENEGOTIATION_INFO_SCSV", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_256_CCM","TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8", "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CCM","TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384", "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256", "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384", "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256", "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256"]}, {extensions, #{srp => undefined, signature_algs => {hash_sign_algos, [{sha512,ecdsa}, {sha512,rsa_pss_pss}, {sha512,rsa_pss_rsae}, {sha512,rsa}, {sha384,ecdsa}, {sha384,rsa_pss_pss}, {sha384,rsa_pss_rsae}, {sha384,rsa}, {sha256,ecdsa}, {sha256,rsa_pss_pss}, {sha256,rsa_pss_rsae}, {sha256,rsa}]}, signature_algs_cert => {signature_algorithms_cert, [{sha512,ecdsa}, rsa_pss_pss_sha512,rsa_pss_rsae_sha512, {sha512,rsa}, {sha384,ecdsa}, rsa_pss_pss_sha384,rsa_pss_rsae_sha384, {sha384,rsa}, {sha256,ecdsa}, rsa_pss_pss_sha256,rsa_pss_rsae_sha256, {sha256,rsa}, {sha,rsa}]}, use_srtp => undefined, elliptic_curves => {elliptic_curves, [{1,3,101,110}, {1,3,101,111}, {1,3,132,0,35}, {1,3,36,3,3,2,8,1,1,13}, {1,3,132,0,34}, {1,3,36,3,3,2,8,1,1,11}, {1,2,840,10045,3,1,7}, {1,3,36,3,3,2,8,1,1,7}]}, sni => {sni,"nfe.prefeitura.sp.gov.br"}, max_frag_enum => undefined,alpn => undefined, ec_point_formats => {ec_point_formats,[0]}, next_protocol_negotiation => undefined, renegotiation_info => {renegotiation_info,undefined}}}] 16:54:42.136 [debug] [message: {:client_hello, {3, 3}, <<103, 4, 60, 130, 104, 234, 111, 209, 128, 76, 165, 30, 187, 2, 172, 17, 53, 81, 43, 206, 247, 42, 202, 105, 156, 135, 6, 36, 45, 244, 39, 49>>, "", :undefined, [<<0, 255>>, <<192, 44>>, <<192, 48>>, <<192, 173>>, <<192, 175>>, "̩", "̨", <<192, 43>>, <<192, 47>>, <<192, 172>>, <<192, 174>>, <<192, 46>>, <<192, 50>>, <<192, 45>>, <<192, 49>>, <<0, 159>>, <<0, 163>>, <<0, 158>>, <<0, 162>>, "̪"], %{srp: :undefined, signature_algs: {:hash_sign_algos, [sha512: :ecdsa, sha512: :rsa_pss_pss, sha512: :rsa_pss_rsae, sha512: :rsa, sha384: :ecdsa, sha384: :rsa_pss_pss, sha384: :rsa_pss_rsae, sha384: :rsa, sha256: :ecdsa, sha256: :rsa_pss_pss, sha256: :rsa_pss_rsae, sha256: :rsa]}, signature_algs_cert: {:signature_algorithms_cert, [{:sha512, :ecdsa}, :rsa_pss_pss_sha512, :rsa_pss_rsae_sha512, {:sha512, :rsa}, {:sha384, :ecdsa}, :rsa_pss_pss_sha384, :rsa_pss_rsae_sha384, {:sha384, :rsa}, {:sha256, :ecdsa}, :rsa_pss_pss_sha256, :rsa_pss_rsae_sha256, {:sha256, :rsa}, {:sha, :rsa}]}, use_srtp: :undefined, elliptic_curves: {:elliptic_curves, [{1, 3, 101, 110}, {1, 3, 101, 111}, {1, 3, 132, 0, 35}, {1, 3, 36, 3, 3, 2, 8, 1, 1, 13}, {1, 3, 132, 0, 34}, {1, 3, 36, 3, 3, 2, 8, 1, 1, 11}, {1, 2, 840, 10045, 3, 1, 7}, {1, 3, 36, 3, 3, 2, 8, 1, 1, 7}]}, sni: {:sni, ~c"nfe.prefeitura.sp.gov.br"}, max_frag_enum: :undefined, alpn: :undefined, ec_point_formats: {:ec_point_formats, [0]}, next_protocol_negotiation: :undefined, renegotiation_info: {:renegotiation_info, :undefined}}}, protocol: :handshake, direction: :outbound] writing (213 bytes) TLS 1.2 Record Protocol, handshake 0000 - 16 03 03 00 d0 01 00 00 cc 03 03 67 04 3c 82 68 ...........g.<.h 0010 - ea 6f d1 80 4c a5 1e bb 02 ac 11 35 51 2b ce f7 .o..L......5Q+.. 0020 - 2a ca 69 9c 87 06 24 2d f4 27 31 00 00 28 00 ff *.i...$-.'1..(.. 0030 - c0 2c c0 30 c0 ad c0 af cc a9 cc a8 c0 2b c0 2f .,.0.........+./ 0040 - c0 ac c0 ae c0 2e c0 32 c0 2d c0 31 00 9f 00 a3 .......2.-.1.... 0050 - 00 9e 00 a2 cc aa 01 00 00 7b 00 0b 00 02 01 00 .........{...... 0060 - 00 00 00 1d 00 1b 00 00 18 6e 66 65 2e 70 72 65 .........nfe.pre 0070 - 66 65 69 74 75 72 61 2e 73 70 2e 67 6f 76 2e 62 feitura.sp.gov.b 0080 - 72 00 0a 00 12 00 10 00 1d 00 1e 00 19 00 1c 00 r............... 0090 - 18 00 1b 00 17 00 1a 00 32 00 1c 00 1a 06 03 08 ........2....... 00a0 - 0b 08 06 06 01 05 03 08 0a 08 05 05 01 04 03 08 ................ 00b0 - 09 08 04 04 01 02 01 00 0d 00 1a 00 18 06 03 08 ................ 00c0 - 0b 08 06 06 01 05 03 08 0a 08 05 05 01 04 03 08 ................ 00d0 - 09 08 04 04 01 ..... 16:54:42.140 [debug] [message: [<<22, 3, 3, 0, 208>>, <<1, 0, 0, 204, 3, 3, 103, 4, 60, 130, 104, 234, 111, 209, 128, 76, 165, 30, 187, 2, 172, 17, 53, 81, 43, 206, 247, 42, 202, 105, 156, 135, 6, 36, 45, 244, 39, 49, 0, 0, 40, 0, 255, 192, 44, 192, 48, ...>>], protocol: :record, direction: :outbound] {:error, :closed} ```