From 519784b5ee58370d6c1262b0eb6c72ee3580f293 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Tue, 1 Jun 2021 00:21:30 +0200 Subject: started to update stfe server Work in progress. --- log_parameters.go | 80 ++++++++++++++++++------------------------------------- 1 file changed, 26 insertions(+), 54 deletions(-) (limited to 'log_parameters.go') diff --git a/log_parameters.go b/log_parameters.go index a2a2d7a..aceff3e 100644 --- a/log_parameters.go +++ b/log_parameters.go @@ -2,6 +2,7 @@ package stfe import ( "crypto" + "crypto/ed25519" "fmt" "time" @@ -10,66 +11,37 @@ import ( // LogParameters is a collection of log parameters type LogParameters struct { - LogId *types.Namespace // log identifier - LogIdBytes []byte // serialized log id - LogIdStr string // serialized log id (hex) - TreeId int64 // used internally by Trillian - Prefix string // e.g., "test" for /test - MaxRange int64 // max entries per get-entries request - SubmitterPolicy bool // if we have a submitter policy (true means that namespaces must be registered) - WitnessPolicy bool // if we have a witness policy (true means that namespaces must be registered) - Submitters *types.NamespacePool // trusted submitters - Witnesses *types.NamespacePool // trusted witnesses - Deadline time.Duration // gRPC deadline - Interval time.Duration // cosigning sth frequency - HashType crypto.Hash // hash function used by Trillian - Signer crypto.Signer // access to Ed25519 private key -} + LogId string // serialized log id (hex) + TreeId int64 // used internally by Trillian + Prefix string // e.g., "test" for /test + MaxRange int64 // max entries per get-entries request + Deadline time.Duration // gRPC deadline + Interval time.Duration // cosigning sth frequency + HashType crypto.Hash // hash function used by Trillian + Signer crypto.Signer // access to Ed25519 private key -// NewLogParameters creates newly initialized log parameters -func NewLogParameters(signer crypto.Signer, logId *types.Namespace, treeId int64, prefix string, submitters, witnesses *types.NamespacePool, maxRange int64, interval, deadline time.Duration, submitterPolicy, witnessPolicy bool) (*LogParameters, error) { - logIdBytes, err := types.Marshal(*logId) - if err != nil { - return nil, fmt.Errorf("Marshal failed for log identifier: %v", err) - } - return &LogParameters{ - LogId: logId, - LogIdBytes: logIdBytes, - LogIdStr: fmt.Sprintf("%x", logIdBytes), - TreeId: treeId, - Prefix: prefix, - MaxRange: maxRange, - SubmitterPolicy: submitterPolicy, - WitnessPolicy: witnessPolicy, - Submitters: submitters, - Witnesses: witnesses, - Deadline: deadline, - Interval: interval, - HashType: crypto.SHA256, - Signer: signer, - }, nil + // Witnesses map trusted witness identifiers to public verification keys + Witnesses map[[types.HashSize]byte][types.VerificationKeySize]byte } -// SignTreeHeadV1 signs a TreeHeadV1 structure -func (lp *LogParameters) SignTreeHeadV1(th *types.TreeHeadV1) (*types.StItem, error) { - serialized, err := types.Marshal(*th) - if err != nil { - return nil, fmt.Errorf("Marshal failed for TreeHeadV1: %v", err) - } - sig, err := lp.Signer.Sign(nil, serialized, crypto.Hash(0)) +// Sign signs a tree head +func (lp *LogParameters) Sign(th *types.TreeHead) (*types.SignedTreeHead, error) { + sig, err := lp.Signer.Sign(nil, th.Marshal(), crypto.Hash(0)) if err != nil { return nil, fmt.Errorf("Sign failed: %v", err) } - lastSthTimestamp.Set(float64(time.Now().Unix()), lp.LogIdStr) - lastSthSize.Set(float64(th.TreeSize), lp.LogIdStr) - return &types.StItem{ - Format: types.StFormatSignedTreeHeadV1, - SignedTreeHeadV1: &types.SignedTreeHeadV1{ - TreeHead: *th, - Signature: types.SignatureV1{ - Namespace: *lp.LogId, - Signature: sig, - }, + lastSthTimestamp.Set(float64(time.Now().Unix()), lp.LogId) + lastSthSize.Set(float64(th.TreeSize), lp.LogId) + + sigident := types.SigIdent{ + KeyHash: types.Hash(lp.Signer.Public().(ed25519.PublicKey)[:]), + Signature: &[types.SignatureSize]byte{}, + } + copy(sigident.Signature[:], sig) + return &types.SignedTreeHead{ + TreeHead: *th, + SigIdent: []*types.SigIdent{ + &sigident, }, }, nil } -- cgit v1.2.3 From 47bacfd5c5d22470340e0823c4ad37b45914b68e Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sun, 6 Jun 2021 15:59:35 +0200 Subject: started using the refactored packages in siglog server --- log_parameters.go | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 log_parameters.go (limited to 'log_parameters.go') diff --git a/log_parameters.go b/log_parameters.go deleted file mode 100644 index aceff3e..0000000 --- a/log_parameters.go +++ /dev/null @@ -1,47 +0,0 @@ -package stfe - -import ( - "crypto" - "crypto/ed25519" - "fmt" - "time" - - "github.com/system-transparency/stfe/types" -) - -// LogParameters is a collection of log parameters -type LogParameters struct { - LogId string // serialized log id (hex) - TreeId int64 // used internally by Trillian - Prefix string // e.g., "test" for /test - MaxRange int64 // max entries per get-entries request - Deadline time.Duration // gRPC deadline - Interval time.Duration // cosigning sth frequency - HashType crypto.Hash // hash function used by Trillian - Signer crypto.Signer // access to Ed25519 private key - - // Witnesses map trusted witness identifiers to public verification keys - Witnesses map[[types.HashSize]byte][types.VerificationKeySize]byte -} - -// Sign signs a tree head -func (lp *LogParameters) Sign(th *types.TreeHead) (*types.SignedTreeHead, error) { - sig, err := lp.Signer.Sign(nil, th.Marshal(), crypto.Hash(0)) - if err != nil { - return nil, fmt.Errorf("Sign failed: %v", err) - } - lastSthTimestamp.Set(float64(time.Now().Unix()), lp.LogId) - lastSthSize.Set(float64(th.TreeSize), lp.LogId) - - sigident := types.SigIdent{ - KeyHash: types.Hash(lp.Signer.Public().(ed25519.PublicKey)[:]), - Signature: &[types.SignatureSize]byte{}, - } - copy(sigident.Signature[:], sig) - return &types.SignedTreeHead{ - TreeHead: *th, - SigIdent: []*types.SigIdent{ - &sigident, - }, - }, nil -} -- cgit v1.2.3