package main import ( "bufio" "crypto/rand" "encoding/base64" "flag" "fmt" "io/ioutil" "log" "os" "strings" "golang.org/x/crypto/ed25519" ) const ( PKAlg = "Ed" KDFAlg = "BK" commentHdr = "untrusted comment: " verifyWith = "verify with " pubKey = "%s public key" secKey = "%s secret key" sigFrom = "signature from %s" 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 [-e] [-x sigfile] -s seckey -m message signify -V [-eq] [-x sigfile] -p pubkey -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") vefify = flag.Bool("V", false, "Verify the message") comment = flag.String("c", "", "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") ) func main() { flag.Parse() var rounds = 42 if *nopass { rounds = 0 } _ = rounds /* if err := Generate(*pub, *sec, *comment, rounds); err != nil { log.Fatal(err) } */ log.Println(parseFile("test.sig")) s, _ := base64.StdEncoding.DecodeString("RWRCSwAAAACzJBN2gC5//jVvDiV76rs4m2aKXkljqDpbOC0bBf7abZhV/Zygr6b0KIbSI56JQutwzsQeouxnnHuVTZp3IW4M9qdpe5Nh8Jrr5g7r0rHLPxEPmcv/dNru6ZjqI7CcGsY=") fmt.Printf("%v\n", s) } const KeyNumLen = 8 type EncKey struct { PKAlg [2]byte KDFAlg [2]byte KDFRounds uint32 // network byte order Salt [16]byte Checksum [8]byte KeyNum [KeyNumLen]byte SecKey [ed25519.PrivateKeySize]byte } type PubKey struct { PKAlg [2]byte KeyNum [KeyNumLen]byte PubKey [ed25519.PublicKeySize]byte } type Sig struct { PKAlg [2]byte KeyNum [KeyNumLen]byte Sig [ed25519.SignatureSize]byte } type File struct { Comment string Key string Body []byte } func Generate(pubFile, secFile, comment string, rounds int) error { pub, sec, err := ed25519.GenerateKey(rand.Reader) if err != nil { return err } b64 := base64.NewEncoder(base64.StdEncoding, os.Stdout) fmt.Println("pub", len(pub), pub) b64.Write(pub) fmt.Println("sec", len(sec), sec) b64.Write(sec) return nil } func Sign() {} func Verify() {} func parseFile(fname string) (File, error) { fd, err := os.Open(fname) if err != nil { return File{}, err } defer fd.Close() buf := bufio.NewReader(fd) comment, err := buf.ReadString('\n') if err != nil { return File{}, err } comment = strings.TrimRight(comment, "\r\n") log.Println(comment) b64, err := buf.ReadString('\n') if err != nil { return File{}, err } b64 = strings.TrimRight(b64, "\r\n") body, err := ioutil.ReadAll(buf) return File{ Comment: comment, Key: b64, Body: body, }, nil }