github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/go/tpm2/apps/Tpm2Keys/Tpm2Keys.go (about) 1 // Copyright (c) 2014, Google, Inc. 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 16 package main 17 18 import ( 19 "flag" 20 "fmt" 21 22 "github.com/jlmucb/cloudproxy/go/tpm2" 23 ) 24 25 // This program creates a key hierarchy consisting of a 26 // primary key, and quoting key for cloudproxy and saves the context. 27 func main() { 28 keySize := flag.Int("modulusSize", 2048, "Modulus size for keys") 29 rootContextFileName := flag.String("rootContextFile", "rootContext.bin", 30 "Root context file") 31 quoteContextFileName := flag.String("quoteContextFile", 32 "quoteContext.bin", "Quote context file") 33 storeContextFileName := flag.String("storeContextFile", 34 "storeContext.bin", "Store context file") 35 pcrList := flag.String("pcrList", "7", "Pcr list") 36 flag.Parse() 37 38 fmt.Printf("Pcr list: %s\n", *pcrList) 39 40 // Open tpm 41 rw, err := tpm2.OpenTPM("/dev/tpm0") 42 if err != nil { 43 fmt.Printf("OpenTPM failed %s\n", err) 44 return 45 } 46 defer rw.Close() 47 48 // Flushall 49 err = tpm2.Flushall(rw) 50 if err != nil { 51 fmt.Printf("Flushall failed\n") 52 return 53 } 54 55 pcrs, err := tpm2.StringToIntList(*pcrList) 56 if err != nil { 57 fmt.Printf("Can't format pcr list\n") 58 return 59 } 60 61 err = tpm2.InitTpm2KeysandContexts(rw, pcrs, uint16(*keySize), 62 uint16(tpm2.AlgTPM_ALG_SHA1), "", *rootContextFileName, 63 *quoteContextFileName, *storeContextFileName) 64 if err == nil { 65 fmt.Printf("Key creation succeeded\n") 66 } else { 67 fmt.Printf("Key creation failed\n") 68 } 69 return 70 }