Skip to content

Commit 2f56ac5

Browse files
FiloSottilemaisem
authored andcommitted
ssh/agent: fix non-RSA certificates
The type of ssh.PublicKey.Type can be a certificate type, while the algorithm passed to SignWithAlgorithm is going to be an underlying algorithm. Fixes golang/go#52185 Change-Id: I0f7c46defa83d1fd64a3c1e861734650b20cca21 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/404614 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> Run-TryBot: Filippo Valsorda <[email protected]>
1 parent b245557 commit 2f56ac5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ssh/agent/client.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ func (s *agentKeyringSigner) Sign(rand io.Reader, data []byte) (*ssh.Signature,
772772
}
773773

774774
func (s *agentKeyringSigner) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*ssh.Signature, error) {
775-
if algorithm == "" || algorithm == s.pub.Type() {
775+
if algorithm == "" || algorithm == underlyingAlgo(s.pub.Type()) {
776776
return s.Sign(rand, data)
777777
}
778778

@@ -791,6 +791,33 @@ func (s *agentKeyringSigner) SignWithAlgorithm(rand io.Reader, data []byte, algo
791791

792792
var _ ssh.AlgorithmSigner = &agentKeyringSigner{}
793793

794+
// certKeyAlgoNames is a mapping from known certificate algorithm names to the
795+
// corresponding public key signature algorithm.
796+
//
797+
// This map must be kept in sync with the one in certs.go.
798+
var certKeyAlgoNames = map[string]string{
799+
ssh.CertAlgoRSAv01: ssh.KeyAlgoRSA,
800+
ssh.CertAlgoRSASHA256v01: ssh.KeyAlgoRSASHA256,
801+
ssh.CertAlgoRSASHA512v01: ssh.KeyAlgoRSASHA512,
802+
ssh.CertAlgoDSAv01: ssh.KeyAlgoDSA,
803+
ssh.CertAlgoECDSA256v01: ssh.KeyAlgoECDSA256,
804+
ssh.CertAlgoECDSA384v01: ssh.KeyAlgoECDSA384,
805+
ssh.CertAlgoECDSA521v01: ssh.KeyAlgoECDSA521,
806+
ssh.CertAlgoSKECDSA256v01: ssh.KeyAlgoSKECDSA256,
807+
ssh.CertAlgoED25519v01: ssh.KeyAlgoED25519,
808+
ssh.CertAlgoSKED25519v01: ssh.KeyAlgoSKED25519,
809+
}
810+
811+
// underlyingAlgo returns the signature algorithm associated with algo (which is
812+
// an advertised or negotiated public key or host key algorithm). These are
813+
// usually the same, except for certificate algorithms.
814+
func underlyingAlgo(algo string) string {
815+
if a, ok := certKeyAlgoNames[algo]; ok {
816+
return a
817+
}
818+
return algo
819+
}
820+
794821
// Calls an extension method. It is up to the agent implementation as to whether or not
795822
// any particular extension is supported and may always return an error. Because the
796823
// type of the response is up to the implementation, this returns the bytes of the

ssh/certs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ func (c *Certificate) SignCert(rand io.Reader, authority Signer) error {
460460

461461
// certKeyAlgoNames is a mapping from known certificate algorithm names to the
462462
// corresponding public key signature algorithm.
463+
//
464+
// This map must be kept in sync with the one in agent/client.go.
463465
var certKeyAlgoNames = map[string]string{
464466
CertAlgoRSAv01: KeyAlgoRSA,
465467
CertAlgoRSASHA256v01: KeyAlgoRSASHA256,

0 commit comments

Comments
 (0)