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

pkcs12.serialize_key_and_certificates does not produce a valid PKCS #12 client certificate bundle in cryptography >= 43.0.0 #11927

Open
blackm0re opened this issue Nov 10, 2024 · 8 comments
Labels
Stale waiting-on-reporter Issue is waiting on a reply from the reporter. It will be automatically cloesd if there is no reply.

Comments

@blackm0re
Copy link

Tested Python versions 3.11, 3.12
Tested cryptography versions: 42.0.8, 43.0.0, 43.0.0.3
cffi 1.17.1
setuptools 74.1.3
pip 24.2

Installing:
python -m venv venvC43
source venvC43/bin/activate
pip install cryptography==

Reproducing:
Running the attached code
pkcs12_example.py.txt
using cryptography >= 43.0.0 completes without error. The resulting bundle is rejected (after prompting and receiving correct password) by Mozilla Firefox and Google Chrome with the following error message:

"The PKCS #12 operation failed for unknown reasons"

Running exactly the same code with cryptography 42.0.8 produces a bundle that is accepted by the browsers.

@alex
Copy link
Member

alex commented Nov 10, 2024

I'm almost positive this is because they do not support the default encryption mode, as documented: https://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/#cryptography.hazmat.primitives.serialization.pkcs12.serialize_key_and_certificates

You can follow the example to use PBESv1SHA1And3KeyTripleDESCBC instead.

@alex alex added the waiting-on-reporter Issue is waiting on a reply from the reporter. It will be automatically cloesd if there is no reply. label Nov 10, 2024
@blackm0re
Copy link
Author

blackm0re commented Nov 10, 2024

I get exactly the same result when using the exact example above (pkcs12.PBES.PBESv1SHA1And3KeyTripleDESCBC):
Works with 42.0.8, does not work with 43.0.3

No Windows or MacOS involved either.

I see that the serialization code went through some refactoring 4 months ago.

@alex
Copy link
Member

alex commented Nov 10, 2024 via email

@blackm0re
Copy link
Author

blackm0re commented Nov 11, 2024

After performing the following steps:
git clone https://github.com/pyca/cryptography.git
cd cryptography
python -m build .

Getting:
Built wheel for abi3 Python ≥ 3.7 to /tmp/build-via-sdist-url3g36u/cryptography-44.0.0.dev1/target/wheels/cryptography-44.0.0.dev1-cp37-abi3-linux_x86_64.whl
/tmp/build-via-sdist-url3g36u/cryptography-44.0.0.dev1/target/wheels/cryptography-44.0.0.dev1-cp37-abi3-linux_x86_64.whl
Successfully built cryptography-44.0.0.dev1.tar.gz and cryptography-44.0.0.dev1-cp37-abi3-linux_x86_64.whl

Then:
python -m venv venvCDev
source venvCDev/bin/activate
pip install dist/cryptography-44.0.0.dev1-cp37-abi3-linux_x86_64.whl

The above code runs and produces a valid bundle (both with pkcs12.PBES.PBESv1SHA1And3KeyTripleDESCBC and pkcs12.PBES.PBESv2SHA256AndAES256CBC)

@alex
Copy link
Member

alex commented Nov 11, 2024

Ok, I think that means that b5a312f is the fix. It'll be included in the next release.

@blackm0re
Copy link
Author

Good news :)
Which release would that be? 44.0.0 or 43.0.4?

@alex
Copy link
Member

alex commented Nov 12, 2024

44.0

Copy link

This issue has been waiting for a reporter response for 3 days. It will be auto-closed if no activity occurs in the next 5 days.

@github-actions github-actions bot added the Stale label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale waiting-on-reporter Issue is waiting on a reply from the reporter. It will be automatically cloesd if there is no reply.
Development

No branches or pull requests

2 participants