2014-12-09 17:00:18 -06:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2014-12-10 20:04:21 -06:00
|
|
|
"github.com/MDrollette/go-i2p/reseed"
|
2014-12-09 17:00:18 -06:00
|
|
|
"github.com/MDrollette/go-i2p/su3"
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewSu3VerifyCommand() cli.Command {
|
|
|
|
return cli.Command{
|
|
|
|
Name: "verify",
|
|
|
|
Usage: "Verify a Su3 file",
|
|
|
|
Description: "Verify a Su3 file",
|
|
|
|
Action: su3VerifyAction,
|
|
|
|
Flags: []cli.Flag{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func su3VerifyAction(c *cli.Context) {
|
|
|
|
file, err := os.Open(c.Args().Get(0))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
2014-12-10 19:17:12 -06:00
|
|
|
su3File, err := su3.Parse(file)
|
2014-12-10 17:21:40 -06:00
|
|
|
if 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"}
|
|
|
|
cert, err := ks.ReseederCertificate(su3File.SignerId)
|
|
|
|
if nil != err {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := su3File.VerifySignature(cert); nil != err {
|
2014-12-09 17:00:18 -06:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2014-12-10 19:17:12 -06:00
|
|
|
fmt.Printf("Signature is valid for signer '%s'\n", su3File.SignerId)
|
2014-12-09 17:00:18 -06:00
|
|
|
}
|