cose-rust
A Rust crate to encode and decode secured data (Signatures, Encryption or MACed) in CBOR Object Signing and Encryption (COSE) format, RFC 8152.
This crate uses the rust-openssl and rand for the cryptographic operations and the cbor-codec for the CBOR encoding/decoding.
COSE
COSE is a concise binary data format that protects the payload of the message with a set of cryptographic operations.
A COSE structure is as follows:
- Tag: A COSE mesage type identifier.
- Protected header: A CBOR encoded object that contains information to be integrity protected by the cryptographic process.
- Unprotected header: An object that contains information that is not integrity protected.
- Content: This is specific to each type of message:
- cose-sign1: payload and its signature.
- cose-encrypt0: just the ciphertext.
- cose-mac0: payload and its tag.
- cose-sign: payload and an array of signers buckets (each similar to cose-sign1).
- cose-encrypt: ciphertext and an array of recipients buckets (each similar to cose-encrypt0).
- cose-mac: payload and an array of recipients buckets (each similar to cose-mac0).
This COSE structure is then encoded in CBOR data format, resulting in a compact binary representation.
The COSE RFC 8152 specifies the following 6 types of COSE messages:
- cose-sign1: A digitally signed COSE message with a single recipient.
- cose-sign: A digitally signed COSE message with multiple signers, each signer has its own signature of the payload.
- cose-encrypt0: An encrypted COSE message with a single recipient.
- cose-encrypt: An encrypted COSE message with multiple recipients. In this case, for each recipient, the ciphertext is encrypted/decrypted by a shared secret between the recipient and the sender, a derived key from the shared secret or a randomly generated CEK that is derived from the shared secret (KEK).
- cose-mac0: A MAC tagged COSE message with a single recipient.
- cose-encrypt: A MAC tagged COSE message with multiple recipients. In this case, for each recipient, the tag is created/verified by a shared secret between the recipient and the sender, a derived key from the shared secret or a randomly generated CEK that is derived from the shared secret (KEK).
Examples
The following examples, demonstrate how to build the basic cose messages (cose-sign1, cose-encrypt0, cose-mac0), examples of other use cases and cose message types can be found in the respective documentation.
cose-sign1
use sign;
use keys;
use algs;
cose-encrypt0
use encrypt;
use keys;
use algs;
cose-mac0
use mac;
use keys;
use algs;
License
This crate, cose-rust, is licensed by the MIT License.
Note
This crate is under development and it has not been tested yet.