Skip to content

Commit 80ee634

Browse files
committed
Fix parse error when using key fingerprints
The last release broke using private key fingerprints. This change fixes that up so that we properly delineate fingerprints and kms urls and handle them each appropriately.
1 parent 7952e33 commit 80ee634

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TAG?=1.6.2
1+
TAG?=1.7.1
22
VERSION := $(shell echo `git describe --tags --long --match=*.*.* --dirty` | sed s/version-//g)
33

44
PKG=github.com/cloudtools/ssh-cert-authority

sign_certd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ func (h *certRequestHandler) maybeSignWithCa(requestID string, numSignersRequire
655655
return true, nil
656656
}
657657
log.Printf("Received %d signatures for %s, signing now.\n", len(h.state[requestID].signatures), requestID)
658-
signer, err := ssh_ca_util.GetSignerForFingerprint(signingKeyFingerprint, h.sshAgentConn)
658+
signer, err := ssh_ca_util.GetSignerForFingerprintOrUrl(signingKeyFingerprint, h.sshAgentConn)
659659
if err != nil {
660660
log.Printf("Couldn't find signing key for request %s, unable to sign request: %s\n", requestID, err)
661661
return false, fmt.Errorf("Couldn't find signing key, unable to sign. Sorry.")

util/ssh.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,30 @@ import (
77
"golang.org/x/crypto/ssh/agent"
88
"io"
99
"net/url"
10+
"regexp"
1011
)
1112

12-
func GetSignerForFingerprint(fingerprint string, conn io.ReadWriter) (ssh.Signer, error) {
13+
var md5Fingerprint = regexp.MustCompile("([0-9a-fA-F]{2}:){15}[0-9a-fA-F]{2}")
14+
15+
func GetSignerForFingerprintOrUrl(fingerprint string, conn io.ReadWriter) (ssh.Signer, error) {
16+
isFingerprint := md5Fingerprint.MatchString(fingerprint)
17+
if isFingerprint {
18+
return GetSignerForFingerprint(fingerprint, conn)
19+
}
1320
keyUrl, err := url.Parse(fingerprint)
1421
if err != nil {
1522
return nil, fmt.Errorf("Ignoring invalid private key url: '%s'. Error parsing: %s", fingerprint, err)
1623
}
17-
if keyUrl.Scheme == "gcpkms" {
18-
return getSignerForGcpKms(keyUrl.Path)
19-
} else {
20-
return getSignerForSshAgent(fingerprint, conn)
24+
if keyUrl.Scheme != "gcpkms" {
25+
return nil, fmt.Errorf("gcpkms:// is the only supported url scheme")
2126
}
27+
return getSignerForGcpKms(keyUrl.Path)
2228
}
2329
func getSignerForGcpKms(keyUrl string) (ssh.Signer, error) {
2430
return signer.NewSshGcpKmsSigner(keyUrl)
2531
}
2632

27-
func getSignerForSshAgent(fingerprint string, conn io.ReadWriter) (ssh.Signer, error) {
33+
func GetSignerForFingerprint(fingerprint string, conn io.ReadWriter) (ssh.Signer, error) {
2834
sshAgent := agent.NewClient(conn)
2935
signers, err := sshAgent.Signers()
3036
if err != nil {

0 commit comments

Comments
 (0)