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

pkcs7: IndefiniteLength error decoding DER #1046

Closed
jstayton opened this issue May 4, 2023 · 2 comments
Closed

pkcs7: IndefiniteLength error decoding DER #1046

jstayton opened this issue May 4, 2023 · 2 comments

Comments

@jstayton
Copy link

jstayton commented May 4, 2023

Hey 👋🏻

In attempting to decode a PKCS#7 message, I'm running into this error:

Error: Error { kind: IndefiniteLength, position: None }

Here's a simple code example with the included PEM:

use der::Decode;
use pkcs7::ContentInfo;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let pem = "\
-----BEGIN PKCS7-----
MIAGCSqGSIb3DQEHAqCAMIACAQExADALBgkqhkiG9w0BBwGggDCCAx8wggIHoAMC
AQICFEhLjcIXE4MNguMD6oLF8ajCWebGMA0GCSqGSIb3DQEBDAUAMFIxCzAJBgNV
BAYTAlVTMRAwDgYDVQQKDAdUcnVlcGljMQ0wCwYDVQQLDARMZW5zMSIwIAYDVQQD
DBlXZWJDbGFpbVNpZ25pbmdDQS1TdGFnaW5nMB4XDTIzMDUwNDEwMjAwOVoXDTI1
MDUwMzEwMjAwOFowQjELMAkGA1UEBhMCVVMxDzANBgNVBAoMBlRlc3QgTzEQMA4G
A1UECwwHVGVzdCBPVTEQMA4GA1UEAwwHVGVzdCBDTjBZMBMGByqGSM49AgEGCCqG
SM49AwEHA0IABCwryo85F/O++GYLlxuu0MYt1pMxak5GXxNDVvXwJkcMqJoKkvmi
wPXiPp+PrggwQTCv+ndudo2UqveGzQWObq+jgccwgcQwDAYDVR0TAQH/BAIwADAf
BgNVHSMEGDAWgBTAPo0ggyDn0pPjAP/m5u7acvZF7DBPBggrBgEFBQcBAQRDMEEw
PwYIKwYBBQUHMAGGM2h0dHA6Ly92YS50cnVlcGljLm5pbmphL2VqYmNhL3B1Ymxp
Y3dlYi9zdGF0dXMvb2NzcDATBgNVHSUEDDAKBggrBgEFBQcDBDAdBgNVHQ4EFgQU
T0nYwB31Cb5u4rDNWrneqS/m7uswDgYDVR0PAQH/BAQDAgWgMA0GCSqGSIb3DQEB
DAUAA4IBAQBGxnl/ofuUapJajVBcb2ykuLRCiQp/IUsd+nSEj7QZ5RCbal3CKvwM
uPQxD12z/VVpmYFa4FLW7J0LNqAFiePKl18l1r7RgY0H40xZLq0nQZJ5bSK6t6J4
3tCymUG+JvcZUqsBfyu57H7CzJqbfOWQbjqutleUyaq2PWTVl17rYl+cIusXFRT0
d8v276vM21y3DA/KoVvjf91T62a1ngHsIfA2wR0rcOn7+0wHm8Bcd3yp/kspVnri
Wn4eLAB/J4WFNALqEeFNyeKZ/saOXVGKCyWzPrTVl2sagpzWxYnqhwe33ZWlpO7T
zubtBhFr8/SIWeVHiT19OeeF/d0aUWWjAAAxAAAAAAAAAA==
-----END PKCS7-----";

    let (_type, der) = pem_rfc7468::decode_vec(pem.as_bytes()).unwrap();

    let content = ContentInfo::from_der(der.as_slice())?;

    dbg!(content);

    Ok(())
}

OpenSSL seems to be able to parse it:

$ openssl pkcs7 -in pkcs7.pem -print_certs
subject=/C=US/O=Test O/OU=Test OU/CN=Test CN
-----BEGIN CERTIFICATE-----
MIIDHzCCAgegAwIBAgIUSEuNwhcTgw2C4wPqgsXxqMJZ5sYwDQYJKoZIhvcNAQEM
BQAwUjELMAkGA1UEBhMCVVMxEDAOBgNVBAoMB1RydWVwaWMxDTALBgNVBAsMBExl
bnMxIjAgBgNVBAMMGVdlYkNsYWltU2lnbmluZ0NBLVN0YWdpbmcwHhcNMjMwNTA0
MTAyMDA5WhcNMjUwNTAzMTAyMDA4WjBCMQswCQYDVQQGEwJVUzEPMA0GA1UECgwG
VGVzdCBPMRAwDgYDVQQLDAdUZXN0IE9VMRAwDgYDVQQDDAdUZXN0IENOMFkwEwYH
KoZIzj0CAQYIKoZIzj0DAQcDQgAELCvKjzkX8774ZguXG67Qxi3WkzFqTkZfE0NW
9fAmRwyomgqS+aLA9eI+n4+uCDBBMK/6d252jZSq94bNBY5ur6OBxzCBxDAMBgNV
HRMBAf8EAjAAMB8GA1UdIwQYMBaAFMA+jSCDIOfSk+MA/+bm7tpy9kXsME8GCCsG
AQUFBwEBBEMwQTA/BggrBgEFBQcwAYYzaHR0cDovL3ZhLnRydWVwaWMubmluamEv
ZWpiY2EvcHVibGljd2ViL3N0YXR1cy9vY3NwMBMGA1UdJQQMMAoGCCsGAQUFBwME
MB0GA1UdDgQWBBRPSdjAHfUJvm7isM1aud6pL+bu6zAOBgNVHQ8BAf8EBAMCBaAw
DQYJKoZIhvcNAQEMBQADggEBAEbGeX+h+5RqklqNUFxvbKS4tEKJCn8hSx36dISP
tBnlEJtqXcIq/Ay49DEPXbP9VWmZgVrgUtbsnQs2oAWJ48qXXyXWvtGBjQfjTFku
rSdBknltIrq3onje0LKZQb4m9xlSqwF/K7nsfsLMmpt85ZBuOq62V5TJqrY9ZNWX
XutiX5wi6xcVFPR3y/bvq8zbXLcMD8qhW+N/3VPrZrWeAewh8DbBHStw6fv7TAeb
wFx3fKn+SylWeuJafh4sAH8nhYU0AuoR4U3J4pn+xo5dUYoLJbM+tNWXaxqCnNbF
ieqHB7fdlaWk7tPO5u0GEWvz9IhZ5UeJPX0554X93RpRZaM=
-----END CERTIFICATE-----

I see that there's a der::IndefiniteLength type, but I'm not sure how that could be used.

Any help is appreciated!

@tarcieri
Copy link
Member

tarcieri commented May 4, 2023

Unfortunately we lack proper support for BER. It's something I've been meaning to address.

Closing as dup of #779

@tarcieri tarcieri closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2023
@jstayton
Copy link
Author

jstayton commented May 4, 2023

👍🏻 Sorry for the dup!

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

No branches or pull requests

2 participants