nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.59k stars 1.47k forks source link

httpclient ssl options issue #24394

Open vchettur opened 1 week ago

vchettur commented 1 week ago

Description

When I type the example under the std/httpclient (https://nim-lang.org/docs/httpclient.html#sslslashtls-support):

import httpclient var client = newHttpClient(sslContext=newContext(verifyMode=CVerifyPeer))

I get the following: undeclared identifier: 'newContext' candidates (edit distance, scope distance); see '--spellSuggest': (3, 3): 'getContent'nim(nimsuggest chk) undeclared identifier: 'newContext'

candidates (edit distance, scope distance); see '--spellSuggest': (3, 3): 'getContent' t1.newContext: Error Type Compilation gives me the same error.

Nim Version

version 2.2

Current Output

No response

Expected Output

No response

Known Workarounds

No response

Additional Information

No response

metagn commented 1 week ago

You will also have to compile with ssl defined like so: nim c -d:ssl ....

Did you enable -d:ssl?

vchettur commented 1 week ago

You will also have to compile with ssl defined like so: nim c -d:ssl ....

Did you enable -d:ssl?

Yes. I'm compiling with -d:ssl. Nim syntax check highlights it even before compilation in VS Code. The newHttpClient() works fine without 'verifyMode=CVerifyPeer'

I was trying to actually use the option because I wanted to use CVerifyNone since I was having trouble with one specific trusted site of my client with which I get: Error: error:14004410:SSL routines:CONNECT_CR_SRVR_HELLO:sslv3 alert handshake failure

vchettur commented 1 week ago

I also tested with the puppy library, curl, and the site works fine. Also works fine with python's request library.

Here is an example link for testing with the httpclient library: http://epe.lac-bac.gc.ca/100/201/300/519_magazine/2021/31-519Jan2021.pdf

metagn commented 1 week ago

The example is wrong, net needs to be imported as well.

vchettur commented 1 week ago

The example is wrong, net needs to be imported as well.

Thank you for your assistance.

A. The team might also want to check nimsuggest. While it is now compiling after importing std/net, the VSCode extension gives a misleading squiggly mark: undeclared identifier: 'newContext' candidates (edit distance, scope distance); see '--spellSuggest': (3, 6): 'SslContext' (3, 6): 'getContent'nim(nimsuggest chk) undeclared identifier: 'newContext'

candidates (edit distance, scope distance); see '--spellSuggest': (3, 6): 'SslContext' (3, 6): 'getContent' mbtest.downloadFile.newContext: Error Type

Screenshot 2024-10-31 at 7 55 52 PM

B. It still doesn't resolve my handshake issue with the specific site. If you have any suggestions, I would be grateful.

nim compile -d:release -d:ssl --mm:orc --verbosity:1 --hints:off --run "/Users/vinodchettur/nim-workspace/Examples/malebolgia/mbtest.nim" Starting concurrent downloads...

Download Results:

http://epe.lac-bac.gc.ca/100/201/300/519_magazine/2018/1-519July2018.pdf Error: error:14004410:SSL routines:CONNECT_CR_SRVR_HELLO:sslv3 alert handshake failure ✗ http://epe.lac-bac.gc.ca/100/201/300/519_magazine/2018/2-519August2018.pdf Error: error:14004410:SSL routines:CONNECT_CR_SRVR_HELLO:sslv3 alert handshake failure ✗ http://epe.lac-bac.gc.ca/100/201/300/519_magazine/2018/3-519September2018.pdf Error: error:14004410:SSL routines:CONNECT_CR_SRVR_HELLO:sslv3 alert handshake failure \nTotal time: 0.30s Success rate: 0/3 (0.0%)

[Done] exited with code=0 in 0.475 seconds

C. Other sites give successful results with the same code. nim compile -d:release -d:ssl --mm:orc --verbosity:1 --hints:off --run "/Users/vinodchettur/nim-workspace/Examples/malebolgia/mbtestv1.nim" Starting concurrent downloads...

Download Results:

https://www.erudit.org/fr/revues/aequitas/2024-v30-n1-aequitas09438/1112353ar.pdf -> 1112353ar.pdf Duration: 0.52s ✓ https://www.erudit.org/fr/revues/aequitas/2024-v30-n1-aequitas09438/1112354ar.pdf -> 1112354ar.pdf Duration: 0.52s ✓ https://www.erudit.org/fr/revues/aequitas/2024-v30-n1-aequitas09438/1112355ar.pdf -> 1112355ar.pdf Duration: 1.18s \nTotal time: 1.18s Success rate: 3/3 (100.0%)

metagn commented 1 week ago

While it is now compiling after importing std/net, the VSCode extension gives a misleading squiggly mark:

This is because the extension does not enable -d:ssl by itself, you can fix it by using a config file that defines -d:ssl: https://nim-lang.org/docs/nimc.html#compiler-usage-configuration-files, https://nim-lang.org/docs/nims.html.

I don't know much about your problem, you could try the other options mentioned in the docs for newContext: https://nim-lang.org/docs/net.html#newContext%2Cstring%2Cstring%2Cstring%2Cstring.

vchettur commented 1 week ago

Thank you once again. I will try to resolve my issue one way or the other. My code works with the puppy library so I have a fallback option.

vchettur commented 1 week ago

One last comment. There seems to be an issue that I could not resolve with that particular site. I tried different options with httpclient using newContext(protVersion = protSSLv23, verifyMode = CVerifyNone) and different protVersions and none of them worked. I imported std/net and compiled with -d:ssl.

http://epe.lac-bac.gc.ca/100/201/300/519_magazine/2018/1-519July2018.pdf Error: error:14004410:SSL routines:CONNECT_CR_SRVR_HELLO:sslv3 alert handshake failure

No issues with Puppy library, Curly library or curl with Nim.

I also tested that site with libcurl and C, requests and python, reqwests and Rust, net/http and Go and there was no issue at all.