From a5eef4512fcc3f1ba54154835deb5fb23d93031e Mon Sep 17 00:00:00 2001 From: Akulij Date: Wed, 26 Feb 2025 20:46:21 +0500 Subject: [PATCH] Initial working PoC --- cmd/age-gen-passphrase/main.go | 46 ++++++++++++++++++++++++++++++++++ go.mod | 9 +++++++ go.sum | 6 +++++ 3 files changed, 61 insertions(+) create mode 100644 cmd/age-gen-passphrase/main.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/cmd/age-gen-passphrase/main.go b/cmd/age-gen-passphrase/main.go new file mode 100644 index 0000000..87f25f8 --- /dev/null +++ b/cmd/age-gen-passphrase/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "time" + "unsafe" + "errors" + + "crypto/sha256" + "golang.org/x/crypto/curve25519" + + "filippo.io/age" +) + +type X25519Identity struct { + secretKey, ourPublicKey []byte +} + +func main() { + sum := sha256.Sum256([]byte("some secret password phrase")) + fmt.Printf("Password hash: %x\n", sum) + + k, err := newX25519IdentityFromScalar(sum[:]) + if err != nil { + fmt.Printf("internal error: %v", err) + } + + fmt.Printf("Public key: %s\n", k.Recipient()) + + fmt.Printf("# created: %s\n", time.Now().Format(time.RFC3339)) + fmt.Printf("# public key: %s\n", k.Recipient()) + fmt.Printf("%s\n", k) +} + +// almost a copy of private function in age/x25519.go +func newX25519IdentityFromScalar(secretKey []byte) (*age.X25519Identity, error) { + if len(secretKey) != curve25519.ScalarSize { + return nil, errors.New("invalid X25519 secret key") + } + i := &X25519Identity{ + secretKey: make([]byte, curve25519.ScalarSize), + } + copy(i.secretKey, secretKey) + i.ourPublicKey, _ = curve25519.X25519(i.secretKey, curve25519.Basepoint) + return (*age.X25519Identity)(unsafe.Pointer(i)), nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4a1625d --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/akulij/age-gen-passphrase + +go 1.22.2 + +require ( + filippo.io/age v1.2.1 // indirect + golang.org/x/crypto v0.24.0 // indirect + golang.org/x/sys v0.21.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7ffdd25 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +filippo.io/age v1.2.1 h1:X0TZjehAZylOIj4DubWYU1vWQxv9bJpo+Uu2/LGhi1o= +filippo.io/age v1.2.1/go.mod h1:JL9ew2lTN+Pyft4RiNGguFfOpewKwSHm5ayKD/A4004= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=