Ephenodrom / Dart-Basic-Utils

A dart package for many helper methods fitting common situations
MIT License
364 stars 77 forks source link

Pointycastle introduced in 2.7.0 threw exception on some certs #44

Closed certaintls closed 3 years ago

certaintls commented 3 years ago

Before 2.7.0, these lines work:

File file = new File(cert.path); // e.g. on Android "/system/etc/security/cacerts/7892ad52.0" , the content of this file is pasted below
String certTxt = file.readAsStringSync();
List<int> certData = PemCodec(PemLabel.certificate).decode(certTxt);
String encoded = PemCodec(PemLabel.certificate).encode(certData);
X509CertificateData data = X509Utils.x509CertificateFromPem(encoded);
-----BEGIN CERTIFICATE-----
MIIClDCCAhqgAwIBAgIILCmcWxbtBZUwCgYIKoZIzj0EAwIwfzELMAkGA1UEBhMC
VVMxDjAMBgNVBAgMBVRleGFzMRAwDgYDVQQHDAdIb3VzdG9uMRgwFgYDVQQKDA9T
U0wgQ29ycG9yYXRpb24xNDAyBgNVBAMMK1NTTC5jb20gRVYgUm9vdCBDZXJ0aWZp
Y2F0aW9uIEF1dGhvcml0eSBFQ0MwHhcNMTYwMjEyMTgxNTIzWhcNNDEwMjEyMTgx
NTIzWjB/MQswCQYDVQQGEwJVUzEOMAwGA1UECAwFVGV4YXMxEDAOBgNVBAcMB0hv
dXN0b24xGDAWBgNVBAoMD1NTTCBDb3Jwb3JhdGlvbjE0MDIGA1UEAwwrU1NMLmNv
bSBFViBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IEVDQzB2MBAGByqGSM49
AgEGBSuBBAAiA2IABKoSR5CYG/vvw0AHgyBO8TCCogbR8pKGYfL2IWjKAMTH6kMA
VIbc/R/fALhBYlzccBYy3h+Z1MzFB8gIH2EWB1E9fVwHU+M1OIzfzZ/ZLg1Kthku
WnBaBu2+8KGwytAJKaNjMGEwHQYDVR0OBBYEFFvKXuXe0oGqzagtZFG22XKbl+ZP
MA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0jBBgwFoAUW8pe5d7SgarNqC1kUbbZcpuX
5k8wDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA2gAMGUCMQCK5kCJN+vp1RPZ
ytRrJPOwPYdGWBrssd9v+1a6cGvHOMzosYxPD/fxZ3YOg9AeUY8CMD32IygmTMZg
h5Mmm7I1HrrW9zzRHM76JTymGoEVW/MSD2zuZYrJh6j5B+BimoxcSg==
-----END CERTIFICATE-----

After 2.7.0 (e.g. 2.7.1), X509CertificateData data = X509Utils.x509CertificateFromPem(encoded); will throw exception:

The following _TypeError was thrown building Consumer<CertsModel>(dirty, dependencies: 
type 'ASN1Sequence' is not a subtype of type 'ASN1Set'

Is there anything that the application should do when upgrading to the newer versions?

Ephenodrom commented 3 years ago

Hello @certaintls, Sorry for the delay but I was finally able to fix this issue. The problem was a bug in the pointycastle package. The start position of the value bytes was not calculated in the correct way. The problem only appeard on a few certificates where the length of the value start position description was exactly 127 byte long.

Please use the latest version on pub dev 3.3.3.

certaintls commented 3 years ago

Thank you very much!