-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ssh: support RSA SHA-2 (RFC8332) signatures
This change adds support for RSA SHA-2 based signatures for host keys and certificates. It also switches the default certificate signature algorithm for RSA to use SHA-512. This is implemented by treating ssh.Signer specially when the key type is `ssh-rsa` by also allowing SHA-256 and SHA-512 signatures. Fixes golang/go#37278 Change-Id: I2ee1ac4ae4c9c1de441a2d6cf1e806357ef18910 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/220037 Trust: Jason A. Donenfeld <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jason A. Donenfeld <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
- Loading branch information
1 parent
ceb1ce7
commit b4de73f
Showing
12 changed files
with
213 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import ( | |
"time" | ||
) | ||
|
||
// These constants from [PROTOCOL.certkeys] represent the algorithm names | ||
// These constants from [PROTOCOL.certkeys] represent the key algorithm names | ||
// for certificate types supported by this package. | ||
const ( | ||
CertAlgoRSAv01 = "[email protected]" | ||
|
@@ -27,6 +27,14 @@ const ( | |
CertAlgoSKED25519v01 = "[email protected]" | ||
) | ||
|
||
// These constants from [PROTOCOL.certkeys] represent additional signature | ||
// algorithm names for certificate types supported by this package. | ||
const ( | ||
CertSigAlgoRSAv01 = "[email protected]" | ||
CertSigAlgoRSASHA2256v01 = "[email protected]" | ||
CertSigAlgoRSASHA2512v01 = "[email protected]" | ||
) | ||
|
||
// Certificate types distinguish between host and user | ||
// certificates. The values can be set in the CertType field of | ||
// Certificate. | ||
|
@@ -423,6 +431,12 @@ func (c *Certificate) SignCert(rand io.Reader, authority Signer) error { | |
} | ||
c.SignatureKey = authority.PublicKey() | ||
|
||
if v, ok := authority.(AlgorithmSigner); ok { | ||
if v.PublicKey().Type() == KeyAlgoRSA { | ||
authority = &rsaSigner{v, SigAlgoRSASHA2512} | ||
} | ||
} | ||
|
||
sig, err := authority.Sign(rand, c.bytesForSigning()) | ||
if err != nil { | ||
return err | ||
|
@@ -431,8 +445,14 @@ func (c *Certificate) SignCert(rand io.Reader, authority Signer) error { | |
return nil | ||
} | ||
|
||
// certAlgoNames includes a mapping from signature algorithms to the | ||
// corresponding certificate signature algorithm. When a key type (such | ||
// as ED25516) is associated with only one algorithm, the KeyAlgo | ||
// constant is used instead of the SigAlgo. | ||
var certAlgoNames = map[string]string{ | ||
KeyAlgoRSA: CertAlgoRSAv01, | ||
SigAlgoRSA: CertSigAlgoRSAv01, | ||
SigAlgoRSASHA2256: CertSigAlgoRSASHA2256v01, | ||
SigAlgoRSASHA2512: CertSigAlgoRSASHA2512v01, | ||
KeyAlgoDSA: CertAlgoDSAv01, | ||
KeyAlgoECDSA256: CertAlgoECDSA256v01, | ||
KeyAlgoECDSA384: CertAlgoECDSA384v01, | ||
|
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
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
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
Oops, something went wrong.