ccatoken 0.1.0

CCA attestation token decoding, verification, and appraisal
Documentation
start = platform-ta-kvstore
    / platform-rv-kvstore
    / realm-rv-kvstore

; common hex-encoded byte string formats
hexbytes-4  = text .regexp "([0-9a-f]{2}){4}"
hexbytes-32 = text .regexp "([0-9a-f]{2}){32}"
hexbytes-48 = text .regexp "([0-9a-f]{2}){48}"
hexbytes-64 = text .regexp "([0-9a-f]{2}){64}"

impl-id-type = hexbytes-32

; EAT UEID type RAND (0x01)
inst-id-type = text .regexp "01([0-9a-f]{2}){32}"

;measurement-type = hexbytes-32 / hexbytes-48 / hexbytes-64
measurement-type = hexbytes-32

config-type = hexbytes-4

x-reason-type = "insecure" / "revoked" / "obsolete"

; see https://www.iana.org/assignments/hash-function-text-names/hash-function-text-names.xhtml
hash-algo-id-type = "md2"
    / "md5"
    / "sha-1"
    / "sha-224"
    / "sha-256"
    / "sha-384"
    / "sha-512"
    / "shake128"
    / "shake256"

perso-type = hexbytes-64

rim-type = measurement-type

; a platform ref-val, including fw measurements and platform config.
; it describes an acceptable state for a certain platform, identified by impl-id.
; there may be multiple platform-rv records for the same platform at any point in
; time, each describing one possible "good" state.
platform-rv = {
    platform-claims
}
 
platform-claims = (
    "implementation-id" => impl-id-type
    "platform-configuration" => config-type
    "sw-components" => [ + swcomp ]
)
 
; sw components
swcomp = {
    ? "component-type" => text
    "measurement-value" => measurement-type
    ? "version" => text 
    "signer-id" => measurement-type
    ? "hash-algo-id" => hash-algo-id-type
}

x-platform-rv = {
    platform-claims
    "x-reason" => x-reason-type
}

; a realm ref-val, including rim, rem and personalisation value
; it describes an acceptable state for a given realm / CC workload.
; there may be multiple realm-rv records for the same realm
realm-claims = (
    "initial-measurement" => measurement-type
    ? "extensible-measurements" => [ 4*4 measurement-type ]
    ? "personalization-value" => perso-type
    "rak-hash-algorithm" => hash-algo-id-type
)

realm-rv = {
    realm-claims
}

x-realm-rv = {
    realm-claims
    "x-reason" => x-reason-type
}

; CPAK endorsement
cpak-claims = (
    "instance-id" => inst-id-type
    "implementation-id" => impl-id-type
    "pkey" => example-jwk
)

cpak = {
    cpak-claims
}

example-jwk = {
    "kty" => "EC",
    "crv" => "P-256",
    "x" => "MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
    "y" => "4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM"
}

x-cpak = {
    cpak-claims
    "x-reason" => x-reason-type
}

; the following k-v stores are only examples: the way the core types are
; organised is an implementation detail.

platform-rv-kvstore = {
    ? "accept-list" => {
        + impl-id-type => [ + platform-rv ]
    },
    ? "deny-list" => {
        + impl-id-type => [ + x-platform-rv ]
    },
}

realm-rv-kvstore = {
    ? "accept-list" => {
        + rim-type => [ + realm-rv ]
    },
    ? "deny-list" => {
        + rim-type => [ + x-realm-rv ]
    }
}

platform-ta-kvstore = {
    ? "accept-list" => {
        + inst-id-type => cpak
    },
    ? "deny-list" => {
        + inst-id-type => x-cpak
    }
}