...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package util
16
17 import (
18 "crypto/sha256"
19
20 ct "github.com/google/certificate-transparency-go"
21 "github.com/google/certificate-transparency-go/tls"
22 "github.com/google/trillian"
23 "k8s.io/klog/v2"
24 )
25
26
27
28 func BuildLogLeaf(logPrefix string,
29 merkleLeaf ct.MerkleTreeLeaf, leafIndex int64,
30 cert ct.ASN1Cert, chain []ct.ASN1Cert, isPrecert bool,
31 ) (trillian.LogLeaf, error) {
32 leafData, err := tls.Marshal(merkleLeaf)
33 if err != nil {
34 klog.Warningf("%s: Failed to serialize Merkle leaf: %v", logPrefix, err)
35 return trillian.LogLeaf{}, err
36 }
37
38 extraData, err := ExtraDataForChain(cert, chain, isPrecert)
39 if err != nil {
40 klog.Warningf("%s: Failed to serialize chain for ExtraData: %v", logPrefix, err)
41 return trillian.LogLeaf{}, err
42 }
43
44
45
46 leafIDHash := sha256.Sum256(cert.Data)
47
48 return trillian.LogLeaf{
49 LeafValue: leafData,
50 ExtraData: extraData,
51 LeafIndex: leafIndex,
52 LeafIdentityHash: leafIDHash[:],
53 }, nil
54 }
55
56
57
58 func ExtraDataForChain(cert ct.ASN1Cert, chain []ct.ASN1Cert, isPrecert bool) ([]byte, error) {
59 var extra interface{}
60 if isPrecert {
61
62 extra = ct.PrecertChainEntry{
63 PreCertificate: cert,
64 CertificateChain: chain,
65 }
66 } else {
67
68
69
70 extra = ct.CertificateChain{Entries: chain}
71 }
72 return tls.Marshal(extra)
73 }
74
View as plain text