aboutsummaryrefslogtreecommitdiff
path: root/type.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-28 13:38:39 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-28 13:38:39 +0100
commitd752d967335e1418f27e03e0389b01178b28f232 (patch)
treeabc3b6f2e3b64af67f19ca50f6e5c3609d829fb9 /type.go
parente7801b268c97c6b72bfcd76549ce5fd50ab0b1b5 (diff)
added signed tree head and get-sth code path
Diffstat (limited to 'type.go')
-rw-r--r--type.go49
1 files changed, 48 insertions, 1 deletions
diff --git a/type.go b/type.go
index 726b215..be2571e 100644
--- a/type.go
+++ b/type.go
@@ -5,6 +5,7 @@ import (
"crypto/x509"
"encoding/base64"
+ "time"
"github.com/google/certificate-transparency-go/tls"
"github.com/google/trillian"
@@ -25,10 +26,24 @@ const (
// StItem references a versioned item based on a given format specifier.
type StItem struct {
Format StFormat `tls:"maxval:65535"`
+ SignedTreeHeadV1 *SignedTreeHeadV1 `tls:"selector:Format,val:1"`
SignedDebugInfoV1 *SignedDebugInfoV1 `tls:"selector:Format,val:2"`
+ // TODO: add consistency proof
InclusionProofV1 *InclusionProofV1 `tls:"selector:Format,val:4"`
ChecksumV1 *ChecksumV1 `tls:"selector:Format,val:5"`
- // TODO: add more items
+}
+
+type SignedTreeHeadV1 struct {
+ LogId []byte `tls:"minlen:2,maxlen:127"`
+ TreeHead TreeHeadV1 `tls:minlen:0, maxlen:65535` // what should maxlen be?
+ Signature []byte `tls:"minlen:0,maxlen:65535"`
+}
+
+type TreeHeadV1 struct {
+ Timestamp uint64
+ TreeSize uint64
+ RootHash NodeHash `tls:minlen:32,maxlen:255`
+ Extension []byte `tls:"minlen:0,maxlen:65535"`
}
// ChecksumV1 associates a package name with an arbitrary checksum value
@@ -60,6 +75,28 @@ type NodeHash struct {
Data []byte `tls:"minlen:32,maxlen:255"`
}
+func NewSignedTreeHeadV1(th TreeHeadV1, logId, signature []byte) StItem {
+ return StItem{
+ Format: StFormatSignedTreeHeadV1,
+ SignedTreeHeadV1: &SignedTreeHeadV1{
+ LogId: logId,
+ TreeHead: th,
+ Signature: signature,
+ },
+ }
+}
+
+func NewTreeHeadV1(timestamp, treeSize uint64, rootHash []byte) TreeHeadV1 {
+ return TreeHeadV1{
+ Timestamp: timestamp,
+ TreeSize: treeSize,
+ RootHash: NodeHash{
+ Data: rootHash,
+ },
+ Extension: nil,
+ }
+}
+
func NewSignedDebugInfoV1(logId, message, signature []byte) StItem {
return StItem{
Format: StFormatSignedDebugInfoV1,
@@ -127,11 +164,21 @@ func (i StItem) String() string {
return fmt.Sprintf("Format(%s): %s", i.Format, *i.InclusionProofV1)
case StFormatSignedDebugInfoV1:
return fmt.Sprintf("Format(%s): %s", i.Format, *i.SignedDebugInfoV1)
+ case StFormatSignedTreeHeadV1:
+ return fmt.Sprintf("Format(%s): %s", i.Format, *i.SignedTreeHeadV1)
default:
return fmt.Sprintf("unknown StItem: %s", i.Format)
}
}
+func (th TreeHeadV1) String() string {
+ return fmt.Sprintf("Timestamp(%s) TreeSize(%d) RootHash(%s)", time.Unix(int64(th.Timestamp/1000), 0), th.TreeSize, base64.StdEncoding.EncodeToString(th.RootHash.Data))
+}
+
+func (i SignedTreeHeadV1) String() string {
+ return fmt.Sprintf("LogId(%s) TreeHead(%s) Signature(%s)", base64.StdEncoding.EncodeToString(i.LogId), i.TreeHead, base64.StdEncoding.EncodeToString(i.Signature))
+}
+
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))
}