@@ -26,6 +26,7 @@ import (
2626 "strconv"
2727
2828 "github.com/cyberphone/json-canonicalization/go/src/webpki.org/jsoncanonicalizer"
29+ "github.com/go-openapi/runtime"
2930 "github.com/go-openapi/runtime/middleware"
3031 "github.com/go-openapi/strfmt"
3132 "github.com/go-openapi/swag"
@@ -97,12 +98,35 @@ func logEntryFromLeaf(ctx context.Context, signer signature.Signer, tc TrillianC
9798
9899 uuid := hex .EncodeToString (leaf .MerkleLeafHash )
99100 if viper .GetBool ("enable_attestation_storage" ) {
100- att , err := storageClient . FetchAttestation ( ctx , uuid )
101+ pe , err := models . UnmarshalProposedEntry ( bytes . NewReader ( leaf . LeafValue ), runtime . JSONConsumer () )
101102 if err != nil {
102- log .Logger .Errorf ("error fetching attestation: %s %s" , uuid , err )
103- } else {
104- logEntryAnon .Attestation = & models.LogEntryAnonAttestation {
105- Data : att ,
103+ return nil , err
104+ }
105+ eimpl , err := types .NewEntry (pe )
106+ if err != nil {
107+ return nil , err
108+ }
109+ attKey := eimpl .AttestationKey ()
110+ if attKey != "" {
111+ att , err := storageClient .FetchAttestation (ctx , attKey )
112+ if err != nil {
113+ log .Logger .Errorf ("error fetching attestation by key, trying by UUID: %s %s" , attKey , err )
114+ // the original attestation implementation stored this by uuid instead of by digest
115+ activeTree := fmt .Sprintf ("%x" , tc .logID )
116+ entryIDstruct , err := sharding .CreateEntryIDFromParts (activeTree , uuid )
117+ if err != nil {
118+ err := fmt .Errorf ("error creating EntryID from active treeID %v and uuid %v: %w" , activeTree , uuid , err )
119+ return nil , err
120+ }
121+ att , err = storageClient .FetchAttestation (ctx , entryIDstruct .UUID )
122+ if err != nil {
123+ log .Logger .Errorf ("error fetching attestation by uuid: %s %s" , entryIDstruct .UUID , err )
124+ }
125+ }
126+ if err == nil {
127+ logEntryAnon .Attestation = & models.LogEntryAnonAttestation {
128+ Data : att ,
129+ }
106130 }
107131 }
108132 }
@@ -224,14 +248,16 @@ func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middl
224248 if viper .GetBool ("enable_attestation_storage" ) {
225249
226250 go func () {
227- attestation := entry .Attestation ()
228- if attestation == nil {
229- log .RequestIDLogger (params .HTTPRequest ).Infof ("no attestation for %s" , entryID )
251+ attKey , attVal := entry .AttestationKeyValue ()
252+ if attVal == nil {
253+ log .RequestIDLogger (params .HTTPRequest ).Infof ("no attestation for %s" , uuid )
230254 return
231255 }
232- // TODO stop using uuid and use attestation hash
233- if err := storeAttestation ( context . Background (), entryIDstruct .UUID , attestation ); err != nil {
256+ if err := storeAttestation ( context . Background (), attKey , attVal ); err != nil {
257+ // entryIDstruct.UUID
234258 log .RequestIDLogger (params .HTTPRequest ).Errorf ("error storing attestation: %s" , err )
259+ } else {
260+ log .RequestIDLogger (params .HTTPRequest ).Infof ("stored attestation for uuid %s with filename %s" , entryIDstruct .UUID , attKey )
235261 }
236262 }()
237263 }
0 commit comments