Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support Ed25519 keys in setup #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bytes"
"context"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rand"
"crypto/rsa"
"errors"
Expand Down Expand Up @@ -50,6 +51,7 @@ func main() {
}

socketPath := flag.String("l", "", "agent: path of the UNIX socket to listen on")
ed25519Flag := flag.Bool("ed25519", false, "setup: generate Ed25519 key")
resetFlag := flag.Bool("really-delete-all-piv-keys", false, "setup: reset the PIV applet")
setupFlag := flag.Bool("setup", false, "setup: configure a new YubiKey")
flag.Parse()
Expand All @@ -65,7 +67,7 @@ func main() {
if *resetFlag {
runReset(yk)
}
runSetup(yk)
runSetup(yk, *ed25519Flag)
} else {
if *socketPath == "" {
flag.Usage()
Expand Down Expand Up @@ -241,6 +243,7 @@ func getPublicKey(yk *piv.YubiKey, slot piv.Slot) (ssh.PublicKey, error) {
}
switch cert.PublicKey.(type) {
case *ecdsa.PublicKey:
case ed25519.PublicKey:
case *rsa.PublicKey:
default:
return nil, fmt.Errorf("unexpected public key type: %T", cert.PublicKey)
Expand Down
9 changes: 7 additions & 2 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func runReset(yk *piv.YubiKey) {
}
}

func runSetup(yk *piv.YubiKey) {
func runSetup(yk *piv.YubiKey, ed25519 bool) {
if _, err := yk.Certificate(piv.SlotAuthentication); err == nil {
log.Println("‼️ This YubiKey looks already setup")
log.Println("")
Expand Down Expand Up @@ -136,8 +136,13 @@ func runSetup(yk *piv.YubiKey) {
log.Fatalln("use --really-delete-all-piv-keys ⚠️")
}

alg := piv.AlgorithmEC256
if ed25519 {
// hack it in, this relies on the piv-go patch
alg = piv.AlgorithmEd25519
}
pub, err := yk.GenerateKey(key, piv.SlotAuthentication, piv.Key{
Algorithm: piv.AlgorithmEC256,
Algorithm: alg,
PINPolicy: piv.PINPolicyOnce,
TouchPolicy: piv.TouchPolicyAlways,
})
Expand Down