2014-12-09 17:00:18 -06:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-12-11 11:24:34 -06:00
|
|
|
"io/ioutil"
|
2014-12-09 17:00:18 -06:00
|
|
|
|
2020-12-24 09:52:27 -05:00
|
|
|
"github.com/urfave/cli"
|
2020-12-24 10:41:16 -05:00
|
|
|
"i2pgit.org/idk/reseed-tools/reseed"
|
|
|
|
"i2pgit.org/idk/reseed-tools/su3"
|
2014-12-09 17:00:18 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewSu3VerifyCommand() cli.Command {
|
|
|
|
return cli.Command{
|
|
|
|
Name: "verify",
|
|
|
|
Usage: "Verify a Su3 file",
|
|
|
|
Description: "Verify a Su3 file",
|
|
|
|
Action: su3VerifyAction,
|
2014-12-13 12:11:47 -06:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "extract",
|
|
|
|
Usage: "Also extract the contents of the su3",
|
|
|
|
},
|
|
|
|
},
|
2014-12-09 17:00:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func su3VerifyAction(c *cli.Context) {
|
2017-10-15 14:14:50 -05:00
|
|
|
su3File := su3.New()
|
2014-12-11 11:24:34 -06:00
|
|
|
|
|
|
|
data, err := ioutil.ReadFile(c.Args().Get(0))
|
|
|
|
if nil != err {
|
2014-12-09 17:00:18 -06:00
|
|
|
panic(err)
|
|
|
|
}
|
2014-12-11 11:24:34 -06:00
|
|
|
if err := su3File.UnmarshalBinary(data); err != nil {
|
2014-12-09 17:00:18 -06:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2014-12-10 01:10:37 -06:00
|
|
|
fmt.Println(su3File.String())
|
|
|
|
|
2014-12-10 20:04:21 -06:00
|
|
|
// get the reseeder key
|
|
|
|
ks := reseed.KeyStore{Path: "./certificates"}
|
2017-10-15 14:14:50 -05:00
|
|
|
cert, err := ks.ReseederCertificate(su3File.SignerID)
|
2014-12-10 20:04:21 -06:00
|
|
|
if nil != err {
|
2014-12-15 14:50:10 -06:00
|
|
|
fmt.Println(err)
|
|
|
|
return
|
2014-12-10 20:04:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := su3File.VerifySignature(cert); nil != err {
|
2014-12-09 17:00:18 -06:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2017-10-15 14:14:50 -05:00
|
|
|
fmt.Printf("Signature is valid for signer '%s'\n", su3File.SignerID)
|
2014-12-13 12:11:47 -06:00
|
|
|
|
|
|
|
if c.Bool("extract") {
|
|
|
|
// @todo: don't assume zip
|
|
|
|
ioutil.WriteFile("extracted.zip", su3File.BodyBytes(), 0755)
|
|
|
|
}
|
2014-12-09 17:00:18 -06:00
|
|
|
}
|