-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: also list decryption keys for gnupg
- Loading branch information
Showing
11 changed files
with
253 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package securitykey | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/go-piv/piv-go/piv" | ||
"golang.org/x/crypto/openpgp/packet" | ||
) | ||
|
||
// DecryptionKey is a cryptographic decryption key on a hardware security | ||
// device. | ||
type DecryptionKey struct { | ||
CryptoKey | ||
PubPGP *packet.PublicKey | ||
} | ||
|
||
// decryptionKeys returns the decryption keys available on the given yubikey. | ||
func decryptionKeys(yk *piv.YubiKey) ([]DecryptionKey, error) { | ||
var decryptionKeys []DecryptionKey | ||
for _, s := range defaultDecryptSlots { | ||
cert, err := yk.Certificate(s.Slot) | ||
if err != nil { | ||
if errors.Is(err, piv.ErrNotFound) { | ||
continue | ||
} | ||
return nil, fmt.Errorf("couldn't get certificate for slot %x: %v", | ||
s.Slot.Key, err) | ||
} | ||
pubKey, ok := cert.PublicKey.(*ecdsa.PublicKey) | ||
if !ok { | ||
return nil, fmt.Errorf("invalid public key type: %T", cert.PublicKey) | ||
} | ||
decryptionKeys = append(decryptionKeys, DecryptionKey{ | ||
CryptoKey: CryptoKey{ | ||
Public: pubKey, | ||
SlotSpec: s, | ||
}, | ||
PubPGP: packet.NewECDSAPublicKey(cert.NotBefore, pubKey), | ||
}) | ||
} | ||
return decryptionKeys, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package securitykey | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/go-piv/piv-go/piv" | ||
"golang.org/x/crypto/openpgp/packet" | ||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
// SigningKey is a public signing key on a security key / hardware token. | ||
type SigningKey struct { | ||
CryptoKey | ||
PubSSH ssh.PublicKey | ||
PubPGP *packet.PublicKey | ||
} | ||
|
||
// signingKeys returns the signing keys available on the given yubikey. | ||
func signingKeys(yk *piv.YubiKey) ([]SigningKey, error) { | ||
var signingKeys []SigningKey | ||
for _, s := range defaultSignSlots { | ||
cert, err := yk.Certificate(s.Slot) | ||
if err != nil { | ||
if errors.Is(err, piv.ErrNotFound) { | ||
continue | ||
} | ||
return nil, fmt.Errorf("couldn't get certificate for slot %x: %v", | ||
s.Slot.Key, err) | ||
} | ||
pubKey, ok := cert.PublicKey.(*ecdsa.PublicKey) | ||
if !ok { | ||
return nil, fmt.Errorf("invalid public key type: %T", cert.PublicKey) | ||
} | ||
pubSSH, err := ssh.NewPublicKey(cert.PublicKey) | ||
if err != nil { | ||
return nil, fmt.Errorf("couldn't convert public key: %v", err) | ||
} | ||
signingKeys = append(signingKeys, SigningKey{ | ||
CryptoKey: CryptoKey{ | ||
Public: pubKey, | ||
SlotSpec: s, | ||
}, | ||
PubSSH: pubSSH, | ||
PubPGP: packet.NewECDSAPublicKey(cert.NotBefore, pubKey), | ||
}) | ||
} | ||
return signingKeys, nil | ||
} |
Oops, something went wrong.