Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitece3a2a

Browse files
committed
Add support for Ed25519 keys
1 parent2e5376c commitece3a2a

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module filippo.io/yubikey-agent
33
go1.19
44

55
require (
6-
github.com/go-piv/piv-gov1.10.0
6+
github.com/go-piv/piv-go/v2v2.3.0
77
github.com/twpayne/go-pinentry-minimalv0.0.0-20220113210447-2a5dc4396c2a
88
golang.org/x/cryptov0.4.0
99
golang.org/x/termv0.3.0

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/go-piv/piv-gov1.10.0 h1:P1Y1VjBI5DnXW0+YkKmTuh5opWnMIrKriUaIOblee9Q=
2-
github.com/go-piv/piv-gov1.10.0/go.mod h1:NZ2zmjVkfFaL/CF8cVQ/pXdXtuj110zEKGdJM6fJZZM=
1+
github.com/go-piv/piv-go/v2v2.3.0 h1:kKkrYlgLQTMPA6BiSL25A7/x4CEh2YCG7rtb/aTkx+g=
2+
github.com/go-piv/piv-go/v2v2.3.0/go.mod h1:ShZi74nnrWNQEdWzRUd/3cSig3uNOcEZp+EWl0oewnI=
33
github.com/twpayne/go-pinentry-minimalv0.0.0-20220113210447-2a5dc4396c2a h1:a1bRrtgkiv0tytmDVXU5Dqse/WOTws7JvsY2WxPMZ6M=
44
github.com/twpayne/go-pinentry-minimalv0.0.0-20220113210447-2a5dc4396c2a/go.mod h1:ARJJXqNuaxVS84jX6ST52hQh0TtuQZWABhTe95a6BI4=
55
golang.org/x/cryptov0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=

‎main.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bytes"
1111
"context"
1212
"crypto/ecdsa"
13+
"crypto/ed25519"
1314
"crypto/rand"
1415
"crypto/rsa"
1516
"errors"
@@ -28,7 +29,7 @@ import (
2829
"syscall"
2930
"time"
3031

31-
"github.com/go-piv/piv-go/piv"
32+
"github.com/go-piv/piv-go/v2/piv"
3233
"golang.org/x/crypto/ssh"
3334
"golang.org/x/crypto/ssh/agent"
3435
"golang.org/x/crypto/ssh/terminal"
@@ -249,6 +250,7 @@ func getPublicKey(yk *piv.YubiKey, slot piv.Slot) (ssh.PublicKey, error) {
249250
}
250251
switchcert.PublicKey.(type) {
251252
case*ecdsa.PublicKey:
253+
case ed25519.PublicKey:
252254
case*rsa.PublicKey:
253255
default:
254256
returnnil,fmt.Errorf("unexpected public key type: %T",cert.PublicKey)

‎setup.go‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"runtime/debug"
2222
"time"
2323

24-
"github.com/go-piv/piv-go/piv"
24+
"github.com/go-piv/piv-go/v2/piv"
2525
"golang.org/x/crypto/ssh"
2626
"golang.org/x/term"
2727
)
@@ -100,7 +100,15 @@ func runSetup(yk *piv.YubiKey) {
100100
fmt.Println("")
101101
fmt.Println("🧪 Reticulating splines...")
102102

103-
varkey [24]byte
103+
varversion=yk.Version()
104+
varkey []byte
105+
ifsupportsVersion(&version,5,4,0) {
106+
// Yubikey Firmware >=5.4.0 supports AES256 management keys
107+
key=make([]byte,32)
108+
}else {
109+
key=make([]byte,24)
110+
}
111+
104112
if_,err:=rand.Read(key[:]);err!=nil {
105113
log.Fatal(err)
106114
}
@@ -137,8 +145,16 @@ func runSetup(yk *piv.YubiKey) {
137145
log.Fatalln("use --really-delete-all-piv-keys ⚠️")
138146
}
139147

148+
varalg piv.Algorithm
149+
ifsupportsVersion(&version,5,7,0) {
150+
// For newer Yubikeys, upgrade the key automatically to Ed25519
151+
alg=piv.AlgorithmEd25519
152+
}else {
153+
alg=piv.AlgorithmEC256
154+
}
155+
140156
pub,err:=yk.GenerateKey(key,piv.SlotAuthentication, piv.Key{
141-
Algorithm:piv.AlgorithmEC256,
157+
Algorithm:alg,
142158
PINPolicy:piv.PINPolicyOnce,
143159
TouchPolicy:piv.TouchPolicyAlways,
144160
})
@@ -196,6 +212,16 @@ func runSetup(yk *piv.YubiKey) {
196212
fmt.Println("💭 Remember: everything breaks, have a backup plan for when this YubiKey does.")
197213
}
198214

215+
funcsupportsVersion(v*piv.Version,major,minor,patchint)bool {
216+
ifv.Major!=major {
217+
returnv.Major>major
218+
}
219+
ifv.Minor!=minor {
220+
returnv.Minor>minor
221+
}
222+
returnv.Patch>=patch
223+
}
224+
199225
funcrandomSerialNumber()*big.Int {
200226
serialNumberLimit:=new(big.Int).Lsh(big.NewInt(1),128)
201227
serialNumber,err:=rand.Int(rand.Reader,serialNumberLimit)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp