-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update macsesh documentation and session types for release.
- Loading branch information
1 parent
e5d7311
commit fbb222b
Showing
6 changed files
with
124 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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 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 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,48 +1,40 @@ | ||
"""This package allows requests to verify certs with the macOS keychain | ||
It uses any trusted certs from keychains included in the current | ||
user's keychain search list, as well as the system roots. Typically, | ||
this is the user's default at ~/Library/Keychains/login.keychain, | ||
the system keychain at /Library/Keychains/System.keychain, and the | ||
System Roots keychain at | ||
/System/Library/Keychains/SystemRootCertificates.keychain. | ||
To achieve this, one of three different strategies can be employed: | ||
1. KeychainSession uses a custom SSLContext, requests Adapter, and | ||
requests Session, and injects the SSLContext into urllib3. This | ||
approach is the recommendation. | ||
2. SecureTransportSession uses the urllib3 contrib module for injecting | ||
SecureTransport equivalents into stock urllib3. While this approach | ||
uses more of the native networking framework, it also seems to be | ||
written primarily with the goal of solving the issues with macOS and | ||
aging OpenSSL versions to ensure that Macs could still use pip. | ||
Therefore, it's not entirely feature-complete in providing a full | ||
requests Adapter. It's definitely worth experimenting with. | ||
3. SimpleKeychainSession circumvents the normal flow of session | ||
startup, and tells the SSLContext to load its trust information | ||
early; in this case from certs dumped from the keychain. | ||
Example Usage: | ||
"""MacSesh | ||
This package allows the popular requests library to use the macOS | ||
keychain for both validating a server, and for doing client cert auth. | ||
Its original use-case was for Mac admins wanting to use python requests | ||
and certs provided by an MDM for TLS, Specifically, SCEP certs client | ||
cert auth and x509 payloads for server validation. | ||
## Example Usage: | ||
Validate using a trusted cert from the keychain: | ||
``` | ||
>>> import macsesh | ||
>>> sesh = macsesh.KeychainSession() | ||
>>> sesh = macsesh.Session() | ||
>>> response = sesh.get('https://nethack.org') | ||
``` | ||
Note: if you want to revert to "normal" requests (probably using | ||
certifi), in the same python process, you'll need to remove this | ||
module's injected stuff from urllib3: | ||
If you want to use the "basic" requests API without creating a session: | ||
``` | ||
>>> macsesh.extract_from_urllib3() | ||
>>> macsesh.inject_into_requests() | ||
>>> requests.get('https://en.wikipedia.org/wiki/Taco') # Uses keychain | ||
``` | ||
Finally, any certs added to the keychains after starting a session will | ||
not be available. The sessions and adapters all have an update_truststore | ||
method for re-dumping the trust. | ||
Client cert auth: | ||
``` | ||
>>> import macsesh | ||
>>> sesh = macsesh.Session() | ||
>>> response = sesh.get('https://nethack.org', cert='My Identity Cert') | ||
``` | ||
""" | ||
from .keychain import get_trusted_certs, get_truststore_data, get_system_roots | ||
|
||
|
||
from .injected_adapter import KeychainAdapter, KeychainContext | ||
from .keychain import get_trusted_certs, get_truststore_data, get_system_roots | ||
from .secure_transport_adapter import SecureTransportAdapter | ||
from .session import KeychainSession, SecureTransportSession, SimpleKeychainSession | ||
from .session import KeychainSession, Session, SimpleKeychainSession | ||
from .simple_adapter import SimpleKeychainAdapter | ||
from .util import extract_from_urllib3, inject_into_requests, extract_from_requests | ||
from .version import __version__ |
This file contains 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 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 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 +1 @@ | ||
__version__ = '0.2.1' | ||
__version__ = '0.3.0' |