summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/crypto/ssh/certs.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/crypto/ssh/certs.go')
-rw-r--r--vendor/golang.org/x/crypto/ssh/certs.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/vendor/golang.org/x/crypto/ssh/certs.go b/vendor/golang.org/x/crypto/ssh/certs.go
index a3dc629c6..139fa31e1 100644
--- a/vendor/golang.org/x/crypto/ssh/certs.go
+++ b/vendor/golang.org/x/crypto/ssh/certs.go
@@ -233,7 +233,11 @@ func parseCert(in []byte, privAlgo string) (*Certificate, error) {
if err != nil {
return nil, err
}
-
+ // The Type() function is intended to return only certificate key types, but
+ // we use certKeyAlgoNames anyway for safety, to match [Certificate.Type].
+ if _, ok := certKeyAlgoNames[k.Type()]; ok {
+ return nil, fmt.Errorf("ssh: the signature key type %q is invalid for certificates", k.Type())
+ }
c.SignatureKey = k
c.Signature, rest, ok = parseSignatureBody(g.Signature)
if !ok || len(rest) > 0 {
@@ -301,16 +305,13 @@ type CertChecker struct {
SupportedCriticalOptions []string
// IsUserAuthority should return true if the key is recognized as an
- // authority for the given user certificate. This allows for
- // certificates to be signed by other certificates. This must be set
- // if this CertChecker will be checking user certificates.
+ // authority for user certificate. This must be set if this CertChecker
+ // will be checking user certificates.
IsUserAuthority func(auth PublicKey) bool
// IsHostAuthority should report whether the key is recognized as
- // an authority for this host. This allows for certificates to be
- // signed by other keys, and for those other keys to only be valid
- // signers for particular hostnames. This must be set if this
- // CertChecker will be checking host certificates.
+ // an authority for this host. This must be set if this CertChecker
+ // will be checking host certificates.
IsHostAuthority func(auth PublicKey, address string) bool
// Clock is used for verifying time stamps. If nil, time.Now
@@ -447,12 +448,19 @@ func (c *CertChecker) CheckCert(principal string, cert *Certificate) error {
// SignCert signs the certificate with an authority, setting the Nonce,
// SignatureKey, and Signature fields. If the authority implements the
// MultiAlgorithmSigner interface the first algorithm in the list is used. This
-// is useful if you want to sign with a specific algorithm.
+// is useful if you want to sign with a specific algorithm. As specified in
+// [SSH-CERTS], Section 2.1.1, authority can't be a [Certificate].
func (c *Certificate) SignCert(rand io.Reader, authority Signer) error {
c.Nonce = make([]byte, 32)
if _, err := io.ReadFull(rand, c.Nonce); err != nil {
return err
}
+ // The Type() function is intended to return only certificate key types, but
+ // we use certKeyAlgoNames anyway for safety, to match [Certificate.Type].
+ if _, ok := certKeyAlgoNames[authority.PublicKey().Type()]; ok {
+ return fmt.Errorf("ssh: certificates cannot be used as authority (public key type %q)",
+ authority.PublicKey().Type())
+ }
c.SignatureKey = authority.PublicKey()
if v, ok := authority.(MultiAlgorithmSigner); ok {