Skip to content

Commit c28f009

Browse files
authored
Add Log ID to LogEntry field (sigstore#294)
* Add Log ID to LogEntry field Since the signed entry timestamp (SET) will be able to prove insertion into the log, adding the log ID (aka public key SHA256 hash) makes it easier to know which log the entry came from. Signed-off-by: Bob Callaway <bob.callaway@gmail.com>
1 parent 603b4a8 commit c28f009

File tree

6 files changed

+93
-23
lines changed

6 files changed

+93
-23
lines changed

cmd/rekor-cli/app/get.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ type getCmdOutput struct {
4040
LogIndex int
4141
IntegratedTime int64
4242
UUID string
43+
LogID string
4344
}
4445

4546
func (g *getCmdOutput) String() string {
46-
s := fmt.Sprintf("Index: %d\n", g.LogIndex)
47+
s := fmt.Sprintf("LogID: %v\n", g.LogID)
48+
s += fmt.Sprintf("Index: %d\n", g.LogIndex)
4749
dt := time.Unix(g.IntegratedTime, 0).UTC().Format(time.RFC3339)
4850
s += fmt.Sprintf("IntegratedTime: %s\n", dt)
4951
s += fmt.Sprintf("UUID: %s\n", g.UUID)
@@ -130,8 +132,9 @@ func parseEntry(uuid string, e models.LogEntryAnon) (interface{}, error) {
130132
obj := getCmdOutput{
131133
Body: eimpl,
132134
UUID: uuid,
133-
IntegratedTime: e.IntegratedTime,
135+
IntegratedTime: *e.IntegratedTime,
134136
LogIndex: int(*e.LogIndex),
137+
LogID: *e.LogID,
135138
}
136139

137140
return &obj, nil

openapi.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ definitions:
291291
additionalProperties:
292292
type: object
293293
properties:
294+
logID:
295+
type: string
296+
pattern: '^[0-9a-fA-F]{64}$'
297+
description: This is the SHA256 hash of the DER-encoded public key for the log at the time the entry was included in the log
294298
logIndex:
295299
type: integer
296300
minimum: 0
@@ -311,10 +315,12 @@ definitions:
311315
# 1. Remove the Verification object from the JSON Document
312316
# 2. Canonicalize the remaining JSON document by following RFC 8785 rules
313317
# 3. Verify the canonicalized payload and signedEntryTimestamp against rekor's public key
314-
description: Signature over the logIndex, body and integratedTime.
318+
description: Signature over the logID, logIndex, body and integratedTime.
315319
required:
320+
- "logID"
316321
- "logIndex"
317322
- "body"
323+
- "integratedTime"
318324

319325
SearchIndex:
320326
type: object

pkg/api/api.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ package api
1717

1818
import (
1919
"context"
20+
"crypto/sha256"
2021
"crypto/x509"
22+
"encoding/hex"
2123
"encoding/pem"
2224
"fmt"
2325
"time"
@@ -47,12 +49,12 @@ func dial(ctx context.Context, rpcServer string) (*grpc.ClientConn, error) {
4749
}
4850

4951
type API struct {
50-
logClient trillian.TrillianLogClient
51-
logID int64
52-
// PEM encoded public key
53-
pubkey string
54-
signer signature.Signer
55-
verifier *client.LogVerifier
52+
logClient trillian.TrillianLogClient
53+
logID int64
54+
pubkey string // PEM encoded public key
55+
pubkeyHash string // SHA256 hash of DER-encoded public key
56+
signer signature.Signer
57+
verifier *client.LogVerifier
5658
}
5759

5860
func NewAPI() (*API, error) {
@@ -95,6 +97,12 @@ func NewAPI() (*API, error) {
9597
if err != nil {
9698
return nil, errors.Wrap(err, "marshalling public key")
9799
}
100+
hasher := sha256.New()
101+
if _, err = hasher.Write(b); err != nil {
102+
return nil, errors.Wrap(err, "computing hash of public key")
103+
}
104+
pubkeyHashBytes := hasher.Sum(nil)
105+
98106
pubkey := pem.EncodeToMemory(&pem.Block{
99107
Type: "PUBLIC KEY",
100108
Bytes: b,
@@ -106,11 +114,12 @@ func NewAPI() (*API, error) {
106114
}
107115

108116
return &API{
109-
logClient: logClient,
110-
logID: tLogID,
111-
pubkey: string(pubkey),
112-
signer: signer,
113-
verifier: verifier,
117+
logClient: logClient,
118+
logID: tLogID,
119+
pubkey: string(pubkey),
120+
pubkeyHash: hex.EncodeToString(pubkeyHashBytes),
121+
signer: signer,
122+
verifier: verifier,
114123
}, nil
115124
}
116125

pkg/api/entries.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ func logEntryFromLeaf(tc TrillianClient, leaf *trillian.LogLeaf, signedLogRoot *
6262

6363
logEntry := models.LogEntry{
6464
hex.EncodeToString(leaf.MerkleLeafHash): models.LogEntryAnon{
65+
LogID: swag.String(api.pubkeyHash),
6566
LogIndex: &leaf.LeafIndex,
6667
Body: leaf.LeafValue,
67-
IntegratedTime: leaf.IntegrateTimestamp.AsTime().Unix(),
68+
IntegratedTime: swag.Int64(leaf.IntegrateTimestamp.AsTime().Unix()),
6869
Verification: &models.LogEntryAnonVerification{
6970
InclusionProof: &inclusionProof,
7071
},
@@ -143,9 +144,10 @@ func CreateLogEntryHandler(params entries.CreateLogEntryParams) middleware.Respo
143144
uuid := hex.EncodeToString(queuedLeaf.GetMerkleLeafHash())
144145

145146
logEntryAnon := models.LogEntryAnon{
147+
LogID: swag.String(api.pubkeyHash),
146148
LogIndex: swag.Int64(queuedLeaf.LeafIndex),
147149
Body: queuedLeaf.GetLeafValue(),
148-
IntegratedTime: queuedLeaf.IntegrateTimestamp.AsTime().Unix(),
150+
IntegratedTime: swag.Int64(queuedLeaf.IntegrateTimestamp.AsTime().Unix()),
149151
}
150152

151153
if viper.GetBool("enable_retrieve_api") {

pkg/generated/models/log_entry.go

Lines changed: 38 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/generated/restapi/embedded_spec.go

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)