Remote attestation (RATS) messages in CBOR and COSE
README.md

rats #

Remote attestation (RATS) messages in CBOR and COSE.

In remote attestation an Attester sends Evidence about its state to a
Verifier, which appraises it and returns Attestation Results that a Relying
Party acts on (RFC 9334). The IETF RATS working group gives each of those
messages a format, and this library reads, writes, signs and verifies them:

  • Entity Attestation Tokens (EAT, RFC 9711): the Evidence. A claims set
    names the entity (ueid, oemid, hwmodel), its software (swname,
    swversion, manifests, measurements), its debug state, its
    freshness (eat_nonce, iat) and the submodules it is made of, each a
    claims set, the digest of a detached claims set, or a nested token signed
    by its own key. The measured components of RFC 10013 are the measurements
    format for what CoSWID cannot describe, such as firmware measured at
    boot. Detached EAT bundles (tag 602) carry a token with the claims sets
    its digests cover.
  • EAT Attestation Results (EAR, draft-ietf-rats-ear-04): the Verifier's
    answer. For each appraised Attester it gives a status and the AR4SI
    trustworthiness vector (draft-ietf-rats-ar4si-10): eight categories whose
    claims fall in four tiers, none, affirming, warning and contraindicated.
  • Conceptual Message Wrappers (CMW, RFC 9999): a typed envelope that moves
    any of these messages without parsing it, as a record, a CBOR tag or a
    labelled collection.

EATs and EARs are signed as CBOR Web Tokens in a COSE_Sign1, through the
cose package. Verification reads the algorithm from the protected header
only, and refuses one outside the caller's allowlist, by default EdDSA,
ES256, ES384 and ES512. Freshness is the caller's: a token may carry a
nonce, an iat, or neither when the profile uses epoch markers.

A claims set keeps its claims in the order it read them and keeps every
claim it does not know, so a token decoded from preferred-serialisation
bytes encodes back to the same bytes and a Verifier can pass on what it
did not interpret. Decoding refuses what the CDDL of each document
refuses: a nonce outside 8 to 64 bytes, a floating-point iat, an EAR
without a Verifier identity, a CMW indicator outside the registered bits.

Installation #

$ opam install rats

If opam cannot find it, the package may not be in the public
opam-repository yet. Add the overlay repository first:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install rats

Usage #

An Attester issues Evidence: a claims set with a nonce, signed as a CWT
with an Ed25519 key (here the key of RFC 8032 section 7.1, TEST 1). The token
starts with the CWT tag 61 and the COSE_Sign1 tag 18.

# let of_hex h =
    String.init (String.length h / 2) (fun i ->
        Char.chr (int_of_string ("0x" ^ String.sub h (2 * i) 2)));;
val of_hex : string -> string = <fun>
# let priv, pub =
    let seed =
      of_hex "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
    in
    match Crypto_ec.Ed25519.priv_of_octets seed with
    | Ok k ->
        ( (Cose.X509 (`ED25519 k) : Cose.signing_key),
          (Cose.X509 (`ED25519 (Crypto_ec.Ed25519.pub_of_priv k))
            : Cose.verification_key) )
    | Error _ -> assert false;;
val priv : Cose.signing_key = Cose.X509 (`ED25519 <abstr>)
val pub : Cose.verification_key = Cose.X509 (`ED25519 <abstr>)
# let evidence =
    Rats.Eat.v ~nonce:[ "fresh-nonce-0001" ] ~swname:"Example"
      ~swversion:(Rats.Version.v ~scheme:Rats.Version.semver "1.0.0")
      ~dbgstat:Rats.Eat.Disabled_permanently ();;
val evidence : Rats.Eat.t = <abstr>
# let sign claims =
    Result.get_ok (Rats.Eat.sign ~algorithm:EdDSA ~key:priv claims);;
val sign : Rats.Eat.t -> string = <fun>
# let token = sign evidence in
  ( String.length token,
    String.concat ""
      (List.init 4 (fun i -> Printf.sprintf "%02x" (Char.code token.[i]))) );;
- : int * string = (124, "d83dd284")

The Verifier checks the signature under its allowlist and reads the
claims back:

# let claims = Result.get_ok (Rats.Eat.verify ~key:pub (sign evidence));;
val claims : Rats.Eat.t = <abstr>
# Rats.Eat.swname claims;;
- : string option = Some "Example"
# Rats.Eat.verify ~algorithms:[ ES256 ] ~key:pub (sign evidence)
  |> Result.is_error;;
- : bool = true

It then issues an Attestation Result: one appraisal per Attester, with a
status and a trustworthiness vector, and the Evidence it appraised wrapped
in a CMW record.

# let vector =
    Rats.Ar4si.Vector.v
      [ (Rats.Ar4si.Instance_identity, 2); (Rats.Ar4si.Executables, 33) ];;
val vector : Rats.Ar4si.Vector.t = <abstr>
# Rats.Ar4si.Vector.tier vector;;
- : Rats.Ar4si.Tier.t = Rats.Ar4si.Tier.Warning
# let ear =
    Rats.Ear.v ~iat:1_700_000_000L
      ~verifier_id:
        { Rats.Ar4si.Verifier_id.developer = "https://example.org";
          build = "verifier 1.0" }
      ~raw_evidence:
        (Rats.Cmw.record (Media_type "application/eat+cwt") (sign evidence))
      ~submods:
        [ ( "node",
            Rats.Ear.Appraisal.v ~status:(Rats.Ar4si.Vector.tier vector)
              ~trust_vector:vector () ) ]
      ()
  in
  Rats.Ear.sign ~algorithm:EdDSA ~key:priv ear
  |> Result.get_ok |> Rats.Ear.verify ~key:pub
  |> Result.map (fun (e : Rats.Ear.t) -> List.map fst e.submods);;
- : (string list, Loc.Error.t) result = Ok ["node"]

Status #

The CBOR serialisations of RFC 9711, RFC 10013, draft-ietf-rats-ear-04 and
RFC 9999. The JSON serialisations (JWT EATs and EARs, JSON CMWs) are not
implemented, nor are COSE_Mac0 and COSE_Sign tokens, the signed CMW of RFC
9999 section 4.1 or its X.509 extension.

The tests copy the examples of RFC 9711 Appendix A, RFC 10013 section 4.6,
RFC 9999 section 5 and the CBOR figures of draft-ietf-rats-ear-04, and
replay traces generated by Veraison's Go implementations.

Veraison maintains the reference Go
implementations, veraison/eat, veraison/cmw and veraison/ear (whose
EAR is the JSON one of an earlier draft), and veraison/rust-ear in Rust.
The interop tests replay traces generated from the Go libraries.

References #

License #

ISC