github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/pkg/crypto/measure.go (about) 1 // Copyright 2017-2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package crypto 6 7 import ( 8 "io/ioutil" 9 "log" 10 11 "github.com/9elements/tpmtool/pkg/tpm" 12 ) 13 14 const ( 15 // BlobPCR type in PCR 7 16 BlobPCR uint32 = 7 17 // BootConfigPCR type in PCR 8 18 BootConfigPCR uint32 = 8 19 // ConfigDataPCR type in PCR 8 20 ConfigDataPCR uint32 = 8 21 // NvramVarsPCR type in PCR 9 22 NvramVarsPCR uint32 = 9 23 ) 24 25 // TryMeasureData measures a byte array with additional information 26 func TryMeasureData(pcr uint32, data []byte, info string) { 27 TPMInterface, err := tpm.NewTPM() 28 if err != nil { 29 log.Printf("Cannot open TPM: %v", err) 30 return 31 } 32 log.Printf("Measuring blob: %v", info) 33 TPMInterface.Measure(pcr, data) 34 TPMInterface.Close() 35 } 36 37 // TryMeasureFiles measures a variable amount of files 38 func TryMeasureFiles(files ...string) { 39 TPMInterface, err := tpm.NewTPM() 40 if err != nil { 41 log.Printf("Cannot open TPM: %v", err) 42 return 43 } 44 for _, file := range files { 45 log.Printf("Measuring file: %v", file) 46 data, err := ioutil.ReadFile(file) 47 if err != nil { 48 continue 49 } 50 TPMInterface.Measure(BlobPCR, data) 51 } 52 TPMInterface.Close() 53 }