github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/tools/stconfig/commands.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  import (
     8  	"log"
     9  
    10  	"github.com/u-root/u-root/pkg/boot/stboot"
    11  )
    12  
    13  func packBootBall(config string) (err error) {
    14  	ball, err := stboot.BootBallFromConfig(config)
    15  	if err != nil {
    16  		return
    17  	}
    18  
    19  	err = ball.Pack()
    20  	if err != nil {
    21  		return
    22  	}
    23  
    24  	log.Printf("Bootball created at: " + ball.Archive)
    25  	return ball.Clean()
    26  
    27  }
    28  
    29  func addSignatureToBootBall(bootBall, privKey, cert string) (err error) {
    30  	ball, err := stboot.BootBallFromArchive(bootBall)
    31  	if err != nil {
    32  		return
    33  	}
    34  
    35  	err = ball.Sign(privKey, cert)
    36  	if err != nil {
    37  		return
    38  	}
    39  
    40  	if err = ball.Pack(); err != nil {
    41  		return
    42  	}
    43  
    44  	log.Printf("Signatures included for each bootconfig: %d", ball.NumSignatures)
    45  	return ball.Clean()
    46  }
    47  
    48  func unpackBootBall(bootBall string) (err error) {
    49  	ball, err := stboot.BootBallFromArchive(bootBall)
    50  	if err != nil {
    51  		return err
    52  	}
    53  
    54  	log.Println("Archive unpacked into: " + ball.Dir())
    55  	return ball.Clean()
    56  }