Compare commits
6 Commits
666fb84a66
...
721e68a64e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
721e68a64e | ||
|
|
6c40441f70 | ||
|
|
8e5fcfb1be | ||
|
|
ccd10d8c7f | ||
|
|
55f720e419 | ||
|
|
e8ea9461ed |
@ -1,10 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
"unsafe"
|
||||
"errors"
|
||||
|
||||
"golang.org/x/term"
|
||||
|
||||
"crypto/sha256"
|
||||
"golang.org/x/crypto/curve25519"
|
||||
@ -17,17 +22,17 @@ type X25519Identity struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var passphrase string
|
||||
passbytes, err := getPasswordBytes()
|
||||
if err != nil {
|
||||
errorf("Failed to get password, error: %s\n", err)
|
||||
}
|
||||
|
||||
fmt.Print("Enter password: ")
|
||||
fmt.Scanln(&passphrase)
|
||||
|
||||
sum := sha256.Sum256([]byte(passphrase))
|
||||
sum := sha256.Sum256(passbytes)
|
||||
fmt.Printf("Password hash: %x\n", sum)
|
||||
|
||||
k, err := newX25519IdentityFromScalar(sum[:])
|
||||
k, err := newX25519IdentityFromScalar(sum[:])
|
||||
if err != nil {
|
||||
fmt.Printf("internal error: %v", err)
|
||||
errorf("internal error: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Public key: %s\n", k.Recipient())
|
||||
@ -37,6 +42,17 @@ func main() {
|
||||
fmt.Printf("%s\n", k)
|
||||
}
|
||||
|
||||
func getPasswordBytes() ([]byte, error) {
|
||||
if term.IsTerminal(int(os.Stdin.Fd())) {
|
||||
fmt.Print("Enter password: ")
|
||||
passbytes, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||
fmt.Println()
|
||||
return passbytes, err
|
||||
} else {
|
||||
return io.ReadAll(os.Stdin)
|
||||
}
|
||||
}
|
||||
|
||||
// almost a copy of private function in age/x25519.go
|
||||
func newX25519IdentityFromScalar(secretKey []byte) (*age.X25519Identity, error) {
|
||||
if len(secretKey) != curve25519.ScalarSize {
|
||||
@ -49,3 +65,7 @@ func newX25519IdentityFromScalar(secretKey []byte) (*age.X25519Identity, error)
|
||||
i.ourPublicKey, _ = curve25519.X25519(i.secretKey, curve25519.Basepoint)
|
||||
return (*age.X25519Identity)(unsafe.Pointer(i)), nil
|
||||
}
|
||||
|
||||
func errorf(format string, v ...interface{}) {
|
||||
log.Fatalf("age-gen-passphrase ERROR: "+format, v...)
|
||||
}
|
||||
|
||||
57
flake.lock
generated
Normal file
57
flake.lock
generated
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 0,
|
||||
"narHash": "sha256-7Fu7oazPoYCbDzb9k8D/DdbKrC3aU1zlnc39Y8jy/s8=",
|
||||
"path": "/nix/store/m4wcdchjxw2fdyzjp8i6irpc613pchkr-source",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
13
flake.nix
Normal file
13
flake.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
inputs = {
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
outputs = {self, nixpkgs, flake-utils, ...}@inputs:
|
||||
flake-utils.lib.eachDefaultSystem
|
||||
(system:
|
||||
let pkgs = nixpkgs.legacyPackages.${system}; in
|
||||
{
|
||||
devShells.default = import ./shell.nix { inherit pkgs; };
|
||||
}
|
||||
);
|
||||
}
|
||||
8
go.mod
8
go.mod
@ -3,7 +3,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
|
||||
filippo.io/age v1.2.1
|
||||
golang.org/x/crypto v0.24.0
|
||||
golang.org/x/term v0.29.0
|
||||
)
|
||||
|
||||
require golang.org/x/sys v0.30.0 // indirect
|
||||
|
||||
8
go.sum
8
go.sum
@ -1,6 +1,10 @@
|
||||
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805 h1:u2qwJeEvnypw+OCPUHmoZE3IqwfuN5kgDfo5MLzpNM0=
|
||||
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805/go.mod h1:FomMrUJ2Lxt5jCLmZkG3FHa72zUprnhd3v/Z18Snm4w=
|
||||
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=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
|
||||
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user