openssl: asn1parse: "Error in encoding" in freshly created certificate (all tested OpenSSL versions)
Tested with 1.1.0 tip, but it can be reproduced with 1.0.2h and even OS X bundled 0.9.8zh.
# Error
openssl req -new -subj '/O=1234567890/CN=123456789' -newkey rsa:2048 -nodes -keyout privkey1.pem > example1.csr
openssl x509 -req -in example1.csr -signkey privkey1.pem > example1.crt
# 'Error in encoding' at the end of 'example1.crt.asn1.txt'
# console: '140735153328128:error:0D07209B:asn1 encoding routines:ASN1_get_object:too long:crypto/asn1/asn1_lib.c:90:'
openssl asn1parse -in example1.crt > example1.crt.asn1.txt
# OK
openssl req -new -subj '/O=123456789/CN=123456789' -newkey rsa:2048 -nodes -keyout privkey2.pem > example2.csr
openssl x509 -req -in example2.csr -signkey privkey2.pem > example2.crt
openssl asn1parse -in example2.crt > example2.crt.asn1.txt
The only difference between the two cases is a single (0) character removed from -subj option argument in the second, error-free case. The error happens after dumping the whole ASN.1 structure with no apparent problems.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 38 (21 by maintainers)
Commits related to this issue
- bio_b64.c: prevent base64 filter BIO from decoding out-of-bound data Fixes #5405, #1381 The base64 filter BIO reads its input in chunks of B64_BLOCK_SIZE bytes. When processing input in PEM format i... — committed to mspncp/openssl by mspncp 6 years ago
- bio_b64.c: prevent base64 filter BIO from decoding out-of-bound data Fixes #5405, #1381 The base64 filter BIO reads its input in chunks of B64_BLOCK_SIZE bytes. When processing input in PEM format i... — committed to openssl/openssl by mspncp 6 years ago
- bio_b64.c: prevent base64 filter BIO from decoding out-of-bound data Fixes #5405, #1381 The base64 filter BIO reads its input in chunks of B64_BLOCK_SIZE bytes. When processing input in PEM format i... — committed to openssl/openssl by mspncp 6 years ago
- bio_b64.c: prevent base64 filter BIO from decoding out-of-bound data Fixes #5405, #1381 The base64 filter BIO reads its input in chunks of B64_BLOCK_SIZE bytes. When processing input in PEM format i... — committed to openssl/openssl by mspncp 6 years ago
- bio_b64.c: prevent base64 filter BIO from decoding out-of-bound data Fixes #5405, #1381 The base64 filter BIO reads its input in chunks of B64_BLOCK_SIZE bytes. When processing input in PEM format i... — committed to bernd-edlinger/openssl by mspncp 6 years ago
I think there’s a real bug here, perhaps not a high priority one, but it is likely that either
EVP_DecodeUpdate()incrypto/evp/encode.c, orb64_read()incrypto/evp/bio_b64.cis not quite right. A “-” character is designated asB64_EOFin theEVP_DecodeUpdate()code, but that seems to be forgotten when-----END CERTIFICATE-----or similar is split across an I/O boundary just right.So we can keep the issue open to resolve after the 1.1.0 release. This certainly leads to rather unexpected behaviour.
This seems to work and does not use
asn1parseat all.Tip: built with clang and configured with
enable-asangives a pretty damn accurate crash-trace@vszakats thanks for reporting this issue and for your patience! (which finally is rewarded now 😉 )
@vszakats, using your two scripts from https://github.com/openssl/openssl/issues/1381#issuecomment-237077997, I verified that my patch solves your issue.
Without #5422 (OpenSSL 1.1.0h-dev)
$ opensl version
$ ./ok.sh
$ ./failed.sh
With Patch #5422 (master)
$ openssl version
$ ./ok.sh
$ ./failed.sh