From 075865c417c387783d37a6705d66034f2fd9ff4a Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 20 Feb 2015 10:45:42 +0100 Subject: add verification of messages This commit adds back the possibility to verify a message through a public key and a signature. It works a little bit different than before as it always prints the base64 version, but it makes it easier to use. --- flags.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'flags.go') diff --git a/flags.go b/flags.go index 9af8371..c825b57 100644 --- a/flags.go +++ b/flags.go @@ -5,6 +5,7 @@ package main import ( "crypto/elliptic" + "encoding/base64" "flag" "fmt" "io" @@ -48,13 +49,17 @@ type ( publicKeyPath string // path to the public key signRequestPath string // path to the certificate sign request certificateFlags *certFlagsContainer // container for certificate related flags + signature string // a base64 encoded signature } // a container for the refined flags flagSet struct { PrivateKey pki.PrivateKey + PublicKey pki.PublicKey Output io.WriteCloser Input io.ReadCloser + // an asn1 encoded signature of a signage process + Signature []byte // private key specific stuff PrivateKeyGenerationFlags privateKeyGenerationFlags @@ -140,6 +145,22 @@ func (f *Flags) parsePrivateKey() error { return nil } +// add the public key flag +func (f *Flags) AddPublicKey() { + f.check_list = append(f.check_list, f.parsePublicKey) + f.flagset.StringVar(&f.flag_container.publicKeyPath, "public-key", "", "path to the public key") +} + +// parse public key flag +func (f *Flags) parsePublicKey() error { + if f.flag_container.publicKeyPath == "" { return fmt.Errorf("No public key given!") } + + pu, err := ReadPublicKeyFile(f.flag_container.publicKeyPath) + if err != nil { return fmt.Errorf("Error reading public key: %s", err) } + f.Flags.PublicKey = pu + return nil +} + // add the output parameter to the checklist func (f *Flags) AddOutput() { f.check_list = append(f.check_list, f.parseOutput) @@ -214,3 +235,17 @@ func (f *Flags) parsePrivateKeyGenerationFlags() error { } return nil } + +// add the signature flag to load a signature from a signing process +func (f *Flags) AddSignature() { + f.check_list = append(f.check_list, f.parseSignature) + f.flagset.StringVar(&f.flag_container.signature, "signature", "", "the base64 encoded signature to use for verification") +} + +// parse the signature flag +func (f *Flags) parseSignature() error { + var err error + f.Flags.Signature, err = base64.StdEncoding.DecodeString(f.flag_container.signature) + if err != nil { return err } + return nil +} -- cgit v1.2.3-70-g09d2