Skip to content

Commit

Permalink
Fix parse error when using key fingerprints
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bobveznat committed Feb 11, 2019
1 parent 7952e33 commit 80ee634
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TAG?=1.6.2
TAG?=1.7.1
VERSION := $(shell echo `git describe --tags --long --match=*.*.* --dirty` | sed s/version-//g)

PKG=github.com/cloudtools/ssh-cert-authority
Expand Down
2 changes: 1 addition & 1 deletion sign_certd.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ func (h *certRequestHandler) maybeSignWithCa(requestID string, numSignersRequire
return true, nil
}
log.Printf("Received %d signatures for %s, signing now.\n", len(h.state[requestID].signatures), requestID)
signer, err := ssh_ca_util.GetSignerForFingerprint(signingKeyFingerprint, h.sshAgentConn)
signer, err := ssh_ca_util.GetSignerForFingerprintOrUrl(signingKeyFingerprint, h.sshAgentConn)
if err != nil {
log.Printf("Couldn't find signing key for request %s, unable to sign request: %s\n", requestID, err)
return false, fmt.Errorf("Couldn't find signing key, unable to sign. Sorry.")
Expand Down
18 changes: 12 additions & 6 deletions util/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ import (
"golang.org/x/crypto/ssh/agent"
"io"
"net/url"
"regexp"
)

func GetSignerForFingerprint(fingerprint string, conn io.ReadWriter) (ssh.Signer, error) {
var md5Fingerprint = regexp.MustCompile("([0-9a-fA-F]{2}:){15}[0-9a-fA-F]{2}")

func GetSignerForFingerprintOrUrl(fingerprint string, conn io.ReadWriter) (ssh.Signer, error) {
isFingerprint := md5Fingerprint.MatchString(fingerprint)
if isFingerprint {
return GetSignerForFingerprint(fingerprint, conn)
}
keyUrl, err := url.Parse(fingerprint)
if err != nil {
return nil, fmt.Errorf("Ignoring invalid private key url: '%s'. Error parsing: %s", fingerprint, err)
}
if keyUrl.Scheme == "gcpkms" {
return getSignerForGcpKms(keyUrl.Path)
} else {
return getSignerForSshAgent(fingerprint, conn)
if keyUrl.Scheme != "gcpkms" {
return nil, fmt.Errorf("gcpkms:// is the only supported url scheme")
}
return getSignerForGcpKms(keyUrl.Path)
}
func getSignerForGcpKms(keyUrl string) (ssh.Signer, error) {
return signer.NewSshGcpKmsSigner(keyUrl)
}

func getSignerForSshAgent(fingerprint string, conn io.ReadWriter) (ssh.Signer, error) {
func GetSignerForFingerprint(fingerprint string, conn io.ReadWriter) (ssh.Signer, error) {
sshAgent := agent.NewClient(conn)
signers, err := sshAgent.Signers()
if err != nil {
Expand Down

0 comments on commit 80ee634

Please sign in to comment.