digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.05k stars 779 forks source link

Add support for pkcs encryption with secret key for recipient #1067

Open frelibert opened 9 months ago

frelibert commented 9 months ago

In cases where the recipient is not yet known or it is a group of recipients that may share a secret, encryption should be done with a secret key. this results in a different algorithm and logic to be executed and a different RecipientInfo block in the cms message.

From the rfc: https://datatracker.ietf.org/doc/html/rfc5652#page-25

Recipient information using previously distributed symmetric keys is represented in the type KEKRecipientInfo. Each instance of KEKRecipientInfo will transfer the content-encryption key to one or more recipients who have the previously distributed key-encryption key.

  KEKRecipientInfo ::= SEQUENCE {
    version CMSVersion,  -- always set to 4
    kekid KEKIdentifier,
    keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
    encryptedKey EncryptedKey }

  KEKIdentifier ::= SEQUENCE {
    keyIdentifier OCTET STRING,
    date GeneralizedTime OPTIONAL,
    other OtherKeyAttribute OPTIONAL }

It should be possible to add a recipient with a symmetric key and key identifier before encryption takes place.