From abac35e7437dd1ac2b3687dfa51de7f9d4b6e853 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 8 Feb 2021 13:54:03 +0100 Subject: basic cleanups regarding SSL handling (#16940) [backport:1.0] * basic cleanups regarding SSL handling * enabled certificate checking on Windows * updated the SSL test * quoting helps --- lib/pure/net.nim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/pure/net.nim') diff --git a/lib/pure/net.nim b/lib/pure/net.nim index c59babba7..4504170e8 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -626,11 +626,13 @@ when defineSsl: discard newCTX.SSLCTXSetMode(SSL_MODE_AUTO_RETRY) newCTX.loadCertificates(certFile, keyFile) - when not defined(nimDisableCertificateValidation) and not defined(windows): + const VerifySuccess = 1 # SSL_CTX_load_verify_locations returns 1 on success. + + when not defined(nimDisableCertificateValidation): if verifyMode != CVerifyNone: # Use the caDir and caFile parameters if set if caDir != "" or caFile != "": - if newCTX.SSL_CTX_load_verify_locations(caFile, caDir) != 0: + if newCTX.SSL_CTX_load_verify_locations(caFile, caDir) != VerifySuccess: raise newException(IOError, "Failed to load SSL/TLS CA certificate(s).") else: @@ -638,7 +640,7 @@ when defineSsl: # the SSL_CERT_FILE and SSL_CERT_DIR env vars var found = false for fn in scanSSLCertificates(): - if newCTX.SSL_CTX_load_verify_locations(fn, "") == 0: + if newCTX.SSL_CTX_load_verify_locations(fn, nil) == VerifySuccess: found = true break if not found: -- cgit 1.4.1-2-gfad0