Skip to content

Commit 3147a52

Browse files
committed
ssh: support rsa-sha2-256/512 for client certificates
The server-sig-algs logic was not working for certificate algorithms. Follow-up on CL 392394. Tested with OpenSSH 8.8 configured with PubkeyAcceptedKeyTypes -ssh-rsa-cert-v01@openssh.com Updates golang/go#39885 For golang/go#49952 Change-Id: Ic230dd6f98e96b7938acbd0128ab37d33b70abe5 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/392974 Trust: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent 5d542ad commit 3147a52

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

ssh/certs.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,17 @@ func underlyingAlgo(algo string) string {
483483
return algo
484484
}
485485

486+
// certificateAlgo returns the certificate algorithms that uses the provided
487+
// underlying signature algorithm.
488+
func certificateAlgo(algo string) (certAlgo string, ok bool) {
489+
for certName, algoName := range certKeyAlgoNames {
490+
if algoName == algo {
491+
return certName, true
492+
}
493+
}
494+
return "", false
495+
}
496+
486497
func (cert *Certificate) bytesForSigning() []byte {
487498
c2 := *cert
488499
c2.Signature = nil
@@ -526,13 +537,11 @@ func (c *Certificate) Marshal() []byte {
526537

527538
// Type returns the certificate algorithm name. It is part of the PublicKey interface.
528539
func (c *Certificate) Type() string {
529-
keyType := c.Key.Type()
530-
for certName, keyName := range certKeyAlgoNames {
531-
if keyName == keyType {
532-
return certName
533-
}
540+
certName, ok := certificateAlgo(c.Key.Type())
541+
if !ok {
542+
panic("unknown certificate type for key type " + c.Key.Type())
534543
}
535-
panic("unknown certificate type for key type " + keyType)
544+
return certName
536545
}
537546

538547
// Verify verifies a signature against the certificate's public

ssh/client_auth.go

+10
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,17 @@ func pickSignatureAlgorithm(signer Signer, extensions map[string][]byte) (as Alg
234234
return as, keyFormat
235235
}
236236

237+
// The server-sig-algs extension only carries underlying signature
238+
// algorithm, but we are trying to select a protocol-level public key
239+
// algorithm, which might be a certificate type. Extend the list of server
240+
// supported algorithms to include the corresponding certificate algorithms.
237241
serverAlgos := strings.Split(string(extPayload), ",")
242+
for _, algo := range serverAlgos {
243+
if certAlgo, ok := certificateAlgo(algo); ok {
244+
serverAlgos = append(serverAlgos, certAlgo)
245+
}
246+
}
247+
238248
keyAlgos := algorithmsForKeyFormat(keyFormat)
239249
algo, err := findCommon("public key signature algorithm", keyAlgos, serverAlgos)
240250
if err != nil {

0 commit comments

Comments
 (0)