github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/tools/stconfig/stconfig.go (about) 1 // Copyright 2018 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 main 6 7 // https://xkcd.com/927/ 8 9 // stconfig is a configuration tool to create and manage artifacts for 10 // System Transparency Boot. Artifacts are ment to be uploaded to a 11 // remote provisioning server. 12 13 import ( 14 "log" 15 "os" 16 17 kingpin "gopkg.in/alecthomas/kingpin.v2" 18 ) 19 20 const ( 21 // Author is the author 22 Author = "Philipp Deppenwiese, Jens Drenhaus" 23 // HelpText is the command line help 24 HelpText = "stconfig can be used for managing System Transparency boot configurations" 25 ) 26 27 var goversion string 28 29 var ( 30 create = kingpin.Command("create", "Create a boot ball from stconfig.json") 31 sign = kingpin.Command("sign", "Sign the binary inside the provided stboot.ball and add the signatures and certificates") 32 unpack = kingpin.Command("unpack", "Unpack boot ball file into directory") 33 34 createConfigFile = create.Arg("config", "Path to the manifest file in JSON format").Required().String() 35 36 signInFile = sign.Arg("bootball", "Archive created by 'stconfig create'").Required().String() 37 signPrivKeyFile = sign.Arg("privkey", "Private key for signing").Required().String() 38 signCertFile = sign.Arg("certificate", "Certificate to veryfy the signature").Required().String() 39 40 unpackInFile = unpack.Arg("bootball", "Archive containing the boot files").Required().String() 41 ) 42 43 func main() { 44 kingpin.UsageTemplate(kingpin.CompactUsageTemplate).Version(goversion).Author(Author) 45 kingpin.CommandLine.Help = HelpText 46 47 switch kingpin.Parse() { 48 case create.FullCommand(): 49 if _, err := os.Stat(*createConfigFile); os.IsNotExist(err) { 50 log.Fatalf("%s does not exist: %v", *createConfigFile, err) 51 } 52 if err := packBootBall(*createConfigFile); err != nil { 53 log.Fatalln(err.Error()) 54 } 55 case sign.FullCommand(): 56 if _, err := os.Stat(*signInFile); os.IsNotExist(err) { 57 log.Fatalf("%s does not exist: %v", *signInFile, err) 58 } 59 if _, err := os.Stat(*signPrivKeyFile); os.IsNotExist(err) { 60 log.Fatalf("%s does not exist: %v", *signPrivKeyFile, err) 61 } 62 if _, err := os.Stat(*signCertFile); os.IsNotExist(err) { 63 log.Fatalf("%s does not exist: %v", *signCertFile, err) 64 } 65 if err := addSignatureToBootBall(*signInFile, *signPrivKeyFile, *signCertFile); err != nil { 66 log.Fatalln(err.Error()) 67 } 68 case unpack.FullCommand(): 69 if _, err := os.Stat(*unpackInFile); os.IsNotExist(err) { 70 log.Fatalf("%s does not exist: %v", *signInFile, err) 71 } 72 if err := unpackBootBall(*unpackInFile); err != nil { 73 log.Fatalln(err.Error()) 74 } 75 default: 76 log.Fatal("Command not found") 77 } 78 }