TimothyClaeys / pycose

A Python implementation of the COSE specification (CBOR Object Signing and Encryption) described in RFC 8152.
https://tools.ietf.org/html/rfc8152
Other
39 stars 24 forks source link

Support for detached content #81

Closed becarpenter closed 1 year ago

becarpenter commented 2 years ago

I'm probably missing something but I don't see how to sign or verify with detached content, which RFC 8152 allows. (Reason: we are wondering whether to add COSE signing to GRASP, RFC 8990, and I'd like to prototype it.)

BrianSipos commented 2 years ago

I have used COSE with detached payloads by manipulating the CBOR array between the COSE encoding and CBOR encoding layers. An example of this is the removal (after signing) and replacement (before verification) of the message_dec[2] item in test_sign1_ecdsa.py.

I don't know if this is the one-true-way to make this happen but it does the right thing. Because COSE is more of a framework than a specific protocol, it seems like most uses of the library will need to do similar item- or field-specific manipulation to line things up correctly with the use.

becarpenter commented 2 years ago

Thanks @BrianSipos, I had almost figured that out for myself. It seems a bit expensive because of additional cbor.loads() and dumps() but it will serve my purpose.

letmaik commented 2 years ago

The API of pycose could be extended to support this directly. For example, when signing, there could be an optional detached: Optional[bool]=False keyword argument, and when verifying, there could be an optional payload: Optional[bytes]=None.

@TimothyClaeys What do you think?