github.com/google/trillian-examples@v0.0.0-20240520080811-0d40d35cef0e/binary_transparency/firmware/api/annotation.go (about) 1 // Copyright 2021 Google LLC. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package api 16 17 import "fmt" 18 19 // StatementType is an enum that describes the type of statement in a SignedStatement. 20 type StatementType byte 21 22 // Enum values for the different types of statement. 23 const ( 24 FirmwareMetadataType StatementType = 'f' 25 MalwareStatementType StatementType = 'm' 26 RevocationStatementType StatementType = 'r' 27 ) 28 29 // SignedStatement is a Statement signed by the Claimant. 30 type SignedStatement struct { 31 // Type is one of the statement types from above, and indicates what 32 // Statement should be interpreted as. 33 Type StatementType 34 // The serialised Claim in json form. 35 // This is one of MalwareStatement or BuildStatement. 36 Statement []byte 37 38 // Signature is the bytestream of the signature over (Type || Statement). 39 Signature []byte 40 } 41 42 // FirmwareID is a pointer to a firmware version. 43 // It will be a SignedStatement of type FirmwareMetadataType. 44 type FirmwareID struct { 45 LogIndex uint64 46 FirmwareImageSHA512 []byte 47 } 48 49 func (id FirmwareID) String() string { 50 return fmt.Sprintf("FirmwareID{index %d, hash %x}", id.LogIndex, id.FirmwareImageSHA512) 51 } 52 53 // MalwareStatement is an annotation about malware checks in a firmware version. 54 type MalwareStatement struct { 55 // FirmwareID is the SignedStatement in the log being annotated. 56 FirmwareID FirmwareID 57 58 // Good is a crude signal of goodness. 59 // TODO(mhutchinson): Add more fields as needed for the demo (e.g. Timestamp). 60 Good bool 61 } 62 63 func (s MalwareStatement) String() string { 64 return fmt.Sprintf("MalwareStatement{fw %s, good %t}", s.FirmwareID, s.Good) 65 } 66 67 // RevocationStatement is an annotation that marks a build as revoked. 68 // This statement simply being present for a build marks it as revoked. 69 // There is no way to unrevoke something; this can be done by re-releasing it. 70 // TODO(mhutchinson): Wire this up in the personality. 71 type RevocationStatement struct { 72 // FirmwareID is the SignedStatement in the log being annotated. 73 FirmwareID FirmwareID 74 }