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

Issue imporitng certificates created using OpenSSL::PKCS12 on macOS devices #654

Closed
ravinderrana opened this issue Jul 24, 2023 · 2 comments

Comments

@ravinderrana
Copy link

ravinderrana commented Jul 24, 2023

Hi!

Am having issue with certificates created using OpenSSL::PKCS12 which need to be installed on macOS devices.

Ruby Version: 3.2.2
System OpenSSL Version: OpenSSL 3.0.2 15 Mar 2022
Ruby OpenSSL Gem Version: 3.1.0

Code:

private_key = OpenSSL::PKey::RSA.new 2048
x509_cert = OpenSSL::X509::Certificate.new
x509_cert.public_key = private_key.public_key
signed_cert = x509_cert.sign(private_key, OpenSSL::Digest::SHA256.new)
File.binwrite('/tmp/my-certificate.p12', OpenSSL::PKCS12.create('123456', 'My Cert', private_key, signed_cert).to_der)

Info dump from “openssl pkcs12 -info -in /tmp/my-certificate.p12” shows that the certificate is generated with:

MAC: sha256, Iteration 2048
MAC length: 32, salt length: 8

Seems macOS have issues with hash function HMAC and only SHA1 is supported. Using older version of either Ruby's OpenSSL gem (tested with 2.1.4) or older System's OpenSSL version (Tested with OpenSSL 1.1.1f 31 Mar 2020) seems to work as it generates certificate with:

MAC: sha1, Iteration 1
MAC length: 20, salt length: 8

Following didn't worked as well:

File.binwrite('/tmp/my-certificate.p12', OpenSSL::PKCS12.create('123456', 'My Cert', private_key, signed_cert, nil, "PBE-SHA1-3DES", "PBE-SHA1-RC2-40", nil, 1).to_der)

What should we use to generate the certificate with MAC as SHA1 and iteration 1. Any help will be highly appreciated.

@ravinderrana ravinderrana changed the title Issue with certificates created using OpenSSL::PKCS12 and imported on macOS devices Issue imporitng certificates created using OpenSSL::PKCS12 on macOS devices Jul 24, 2023
@ravinderrana
Copy link
Author

Found similar issue reported for one of Python's cryptography package

There they've added support to set different PBES choices as well as set KDF rounds and MAC algorithm. Here's the relevant PR

Not sure if we need similar approach here or if there is any alternative that we can go with.

@rhenium
Copy link
Member

rhenium commented Aug 4, 2023

Following didn't worked as well:

File.binwrite('/tmp/my-certificate.p12', OpenSSL::PKCS12.create('123456', 'My Cert', private_key, signed_cert, nil, "PBE-SHA1-3DES", "PBE-SHA1-RC2-40", nil, 1).to_der)

The issue is with RC2. OpenSSL::PKCS12.create fails because OpenSSL >= 3.0 implements RC2 in its legacy provider and it's not enabled by default.

Please see #611.

@rhenium rhenium closed this as completed Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants