pkcs7: Allow for missing optional content field
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 28 Jul 2022 09:18:54 +0000 (11:18 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Fri, 29 Jul 2022 05:59:00 +0000 (07:59 +0200)
The content field of type OCTET STRING of a ContentInfo object
with ContentType Data

  ContentInfo ::= SEQUENCE {
     contentType ContentType,
     content
        [0] EXPLICIT OCTET STRING OPTIONAL

is optional and can be missing if no data is available

src/libstrongswan/plugins/pkcs7/pkcs7_data.c

index 235b9fe..98af138 100644 (file)
@@ -60,6 +60,13 @@ METHOD(container_t, get_data, bool,
        chunk_t chunk;
 
        chunk = this->content;
+
+       /* The content field is optional */
+       if (chunk.len == 0)
+       {
+               *data = chunk_empty;
+               return TRUE;
+       }
        if (asn1_unwrap(&chunk, &chunk) == ASN1_OCTET_STRING)
        {
                *data = chunk_clone(chunk);