From e7801b268c97c6b72bfcd76549ce5fd50ab0b1b5 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Tue, 27 Oct 2020 19:16:10 +0100 Subject: added ed25519 signing and SDIs --- type.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'type.go') diff --git a/type.go b/type.go index a629259..726b215 100644 --- a/type.go +++ b/type.go @@ -25,6 +25,7 @@ const ( // StItem references a versioned item based on a given format specifier. type StItem struct { Format StFormat `tls:"maxval:65535"` + SignedDebugInfoV1 *SignedDebugInfoV1 `tls:"selector:Format,val:2"` InclusionProofV1 *InclusionProofV1 `tls:"selector:Format,val:4"` ChecksumV1 *ChecksumV1 `tls:"selector:Format,val:5"` // TODO: add more items @@ -44,11 +45,32 @@ type InclusionProofV1 struct { InclusionPath []NodeHash `tls:"minlen:1,maxlen:65535"` } +// SignedDebugInfoV1 is a signed statement that we intend (but do not promise) +// to insert an entry into the log. Only Ed25519 signatures are supported. +// TODO: double-check that crypto/ed25519 encodes signature as in RFC 8032 +// TODO: need to think about signature format, then update markdown/api.md +type SignedDebugInfoV1 struct { + LogId []byte `tls:"minlen:32,maxlen:127"` + Message []byte `tls:"minlen:0,maxlen:65535"` + Signature []byte `tls:"minlen:0,maxlen:65535"` // defined in RFC 8032 +} + // NodeHash is a hashed Merkle tree node, see RFC 6962/bis (ยง4.9) type NodeHash struct { Data []byte `tls:"minlen:32,maxlen:255"` } +func NewSignedDebugInfoV1(logId, message, signature []byte) StItem { + return StItem{ + Format: StFormatSignedDebugInfoV1, + SignedDebugInfoV1: &SignedDebugInfoV1{ + LogId: logId, + Message: message, + Signature: signature, + }, + } +} + // NewChecksumV1 creates a new StItem of type checksum_v1 func NewChecksumV1(identifier []byte, checksum []byte) StItem { return StItem{ @@ -103,11 +125,17 @@ func (i StItem) String() string { return fmt.Sprintf("Format(%s): %s", i.Format, *i.ChecksumV1) case StFormatInclusionProofV1: return fmt.Sprintf("Format(%s): %s", i.Format, *i.InclusionProofV1) + case StFormatSignedDebugInfoV1: + return fmt.Sprintf("Format(%s): %s", i.Format, *i.SignedDebugInfoV1) default: return fmt.Sprintf("unknown StItem: %s", i.Format) } } +func (i SignedDebugInfoV1) String() string { + return fmt.Sprintf("LogId(%s) Message(%s) Signature(%s)", base64.StdEncoding.EncodeToString(i.LogId), string(i.Message), base64.StdEncoding.EncodeToString(i.Signature)) +} + func (i ChecksumV1) String() string { return fmt.Sprintf("Package(%v) Checksum(%v)", string(i.Package), base64.StdEncoding.EncodeToString(i.Checksum)) } -- cgit v1.2.3