I don't think it's httpClient-related, but I'm quite confused as to what this means.
Basically, I'm using httpClient to download a file:
let got = newHttpClient().getContent(url)
and I get this:
net.nim(506) raiseSSLError
httpclient.nim(891) newConnection
Error: unhandled exception: error:14004410:SSL routines:CONNECT_CR_SRVR_HELLO:sslv3 alert handshake failure [SslError]
What is going on?
I think the issue might be with a specific url - I've tried with http: and https: but to no avail.
Ideas?
For Nim v1.4.0, the proc net.newContext has changed the interface with keys and certificates related files. You have to download the certificates pem files for example here: https://curl.haxx.se/docs/caextract.html and you can do
import httpclient, net
let ctx = newContext(cafile ="cacert.pem")
let client = newHttpClient(sslContext = ctx)
echo client.getContent("https://nim-lang.org")
In case you don't have control with the certificates, you can resort to CVerifyNone , change the context initiation above with let ctx = newContext(verifyMode = CVerifyNone) (this is discouraged but it'll be helpful when in development and you can't be bothered with).
For older Nim version, or any version with newContext hasn't supported selecting the cert, you can workaround like this:
import net, httpclient, openssl
proc setBundle(ctx: SSlCtx, cabundle: cstring) =
discard ctx.SSL_CTX_load_verify_locations(cabundle, nil)
var ctx = newContext()
ctx.context.setBundle("cacert.pem")
var sslClient = newHttpClient(sslContext = ctx)
echo sslClient.getContent("https://nim-lang.org")
The above should handle the value returned from openssl.SSL_CTX_LOAD but I didn't put it in the example. You can see the openssl manual for that. Note that this workaround is only for client, not for server.
Thanks a lot for the input.
Unfortunately, I just tried everything you said and it's still not working.
P.S. I'm by no means an expert at SSL, so I'm a bit ... lost
I tried upgrading via Homebrew too.
Now, I have:
OpenSSL 1.1.1h 22 Sep 2020
However, it's still not working.
Here's the stack trace:
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/httpclient.nim(1095) getContent
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/httpclient.nim(1090) get
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/httpclient.nim(1066) request
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/httpclient.nim(1050) request
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/httpclient.nim(992) requestAux
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/httpclient.nim(887) newConnection
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/net.nim(789) wrapConnectedSocket
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/net.nim(901) socketError
/usr/local/Cellar/nim/1.4.0/nim/lib/pure/net.nim(506) raiseSSLError
Well, I think I've finally "solved" it:
The error had nothing to do, neither with Nim, nor my code, or my local openssl configuration. The problem was with a particular server (I guess).
I was trying to directly download a file from raw.githubusercontent.com...
Simple code:
import httpclient
import nimx/window
var client = newHttpClient()
discard client.get("https://account.api.here.com/oauth2/token")
Getting error:14004410:SSL routines:CONNECT_CR_SRVR_HELLO:sslv3 alert handshake failure [SslError] because ret == 0 after: ret = SSL_connect(socket.sslHandle) but should be ret == 1
But this error happens only in case (3 conditions together):
Please, any suggestions/workaround...
Same issue on [Termux: Android trminal emu]
https://forum.nim-lang.org/t/8345#53796
error: SSL routines:tls_process_server_certificate:certificate verify failed [SslError]
import httpclient
var client = newHttpClient()
echo client.getContent("https://google.com")
c -r -d:ssl httpreq.nim
I would like to know how to set CA on Nim environment.