aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: dddc62476ddb7c21fc59a1f94b35a20cdb3b7bf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main

import (
	"flag"
	"fmt"
	"log"
)

const (
	verFailed = "signature verfication failed"
	verOK     = "Signature Verfied"
)

/*
	signify -C [-q] -p pubkey -x sigfile [file ...]
	signify -G [-n] [-c comment] -p pubkey -s seckey
	signify -S [-ez] [-x sigfile] -s seckey -m message
	signify -V [-eqz] [-p pubkey] [-t keytype] [-x sigfile] -m message
*/

var (
	checksum = flag.Bool("C", false, "Verify a signed checksum list")
	generate = flag.Bool("G", false, "Generate a new key pair")
	sign     = flag.Bool("S", false, "Sign the specfied message")
	verify   = flag.Bool("V", false, "Verify the message")
	comment  = flag.String("c", "signify", "Comment")
	embed    = flag.Bool("e", false, "Embed the message")
	msg      = flag.String("m", "", "Message file")
	nopass   = flag.Bool("n", false, "No key passphrase")
	pub      = flag.String("p", "", "Public key file")
	quiet    = flag.Bool("q", false, "Quiet mode")
	sec      = flag.String("s", "", "Secret key file")
	sig      = flag.String("x", "", "Signature file")
	gzip     = flag.Bool("z", false, "Sign and verify gzip archives")
)

func main() {
	flag.Parse()

	var rounds = 42
	if *nopass {
		rounds = 0
	}

	switch {
	case *generate:
		if err := Generate(*pub, *sec, *comment, rounds); err != nil {
			log.Fatal(err)
		}
	case *sign:
	case *verify:
	}
}

func Generate(pubkeyfile, seckeyfile, comment string, rounds int) error {
	pubKey, encKey, err := NewKey()
	if err != nil {
		return err
	}

	if rounds > 0 {
		pass, err := AskPassword(nil, true)
		if err != nil {
			return err
		}
		encKey.Kdf(pass, rounds)
	}

	sb64, err := Marshal(encKey)
	if err != nil {
		return err
	}

	sfile := File{
		Comment: fmt.Sprintf("%s secret key", comment),
		RawKey:  sb64,
	}
	if err := sfile.WriteFile(seckeyfile, SecMode); err != nil {
		return err
	}

	pb64, err := Marshal(pubKey)
	if err != nil {
		return err
	}
	pfile := File{
		Comment: fmt.Sprintf("%s public key", comment),
		RawKey:  pb64,
	}
	if err := pfile.WriteFile(pubkeyfile, PubMode); err != nil {
		return err
	}

	return nil
}