Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.3k
Truststore#3409
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
Open
lovelydinosaur
wants to merge
21
commits into
masterChoose a base branch
from
tomchristie-patch-1
base:master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+26
−67
Open
Truststore #3409
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3769c56
Truststore
lovelydinosaur 9bcb36a
Requirements
lovelydinosaur d861e9c
Update pyproject.toml
lovelydinosaur b413005
Python versions
lovelydinosaur 83fbd71
Update _config.py
lovelydinosaur c1a88bc
Update README.md
lovelydinosaur 15ffaf9
Update test_config.py
lovelydinosaur cc72d34
Update test_config.py
lovelydinosaur 3933a88
Update test_config.py
lovelydinosaur 2f220ec
Update ssl.md
lovelydinosaur 8bff380
Update ssl.md
lovelydinosaur 4321f00
Update ssl.md
lovelydinosaur e49cc07
Update ssl.md
lovelydinosaur 218db9b
Update ssl.md
lovelydinosaur 670a156
Update README.md
lovelydinosaur 5560472
Update docs/advanced/ssl.md
lovelydinosaur 92d9295
Update CHANGELOG.md
lovelydinosaur 2d2eab7
Update CHANGELOG.md
lovelydinosaur 4e1c691
Update CHANGELOG.md
lovelydinosaur 6c483c9
Merge branch 'master' into tomchristie-patch-1
lovelydinosaur ad5234f
Update docs/advanced/ssl.md
lovelydinosaur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,42 @@ | ||
| When making a request over HTTPS, HTTPX needs to verify the identity of the requested host. To do this, it uses a bundle of SSL certificates (a.k.a. CA bundle) delivered by a trusted certificate authority (CA). | ||
| When making a request over HTTPS we need to verify the identity of the requested host. We rely on the [`truststore`](https://truststore.readthedocs.io/en/latest/) package to load the system certificates, ensuring that `httpx` has the same behaviour on SSL sites as your browser. | ||
| ### Enabling and disabling verification | ||
| ### SSL verification | ||
| By default httpx will verify HTTPS connections, and raise an error for invalid SSL cases... | ||
| ```pycon | ||
| ```python | ||
| >>> httpx.get("https://expired.badssl.com/") | ||
| httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997) | ||
| ``` | ||
| You can disable SSL verification completely and allow insecure requests... | ||
| If you're confident that you want to visit a site with an invalid certificate you can disable SSL verification completely... | ||
| ```pycon | ||
| ```python | ||
| >>> httpx.get("https://expired.badssl.com/", verify=False) | ||
| <Response [200 OK]> | ||
| ``` | ||
| ### Configuring client instances | ||
| ### Custom SSL configurations | ||
| If you're using a `Client()` instance you should pass any `verify=<...>` configuration when instantiating the client. | ||
| If you're using a `Client()` instance you can pass the `verify=<...>` configuration when instantiating the client. | ||
| By default the [certifi CA bundle](https://certifiio.readthedocs.io/en/latest/) is used for SSL verification. | ||
| ```python | ||
| >>> client = httpx.Client(verify=True) | ||
| ``` | ||
| For more complex configurations you can pass an [SSL Context](https://docs.python.org/3/library/ssl.html) instance... | ||
| ```python | ||
| import certifi | ||
| import httpx | ||
| import ssl | ||
lovelydinosaur marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| import certifi | ||
| # This SSL context is equivelent to the default `verify=True`. | ||
| # Use certifi for certificate validation, rather than the system truststore. | ||
| ctx = ssl.create_default_context(cafile=certifi.where()) | ||
| client = httpx.Client(verify=ctx) | ||
| ``` | ||
| Using [the `truststore` package](https://truststore.readthedocs.io/) to support system certificate stores... | ||
| ```python | ||
| import ssl | ||
| import truststore | ||
| import httpx | ||
| # Use system certificate stores. | ||
| ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
| client = httpx.Client(verify=ctx) | ||
| ``` | ||
| Loding an alternative certificate verification store using [the standard SSL context API](https://docs.python.org/3/library/ssl.html)... | ||
| ```python | ||
| import httpx | ||
| import ssl | ||
| # Use an explicitly configured certificate store. | ||
| ctx = ssl.create_default_context(cafile="path/to/certs.pem") # Either cafile or capath. | ||
| client = httpx.Client(verify=ctx) | ||
| ``` | ||
| ### Client side certificates | ||
| Client side certificates allow a remote server to verify the client. They tend to be used within private organizations to authenticate requests to remote servers. | ||
| @@ -71,9 +51,9 @@ client = httpx.Client(verify=ctx) | ||
| ### Working with `SSL_CERT_FILE` and `SSL_CERT_DIR` | ||
| Unlike `requests`, the `httpx` package does not automatically pull in [the environment variables `SSL_CERT_FILE` or `SSL_CERT_DIR`](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_default_verify_paths.html). If you want to use these they need to be enabled explicitly. | ||
| Unlike `requests`, the `httpx` package does not automatically pull in [the environment variables `SSL_CERT_FILE` or `SSL_CERT_DIR`](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_default_verify_paths.html). | ||
| For example... | ||
| These environment variables shouldn't be necessary since they're obsoleted by `truststore`. They can be enabled if required like so... | ||
| ```python | ||
| # Use `SSL_CERT_FILE` or `SSL_CERT_DIR` if configured. | ||
| @@ -87,7 +67,7 @@ client = httpx.Client(verify=ctx) | ||
| ### Making HTTPS requests to a local server | ||
| When making requests to local servers, such as a development server running on `localhost`, you will typically be using unencrypted HTTP connections. | ||
| When making requests to local servers such as a development server running on `localhost`, you will typically be using unencrypted HTTP connections. | ||
| If you do need to make HTTPS connections to a local server, for example to test an HTTPS-only service, you will need to create and use your own certificates. Here's one way to do it... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.