Skip to content

Error parsing valid EncryptedContentInfo #264

@natzlob

Description

@natzlob

I receive valid CMS EncryptedContentInfo bytes, which I call encrypted_content_info. From the EncryptedContentInfo, I can get the encrypted algorithm with encrypted_content_info['content_encryption_algorithm']. However, there is an error when extracting the EncryptedContent from encrypted_content_info. The error is:

encrypted_content_bytes = encrypted_content_info['encrypted_content']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python3.7/site-packages/asn1crypto/core.py", line 3536, in __getitem__
    raise e
  File ".../python3.7/site-packages/asn1crypto/core.py", line 3531, in __getitem__
    return self._lazy_child(key)
  File ".../python3.7/site-packages/asn1crypto/core.py", line 3478, in _lazy_child
    child = self.children[index] = _build(*child)
  File ".../python3.7/site-packages/asn1crypto/core.py", line 5561, in _build
    METHOD_NUM_TO_NAME_MAP.get(method, method)
ValueError: Error parsing asn1crypto.core.OctetString - method should have been primitive, but constructed was found
    while parsing asn1crypto.cms.EncryptedContentInfo

When I take the EncryptedContentInfo, write it to file and use openssl asn1parse to parse it as follows:
openssl asn1parse -inform der -in encrypted_content_info.ber,
the encrypted content can be successfully extracted. If I take the encrypted content obtained from openssl asn1parse, I can then decrypt it successfully etc. This means there is a problem with the way asn1crypto parses this CMS. This seems like a bug with the package.

Is there another way this content should be extracted using asn1crypto? Is there a fix for this problem? Please assist.

Some additional info is that the ContentType of the EncryptedContentInfo is simply data and the error persists in asn1crypto Version 1.5.1 as well as older versions, such as 1.2.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions