in cli/image_cmds.go [722:952]
func AddImageCommands(cmd *cobra.Command) {
imageCmd := &cobra.Command{
Use: "image",
Short: "Shows and manipulates Mynewt image (.img) files",
Run: func(cmd *cobra.Command, args []string) {
cmd.Usage()
},
}
cmd.AddCommand(imageCmd)
showCmd := &cobra.Command{
Use: "show <img-file>",
Short: "Displays JSON describing a Mynewt image file",
Run: runShowCmd,
}
imageCmd.AddCommand(showCmd)
briefCmd := &cobra.Command{
Use: "brief <img-file>",
Short: "Displays brief text description of a Mynewt image file",
Run: runBriefCmd,
}
imageCmd.AddCommand(briefCmd)
signCmd := &cobra.Command{
Use: "sign <img-file> <priv-key-pem> [priv-key-pem...]",
Short: "Appends signatures to a Mynewt image file",
Run: runSignCmd,
}
signCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o", "",
"File to write to")
signCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(signCmd)
addTlvsCmd := &cobra.Command{
Use: "addtlvs <img-file> <tlv-type> <data-filename> " +
"[tlv-type] [data-filename] [...]",
Short: "Adds the specified TLVs to a Mynewt image file",
Run: runAddTlvsCmd,
}
addTlvsCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o", "",
"File to write to")
addTlvsCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(addTlvsCmd)
rmtlvsCmd := &cobra.Command{
Use: "rmtlvs <img-file> <tlv-index> [tlv-index] [...]",
Short: "Removes the specified TLVs from a Mynewt image file",
Run: runRmtlvsCmd,
}
rmtlvsCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o", "",
"File to write to")
rmtlvsCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(rmtlvsCmd)
rmsigsCmd := &cobra.Command{
Use: "rmsigs",
Short: "Removes all signatures from a Mynewt image file",
Run: runRmsigsCmd,
}
rmsigsCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o", "",
"File to write to")
rmsigsCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(rmsigsCmd)
hashableCmd := &cobra.Command{
Use: "hashable <img-file>",
Short: "Extracts an image's hashable content",
Run: runHashableCmd,
}
hashableCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
imageCmd.AddCommand(hashableCmd)
addsigCmd := &cobra.Command{
Use: "addsig <image> <pub-key-der> <sig-der> <sig-tlv-type>",
Short: "Adds a signature to a Mynewt image file",
Run: runAddsigCmd,
}
addsigCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
addsigCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(addsigCmd)
decryptCmd := &cobra.Command{
Use: "decrypt <image> <priv-key-der>",
Short: "Decrypts an encrypted Mynewt image file (partial)",
Long: "Decrypts the body of an encrypted Mynewt image file and " +
"removes the encryption TLVs. This command does not change the " +
"image header and does not recalculate the image hash. This " +
"command is useful for re-signing an image with a new key prior " +
"to re-encrypting.",
Run: runDecryptCmd,
}
decryptCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
decryptCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(decryptCmd)
decryptFullCmd := &cobra.Command{
Use: "decryptfull <image> <priv-key-der>",
Short: "Decrypts an encrypted Mynewt image file (full)",
Long: "Decrypts the body of an encrypted Mynewt image file, " +
"removes the encryption TLVs, clears the 'encrypted' flag in " +
"the image header, and recalculates the image hash.",
Run: runDecryptFullCmd,
}
decryptHwCmd := &cobra.Command{
Use: "decrypthw <image> <aes-secret>",
Short: "Decrypts an hardware-encrypted Mynewt image file",
Long: "Decrypts the body of a hardware-encrypted Mynewt image file and " +
"removes the encryption TLVs. The aes-secret can be 64-encoded " +
"or raw.",
Run: runDecryptHwCmd,
}
decryptHwCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
decryptHwCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(decryptHwCmd)
decryptFullCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
decryptFullCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(decryptFullCmd)
encryptCmd := &cobra.Command{
Use: "encrypt <image> <priv-key-der>",
Short: "Encrypts a Mynewt image file",
Long: "Encrypts the body of an encrypted Mynewt image file and " +
"adds encryption TLVs. This command does not change the " +
"image header and does not recalculate the image hash.",
Run: runEncryptCmd,
}
encryptCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
encryptCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(encryptCmd)
encryptFullCmd := &cobra.Command{
Use: "encryptfull <image> <priv-key-der>",
Short: "Encrypts an encrypted Mynewt image file (full)",
Long: "Encrypts the body of an encrypted Mynewt image file, " +
"adds encryption TLVs, sets the 'encrypted' flag in " +
"the image header, and recalculates the image hash.",
Run: runEncryptFullCmd,
}
encryptFullCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
encryptFullCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(encryptFullCmd)
setBodyCmd := &cobra.Command{
Use: "setbody <image> <body-filename>",
Short: "Replaces an image's body with a file's contents",
Run: runSetBodyCmd,
}
setBodyCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
setBodyCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(setBodyCmd)
verifyCmd := &cobra.Command{
Use: "verify <image>",
Short: "Verifies an Mynewt image's integrity",
Run: runVerifyCmd,
}
verifyCmd.PersistentFlags().StringSliceVar(&OptSignKeys, "signkey",
nil, "Public signing key (.pem) (can be repeated)")
verifyCmd.PersistentFlags().StringSliceVar(&OptEncKeys, "enckey",
nil, "Private encryption key (.der) (can be repeated)")
verifyCmd.PersistentFlags().StringVar(&OptManifest, "manifest",
"", "Manifest file")
imageCmd.AddCommand(verifyCmd)
extractBodyCmd := &cobra.Command{
Use: "extractbody <image> <out-file>",
Short: "Extracts a Mynewt image's body",
Run: runExtractBodyCmd,
}
imageCmd.AddCommand(extractBodyCmd)
rehashImgCmd := &cobra.Command{
Use: "rehash <image>",
Short: "Calculates an image's hash and replaces its SHA256 TLV",
Run: runRehashImgCmd,
}
rehashImgCmd.PersistentFlags().StringVarP(&OptOutFilename, "outfile", "o",
"", "File to write to")
rehashImgCmd.PersistentFlags().BoolVarP(&OptInPlace, "inplace", "i", false,
"Replace input file")
imageCmd.AddCommand(rehashImgCmd)
}