- OCaml 100%
in-toto #
in-toto attestations in DSSE envelopes, for OCaml.
An attestation says something signed about a software artifact: that a commit passed its tests, that a binary was built from a source, what a package contains. The in-toto Attestation Framework v1 gives it three layers. A statement names the artifacts it is about by their digests, the subject, and carries a predicate whose type says what is claimed, such as the Test Result predicate. A DSSE envelope signs the statement's bytes. A bundle groups the envelopes about one artifact, one a line.
DSSE signs the pre-authentication encoding of the payload's type and its
bytes, DSSEv1 LEN(type) type LEN(body) body, never a re-encoding of a
parsed document. A verifier checks the bytes it received and then reads those
same bytes, so two encoders that disagree on JSON whitespace or member order
cannot make one signature mean two things. A statement is written in the
RFC 8785 canonical form, so one statement has one serialization.
The library holds no key: signing and verification are callbacks, so a key in memory, in a keychain or in a hardware token signs the same way.
Installation #
$ opam install in-toto
Usage #
A statement that a commit passed its tests, signed with an Ed25519 key:
let key = X509.Private_key.generate ~seed:"in-toto-readme" `ED25519
let statement =
In_toto.Statement.v ~predicate_type:In_toto.Test_result.predicate_type
~predicate:
(In_toto.Test_result.to_json
{
result = Passed;
configuration = [];
url = None;
passed_tests = [ "build"; "test" ];
warned_tests = [];
failed_tests = [];
})
[
In_toto.Resource_descriptor.v ~name:"hello"
~digest:[ ("gitCommit", "d20ace7968ba43c0219f62d71334c1095bab1602") ]
();
]
let envelope =
In_toto.Dsse.sign ~keyid:"readme" ~payload_type:In_toto.Statement.payload_type
(fun pae -> X509.Private_key.sign `SHA256 key (`Message pae))
(In_toto.Statement.to_string statement)
|> Result.get_ok
The statement is signed in its canonical form:
# print_endline (In_toto.Statement.to_string statement);;
{"_type":"https://in-toto.io/Statement/v1","predicate":{"configuration":[],"failedTests":[],"passedTests":["build","test"],"result":"PASSED","warnedTests":[]},"predicateType":"https://in-toto.io/attestation/test-result/v0.1","subject":[{"digest":{"gitCommit":"d20ace7968ba43c0219f62d71334c1095bab1602"},"name":"hello"}]}
- : unit = ()
A verifier accepts a signature by the key it trusts, and reads the statement from the bytes it verified:
# let accept ~keyid:_ ~pae signature =
Result.is_ok
(X509.Public_key.verify `SHA256 ~signature (X509.Private_key.public key)
(`Message pae));;
val accept : keyid:'a -> pae:string -> string -> bool = <fun>
# In_toto.Dsse.verify accept envelope
|> Option.map In_toto.Statement.of_string
|> Option.map (Result.map (Fmt.str "%a" In_toto.Statement.pp));;
- : (string, [ `Msg of string ]) result option =
Some (Ok "https://in-toto.io/attestation/test-result/v0.1 about 1 subject")
References #
- DSSE protocol v1.0.2 and DSSE envelope v1.0.2
- in-toto Attestation Framework v1: Statement, ResourceDescriptor, DigestSet, Envelope and Bundle
- Test Result predicate v0.1.0
- RFC 8785, the JSON Canonicalization Scheme
Licence #
ISC. See LICENSE.md.