Metadata-Version: 2.4
Name: py_cert_store
Version: 0.3.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Dist: cryptography>=44.0.1
Requires-Dist: pythonnet ; extra == 'tests'
Provides-Extra: tests
License-File: LICENSE
License-Expression: Apache-2.0 license
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/unwarymold9171/Py_Cert_Store
Project-URL: Issues, https://github.com/unwarymold9171/Py_Cert_Store/issues

[![CI](https://github.com/unwarymold9171/Py_Cert_Store/actions/workflows/CI.yml/badge.svg)](https://github.com/unwarymold9171/Py_Cert_Store/actions/workflows/CI.yml)
![PyPI](https://img.shields.io/pypi/v/py_cert_store?link=https%3A%2F%2Fpypi.org%2Fproject%2Fpy-cert-store%2F)
<!-- ![PyPI - Downloads](https://img.shields.io/pypi/dm/py_cert_store) -->
<!-- The downloads badge seems to not be working at this time -->

# Python Certificate Store

The Python Certificate Store (Py_Cert_Store) is a module designed with the intention of interacting with the windows certificate store.

The initial design of this module is to find a certificate meeting a set of basic criteria (Not expired, contains an extension, and is exportable).

## Python Implementation

This code is designed to return a certificate that can be utilized when connecting with the python requests library.

```python
from py_cert_store import get_win_cert
from requests import Session
from requests_pkcs12 import Pkcs12Adapter

certificate = get_win_cert()

with Session() as s:
    s.mount('https://example.com', Pkcs12Adapter(pkcs12_data=certificate))
    r = s.get('https://example.com/test')
```

For further selection of a certificate from the windows certificate store 

```python
from py_cert_store import find_windows_cert_by_extension
from cryptography import x509

valid_certificates = find_windows_cert_by_extension(
    store="My", user="CurrentUser",
    extension_oid=x509.OID_KEY_USAGE.dotted_string,
    extension_value="Digital Signature"
)

certificate_with_metadata = valid_certificates[0]

print(f"Using Certificate: {certificate_with_metadata['FriendlyName']}")
print(f"{certificate_with_metadata['Name']}")
print(f"Validity: {certificate_with_metadata['EffectiveDateString']} - {certificate_with_metadata['ExpirationDateString']}")

certificate = certificate_with_metadata["cert"]

...
```
<!-- ```python
``` -->

## Installing

This library is available as [PyPI package](https://pypi.org/project/py-cert-store):

```
pip install py_cert_store
```

Alternatively, you can retrieve the latest development version via Git: (Note: Rust must be installed to run the development branch)

```
git clone https://github.com/unwarymold9171/Py_Cert_Store.git
```

