Skip to content

Commit

Permalink
Support Ed25519 keys in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nickray committed Jun 27, 2020
1 parent 47bc932 commit f31f10e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit f31f10e

Please sign in to comment.