MightyMouse
MightyMouse

Reputation: 13838

node errors: SSL23_GET_SERVER_HELLO:unknown protocol and SSL3_GET_RECORD:wrong version number

Alright, this very same problem has been asked in the past but with no satisfactory answer; at least for my end. Long story short, using curl for posting data to a remote (note: https) server with the following works:

curl -X POST 'https://a.b.c.d/somewhere/' --data 'somedata' --header "Content-Type: text/turtle" -i

Now, the time comes to do the same thing using node. My functions work fine and if instead of using the https module I use the http module I get a message that I have to try again for https. So, I am using https in order to make the request, with the options below:

var myOptions = {
    hostname : "a.b.c.d",
    port     : "80",
    path     : "/somewhere/",
    method   : 'POST',
    headers  : {
        'Content-Type'   : 'text/turtle', 
        'Content-Length' : message.length
        },
    secureProtocol : 'SSLv3_method'
};

where by the way I have also checked that curl works fine when passing the parameter --sslv3.

However, using the above options I get the following error

140735237133072:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:787:

If on top of my code I put a statement of the form (idea from here)

https.globalAgent.options.secureProtocol = 'SSLv3_method';

then actually the error message changes to

140735237133072:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:../deps/openssl/openssl/ssl/s3_pkt.c:338:

I find this unexpected as I have already indicated in the options part that I want SSLv3_method to be used as the protocol. In any case, how would I be able to reproduce the behavior of curl from command line where everything is working?

Finally, here it is mentioned that port 80 might be a wrong port for using it with https. Is this really true? Why would curl work anyway? If it is true, do you know why, or can you point me to the right direction for understanding the problem?

Thanks in advance for all your help!

Upvotes: 0

Views: 3205

Answers (1)

mscdex
mscdex

Reputation: 106726

You should have port: 443, or just leave it unset since 443 is the default port when using the https module, instead of port: "80".

cURL works without a port because it knows that https:// is port 443 by default. You can pass in a url to https.request() as the first argument (like cURL), but then you can't customize method, headers, or anything else that can't be determined from a URL alone.

Upvotes: 4

Related Questions