in cli/mfg_cmds.go [447:504]
func runAddsigMfgCmd(cmd *cobra.Command, args []string) {
if len(args) < 3 {
ImgmodUsage(cmd, nil)
}
mfgDir := args[0]
keyFilename := args[1]
sigFilename := args[2]
outDir, err := CalcOutFilename(mfgDir)
if err != nil {
ImgmodUsage(cmd, err)
}
// Read manifest.
mman, err := readManifest(mfgDir)
if err != nil {
ImgmodUsage(cmd, err)
}
// Read public key.
keyBytes, err := ioutil.ReadFile(keyFilename)
if err != nil {
ImgmodUsage(cmd, errors.Wrapf(err, "error reading key file"))
}
// Read signature.
sig, err := ioutil.ReadFile(sigFilename)
if err != nil {
ImgmodUsage(cmd, errors.Wrapf(err, "failed to read signature"))
}
if len(sig) > MAX_SIG_LEN {
ImgmodUsage(nil, errors.Errorf(
"signature larger than arbitrary maximum length (%d > %d)",
len(sig), MAX_SIG_LEN))
}
// Update manifest.
mman.Signatures = append(mman.Signatures, manifest.MfgManifestSig{
Key: hex.EncodeToString(sec.RawKeyHash(keyBytes)),
Sig: hex.EncodeToString(sig),
})
// Write new artifacts.
if err := EnsureOutDir(mfgDir, outDir); err != nil {
ImgmodUsage(nil, err)
}
json, err := mman.MarshalJson()
if err != nil {
ImgmodUsage(nil, err)
}
manPath := fmt.Sprintf("%s/%s", outDir, mfg.MANIFEST_FILENAME)
if err := WriteFile(json, manPath); err != nil {
ImgmodUsage(nil, err)
}
}