-
-
Notifications
You must be signed in to change notification settings - Fork 882
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
How can I use a custom SSLContext / PyOpenSSLContext when creating a Client? #924
Comments
Thanks for bringing this use-case to my attention. Got me thinking how this use case can be reconciled with my other thoughts on safe high level TLS APIs. |
Heya,
Yup, the One thing that I did notice prompted by this ticket, is that even though that's a supported usage, and is type annotated as That's something we should clearly improve. We ought to include a very minimal possible example, such as... >>> import httpx
>>> import ssl
>>> import certifi
>>> context = ssl.create_default_context()
>>> context.load_verify_locations(cafile=certifi.where())
>>> httpx.get('https://www.example.com', verify=context)
<Response [200 OK]>
Could you include a traceback with that? We don't have any instances of |
Thanks for the reply @tomchristie. I went back and did some more tests on httpx 0.12.1 and 0.13.0.dev. It looks like the For
If it helps, I'm using my own internal CA to sign the .p12 certs, and that CA is used by the internal server I'm connecting to. I can get to the internal site using the same .p12 and CA with requests_pkcs12. It's still possible I'm messing up the cafile loading though? Thanks. |
If you want custom SSL context support, we do have that, but you need to be using an We don't have support for Lines 107 to 115 in d34c89a
I'd suggest you start by looking into setting up a custom If there's some capabilities exposed by the third party |
Seconding this, pyopenssl allows the use of loading certificates from memory instead of from disk |
There absolutely is such functionality.
This demonstrates the generation and use of an ssl context which never writes its certs or keys to disk, something that, in all of pythonland, is only possible using pyopenssl, because only pyopenssl uses the cffi bindings to the openssl functionality. important peps were proposed and withdrawn, and to date, we appear to be no closer to loading keys from memory in std python than we were ten years ago. httpx solving for this use case, especially async, would be a big deal, as people usually move to other languages to get this done. |
Checklist
Question
Can I create a
httpx.Client
with my ownssl.SSLContext
orurllib3.contrib.pyopenssl.PyOpenSSLContext
instead of passing in cert/key/verify?Background
I found
httpx
while looking for requests syntax + asyncio support. It looks like a great project, thanks for all the work you've put into it.One very oft-asked feature for
requests.py
was making requests with user-provided SSLContexts 2118. Eventually that was resolved by allowing us to pass SSLContexts to Adapters, then mounting the adapter onto a session. As a real world example, I have used pypki2 and requests_pkcs12 at different times to createSession
's from PKCS12/X509 certificates instead of PEM format that I believe vanillarequests
andhttpx
require. There is a requests_pkcs12 author blog post with more background.My understanding from reading
httpx
documentation is that ahttpx.Client
is roughly similar to arequests.Session
and the Dispatcher API will be roughly similar to Adapters. @tomchristie mentions configuring anssl_context
in 768 - Dispatcher API but I didn't understand how to use that in practice.@sethmlarson suggests
httpx.Client(verify=ssl_context)
in 469, which looked similar to my use-case but not identical. When I tried that withhttpx
0.12.1 and 0.13.0.dev, I gotTypeError: expected str, bytes or os.PathLike object, not PyOpenSSLContext
on Client init.Thanks.
(courtesy tagging @rashley-iqt (requests_pkcs12) and @gershwinlabs (pypki2) )
The text was updated successfully, but these errors were encountered: