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

Download of pkcs12 / pfx not recognized by Windows with MVC rewrite #7703

Closed
2 tasks done
mimugmail opened this issue Aug 1, 2024 · 11 comments
Closed
2 tasks done

Download of pkcs12 / pfx not recognized by Windows with MVC rewrite #7703

mimugmail opened this issue Aug 1, 2024 · 11 comments
Assignees
Labels
bug Production bug
Milestone

Comments

@mimugmail
Copy link
Member

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

Describe the bug

Hi, I have a Firewall here with 24.7_9 and when I download a certificate as pfx with a password and double click in Windows, I get an error like enclosed (before even typing a password):

image

Seems it's marked as wrong type somewhere

To Reproduce

see above

Expected behavior

A clear and concise description of what you expected to happen.

Describe alternatives you considered

A clear and concise description of any alternative solutions or workaround you considered.

Screenshots

Se above

Relevant log files

If applicable, information from log files supporting your claim.

Additional context

Add any other context about the problem here.

Environment

Software version used and hardware type if relevant, e.g.:

Versions
OPNsense 24.7_9-amd64
FreeBSD 14.1-RELEASE-p2
OpenSSL 3.0.14

@AdSchellevis
Copy link
Member

same as #7251 ?

@Weltherrscher
Copy link

Weltherrscher commented Aug 3, 2024

No, not the same, i have a similar issue:
An exported p12 from WebUI can't be read with OpenSSL 1.1.1w and 3.3.1 under windows.
(Didn't try Linux by now.)

Steps to reproduce:

  1. Export the internally used certificate (generated on the OPNsense) as PKCS12 in the WebUI
  2. Import the file into the Keystore Explorer under Windows, actually doesn't matter, as it's a Java application
  3. Error message: file corrupt or password incorrect (it WAS correct, tried 4 times)

Tried a workaround:

  1. Exported the certificate and key in PEM format from the OPNsense
  2. Using OpenSSL (under Windows) created a PKCS12 with the cert.pem, key.pem and the same password as above
  3. Imported the file into the Keystore Explorer
  4. Works.

Also, example output from OpenSSL -info for three different generated p12 files:
cert.p12 -> Export from WebUI
bundle_v1.1.p12 -> exported PEMs combined with openssl 1.1.1w
bundle_v3.p12 -> exported PEMs combined with openssl 3.3.1

openssl -info:
e:\Progs\Security\openssl-3\x64\bin>openssl pkcs12 -info -in cert.p12
B47E0000:error:0680007B:asn1 encoding routines:ASN1_get_object:header too long:..\crypto\asn1\asn1_lib.c:105:

e:\Progs\Security\openssl-3\x64\bin>openssl pkcs12 -info -in bundle_v1.1.p12
Enter Import Password:

MAC: sha1, Iteration 2048
MAC length: 20, salt length: 8
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048
Error outputting keys and certificates
E4680000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:..\crypto\evp\evp_fetch.c:355:Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()

e:\Progs\Security\openssl-3\x64\bin>openssl pkcs12 -info -in bundle_v3.p12
Enter Import Password:

MAC: sha256, Iteration 2048
MAC length: 32, salt length: 8
PKCS7 Encrypted data: PBES2, PBKDF2, AES-256-CBC, Iteration 2048, PRF hmacWithSHA256
Certificate bag
Bag Attributes
localKeyID: 57 3C ... 60 87
subject=C=DE, blah blubb server-rsa
issuer=C=DE, blah blubb -ca
-----BEGIN CERTIFICATE-----
MIIHaDkBFg9pdEBhbHRlbmhlaW0uaXQxHjAc...

cert.p12 on OpenSSL 1.1.1w:
e:\Progs\Security\openssl-1.1\x64\bin>openssl pkcs12 -info -in cert.p12
6968:error:0D07207B:asn1 encoding routines:ASN1_get_object:header too long:..\crypto\asn1\asn1_lib.c:101:

@AdSchellevis AdSchellevis self-assigned this Aug 3, 2024
@AdSchellevis
Copy link
Member

I don't see anything weird in our code, but there seems to be something off here, we're using the standard functions offered by php to create these.

if (!openssl_pkcs12_export($certificate, $result['payload'], $private_key, $passphrase, $options)) {

@AdSchellevis AdSchellevis added the bug Production bug label Aug 3, 2024
@AdSchellevis
Copy link
Member

Ok, this was quite unexpected. the endpoint offers the right data, but then the browser seems to return something "random" . b3aa910 should prevent this from happening.

opnsense-patch b3aa910

@Weltherrscher
Copy link

Weltherrscher commented Aug 3, 2024

That was quick! =)

Confirmed working:
cert_new.p12 -> new export from OPNsense (base64)
cert_new_d.p12 -> decoded base64 cert

e:\Progs\Security\openssl-3\x64\bin>openssl pkcs12 -info -in cert_new.p12
702E0000:error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:..\crypto\asn1\tasn_dec.c:1194:
702E0000:error:0688010A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:..\crypto\asn1\tasn_dec.c:349:Type=PKCS12

e:\Progs\Security\openssl-3\x64\bin>openssl pkcs12 -info -in cert_new_d.p12
Enter Import Password:

MAC: sha256, Iteration 2048
MAC length: 32, salt length: 8
PKCS7 Encrypted data: PBES2, PBKDF2, AES-256-CBC, Iteration 2048, PRF hmacWithSHA256
Certificate bag
Bag Attributes
localKeyID: 57 3C ... 60 87
friendlyName: blah (RSA)
subject=C=DE, blahblubb-server-rsa
issuer=C=DE, blahblubb-ca
-----BEGIN CERTIFICATE-----
MIIHaDCCBw+gAwIBAgIBAjAKBggqhkjOPQQ...

Also, Keystore Explorer accepts the base64 decoded cert.

Thank you!

@AdSchellevis
Copy link
Member

@Weltherrscher thanks for confirming, will likely be released in the next minor

@fichtner fichtner added this to the 25.1 milestone Aug 3, 2024
fichtner pushed a commit that referenced this issue Aug 5, 2024
…lob. closes #7703

It looks like out atob() resulted in sending broken data back to the client, the easiest way to prevent this is to keep our endpoint b64 encoded data as is and let the client handle it.
Accoring to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs, we should be able to suffix ;base64 in these cases.

While here, also make sure the result status is as expected.

(cherry picked from commit b3aa910)
AdSchellevis added a commit that referenced this issue Aug 5, 2024
…lob. closes #7703

It looks like out atob() resulted in sending broken data back to the client, the easiest way to prevent this is to keep our endpoint b64 encoded data as is and let the client handle it.
Accoring to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs, we should be able to suffix ;base64 in these cases.

While here, also make sure the result status is as expected.
@dorianborovina
Copy link

Is this fix included in the OPNsense 24.7.3_1?

@fichtner
Copy link
Member

It was fixed in 24.7.1 already.

@dorianborovina
Copy link

dorianborovina commented Aug 30, 2024

The reason I'm asking is because I'm having issues importing the downloaded .p12 from the WebUI on the MacOS client.
Whatever I do, I'm getting the wrong password error even though the Microsoft Certificate Import Wizard accepts the password.
Tried both RSA and ECDSA, tried with complex, simple and no password at all.
Just wanted to double-check before I dive in the OpenSSL command line. :)

@fichtner
Copy link
Member

Some of this incompatibility is because of OpenSSL 1.1 vs. 3.0 defaults. Can't do much more in community scope than mention this.

@dorianborovina
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Production bug
Development

No branches or pull requests

5 participants