Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpclient ssl options issue #24394

Open
vchettur opened this issue Oct 31, 2024 · 8 comments
Open

httpclient ssl options issue #24394

vchettur opened this issue Oct 31, 2024 · 8 comments
Labels
Documentation Content Related to documentation content (not generation). Standard Library

Comments

@vchettur
Copy link

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
Copy link
Collaborator

metagn commented Oct 31, 2024

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

Did you enable -d:ssl?

@vchettur vchettur changed the title Think about the title, twice. httpclient ssl options issue Oct 31, 2024
@vchettur
Copy link
Author

vchettur commented Oct 31, 2024

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
Copy link
Author

vchettur commented Oct 31, 2024

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
Copy link
Collaborator

metagn commented Oct 31, 2024

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

@metagn metagn added Documentation Content Related to documentation content (not generation). Standard Library labels Oct 31, 2024
@vchettur
Copy link
Author

vchettur commented Nov 1, 2024

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
Copy link
Collaborator

metagn commented Nov 1, 2024

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
Copy link
Author

vchettur commented Nov 1, 2024

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
Copy link
Author

vchettur commented Nov 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Content Related to documentation content (not generation). Standard Library
Projects
None yet
Development

No branches or pull requests

2 participants