summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/tasn_dec.c
diff options
context:
space:
mode:
authorjsing <>2022-09-03 18:52:18 +0000
committerjsing <>2022-09-03 18:52:18 +0000
commitb283f6131f8170e90b456bc531cde0fdfc878eec (patch)
treec2f7e3d1627ccbe7aba894c618c04cb4d876e4dc /src/lib/libcrypto/asn1/tasn_dec.c
parentfb18e75fc234776f661aad4dd12a912ff1f62763 (diff)
downloadopenbsd-b283f6131f8170e90b456bc531cde0fdfc878eec.tar.gz
openbsd-b283f6131f8170e90b456bc531cde0fdfc878eec.tar.bz2
openbsd-b283f6131f8170e90b456bc531cde0fdfc878eec.zip
Ensure ASN.1 types are appropriately encoded.
Per X.690, some ASN.1 types must be primitive encoded, some must be constructed and some may be either. Add this data to our types table and check the encoding against this information when decoding. ok tb@
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_dec.c')
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
index 22d8006d0a..457f526e71 100644
--- a/src/lib/libcrypto/asn1/tasn_dec.c
+++ b/src/lib/libcrypto/asn1/tasn_dec.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_dec.c,v 1.79 2022/09/03 18:45:51 jsing Exp $ */ 1/* $OpenBSD: tasn_dec.c,v 1.80 2022/09/03 18:52:18 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -467,13 +467,14 @@ asn1_d2i_primitive_content(ASN1_VALUE **pval, CBS *cbs, CBS *cbs_object,
467 CBS_dup(cbs, &cbs_initial); 467 CBS_dup(cbs, &cbs_initial);
468 CBS_init(&cbs_content, NULL, 0); 468 CBS_init(&cbs_content, NULL, 0);
469 469
470 /* XXX - check primitive vs constructed based on utype. */ 470 if (asn1_must_be_constructed(utype) && !constructed) {
471
472 /* SEQUENCE and SET must be constructed. */
473 if ((utype == V_ASN1_SEQUENCE || utype == V_ASN1_SET) && !constructed) {
474 ASN1error(ASN1_R_TYPE_NOT_CONSTRUCTED); 471 ASN1error(ASN1_R_TYPE_NOT_CONSTRUCTED);
475 goto err; 472 goto err;
476 } 473 }
474 if (asn1_must_be_primitive(utype) && constructed) {
475 ASN1error(ASN1_R_TYPE_NOT_PRIMITIVE);
476 goto err;
477 }
477 478
478 /* SEQUENCE, SET and "OTHER" are left in encoded form. */ 479 /* SEQUENCE, SET and "OTHER" are left in encoded form. */
479 if (utype == V_ASN1_SEQUENCE || utype == V_ASN1_SET || 480 if (utype == V_ASN1_SEQUENCE || utype == V_ASN1_SET ||