Home > Back-end >  Ruby http POST request fails for OpenSSL::SSL::SSLError wrong version number
Ruby http POST request fails for OpenSSL::SSL::SSLError wrong version number

Time:01-19

My app is sending a request to an API, which has now started to return OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=error: wrong version number) error. I checked from https://www.cdn77.com/tls-test that the API supports TLS1.2 and TLS1.3, as it should.

I have tried to use http.ssl_version="TLSv1_2" to force my app to use TLS1.2, but I still get the same SSL error.

I can successfully make a request to that API using curl on my server, but not with Ruby.

I checked openssl s_client -connect eu2.api.concursolutions.com:443 -tls1_2 and it looks ok. At least it looks the same as openssl s_client -connect us2.api.concursolutions.com:443 -tls1_2 and that end point I'm able to request from Ruby.

I tried http.set_debug_output($stdout) in Rails console, but it was not able to provide anything useful, just:

opening connection to eu2.api.concursolutions.com:80...
opened
starting SSL for eu2.api.concursolutions.com:80...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number

Anyone have ideas what to try? Requests from curl and Postman are working, so the issue has to be on my side.

CodePudding user response:

starting SSL for eu2.api.concursolutions.com:80...

This is not the same as

... openssl s_client -connect eu2.api.concursolutions.com:443

In your ruby code you access port 80 but with s_client you access port 443. Port 443 is the port normally used for HTTPS, while 80 is used for plain HTTP. Trying to access plain HTTP with a TLS client results in the kind of strange errors you see.

  • Related