aboutsummaryrefslogtreecommitdiff
path: root/flags.go
diff options
context:
space:
mode:
authorGibheer <gibheer@gmail.com>2015-02-20 10:45:42 +0100
committerGibheer <gibheer@gmail.com>2015-02-20 10:45:42 +0100
commit075865c417c387783d37a6705d66034f2fd9ff4a (patch)
tree106a183e55b732d84bd9532751587e6ae978173f /flags.go
parent1c621c063c26205e23af7bc7e3da4b5064856d4c (diff)
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.
Diffstat (limited to 'flags.go')
-rw-r--r--flags.go35
1 files changed, 35 insertions, 0 deletions
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
+}