Parse BER for PKCS#12 more accurately. CBS_asn1_ber_to_der currently uses heuristics because implicitly-tagged constructed strings in BER are ambiguous with implicitly-tagged sequences. It's not possible to convert BER to DER without knowing the schema. Fortunately, implicitly tagged strings don't appear often so instead split the job up: CBS_asn1_ber_to_der fixes indefinite-length elements and constructed strings it can see. Implicitly-tagged strings it leaves uncoverted, but they will only nest one level down (because BER kindly allows one to nest constructed strings arbitrarily!). CBS_get_asn1_implicit_string then performs the final concatenation at parse time. This isn't much more complex and lets us parse BER more accurately and also reject a number of mis-encoded values (e.g. constructed INTEGERs are not a thing) we'd previously let through. The downside is the post-conversion parsing code must be aware of this limitation of CBS_asn1_ber_to_der. Fortunately, there's only one implicitly-tagged string in our PKCS#12 code. (In the category of things that really really don't matter, but I had spare cycles and the old BER converter is weird.) Change-Id: Iebdd13b08559fa158b308ef83a5bb07bfdf80ae8 Reviewed-on: https://boringssl-review.googlesource.com/7052 Reviewed-by: Adam Langley <agl@google.com>
diff --git a/include/openssl/bytestring.h b/include/openssl/bytestring.h index 9193e11..cf424d0 100644 --- a/include/openssl/bytestring.h +++ b/include/openssl/bytestring.h
@@ -130,7 +130,18 @@ #define CBS_ASN1_ENUMERATED 0xa #define CBS_ASN1_SEQUENCE (0x10 | CBS_ASN1_CONSTRUCTED) #define CBS_ASN1_SET (0x11 | CBS_ASN1_CONSTRUCTED) +#define CBS_ASN1_NUMERICSTRING 0x12 +#define CBS_ASN1_PRINTABLESTRING 0x13 +#define CBS_ASN1_T16STRING 0x14 +#define CBS_ASN1_VIDEOTEXSTRING 0x15 +#define CBS_ASN1_IA5STRING 0x16 +#define CBS_ASN1_UTCTIME 0x17 #define CBS_ASN1_GENERALIZEDTIME 0x18 +#define CBS_ASN1_GRAPHICSTRING 0x19 +#define CBS_ASN1_VISIBLESTRING 0x1a +#define CBS_ASN1_GENERALSTRING 0x1b +#define CBS_ASN1_UNIVERSALSTRING 0x1c +#define CBS_ASN1_BMPSTRING 0x1e #define CBS_ASN1_CONSTRUCTED 0x20 #define CBS_ASN1_CONTEXT_SPECIFIC 0x80