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

CertFP: The file must be a PKCS #12 archive #254

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

ljrk0
Copy link
Contributor

@ljrk0 ljrk0 commented Jul 11, 2023

While this archive is indeed DER-formatted, in contrast to cert_path, a regular DER file created from some certificate/key PEM file won't work:

openssl x509 -outform der -in foo.pem -out foo.der

This will result in the following OpenSSL error through tls-native error:

error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto/asn1/tasn_dec.c:1188:
error:0688010A:asn1 encoding routines:asn1_d2i_ex_primitive:nested asn1
error:crypto/asn1/tasn_dec.c:752:
error:0688010A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1
error:crypto/asn1/tasn_dec.c:685:Field=version, Type=PKCS12

Instead, a PKCS #12 archive must be created like so:

openssl pkcs12 -export -out foo.p12 -inkey fookey.pem -in foocert.pem

If the PEM file contains both the private key and the certificate, the same file can be passed to openssl twice.

Also compare the documentation for from_pkcs12 to from_der in native-tls, as used in the new_secured_transport function:

https://docs.rs/native-tls/0.2.11/native_tls/struct.Identity.html#method.from_pkcs12

While this archive is indeed DER-formatted, in contrast to `cert_path`,
a regular DER file created from some certificate/key PEM file won't work:

```
openssl x509 -outform der -in foo.pem -out foo.der
```

This will result in the following OpenSSL error through tls-native error:

```
error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto/asn1/tasn_dec.c:1188:
error:0688010A:asn1 encoding routines:asn1_d2i_ex_primitive:nested asn1
error:crypto/asn1/tasn_dec.c:752:
error:0688010A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1
error:crypto/asn1/tasn_dec.c:685:Field=version, Type=PKCS12
```

Instead, a PKCS aatxe#12 archive must be created like so:

```
openssl pkcs12 -export -out foo.p12 -inkey fookey.pem -in foocert.pem
```

If the PEM file contains both the private key and the certificate,
the same file can be passed to `openssl` twice.

Also compare the documentation for `from_pkcs12` to `from_der` in
native-tls, as used in the `new_secured_transport` function:

https://docs.rs/native-tls/0.2.11/native_tls/struct.Identity.html#method.from_pkcs12
@aatxe aatxe merged commit 2eb9bf5 into aatxe:develop Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants