You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x/crypto/ssh: ParseDSAPrivateKey lacks validation for DSA parameters #80418
ParseDSAPrivateKey parses PEM/DER-encoded DSA private keys without validating the DSA parameters (P , Q , G , Y ). This allows structurally valid ASN.1 encoded keys with malformed or out-of-range parameters (such as an extremely large Q ) to be parsed successfully. Subsequent operations on these keys, such as dsa.Sign or dsa.Verify , can consume excessive CPU.
This is inconsistent with parseDSA and parseDSAKey , which validate parameters via checkDSAParams and range checks on Y.
Expected Behavior
ParseDSAPrivateKey should validate that:
• Q and P bit lengths are correct.
• G and Y are within the valid group range.
Actual Behavior
ParseDSAPrivateKey passes the parsed ASN.1 values directly to the dsa.PrivateKey structure without validation.
Minimal Example
package main
import (
"crypto/dsa"
"encoding/asn1"
"encoding/pem"
"fmt"
"math/big"
"time"
"golang.org/x/crypto/ssh"
)
func main() {
hugeQ := new(big.Int).Lsh(big.NewInt(1), 20000)
p := new(big.Int).Lsh(big.NewInt(1), 1023)
g := big.NewInt(2)
y := big.NewInt(5)
x := big.NewInt(7)
type dsaKeyASN1 struct {
Version int
P, Q, G, Pub, Priv *big.Int
}
der, _ := asn1.Marshal(dsaKeyASN1{0, p, hugeQ, g, y, x})
pemBlock := pem.EncodeToMemory(&pem.Block{
Type: "DSA PRIVATE KEY",
Bytes: der,
})
key, err := ssh.ParseRawPrivateKey(pemBlock)
if err != nil {
fmt.Printf("Parse error: %v\n", err)
return
}
if priv, ok := key.(*dsa.PrivateKey); ok {
start := time.Now()
_, _ = dsa.Sign(nil, priv, make([]byte, 20))
fmt.Printf("Sign took: %v\n", time.Since(start))
}
}
Output:
Parse error: <nil>
Sign took: [very long]
This was originally reported by Prasanna Dabi (@prasanna8585).
For context on how far behind upstream we are: OpenSSH disabled ssh-dss host and user keys by default at run time in 7.0(2015-08-11), stopped compiling DSA in by default in 9.8 (2024-07-01), and removed the code entirely in 10.0 (2025-04-09).
On Red Hat systems DSA has not been usable with OpenSSH clients since RHEL 8: DSA host keys are not accepted even when the system-wide cryptographic policy is set to LEGACY.
We still lists ssh-dss and ssh-dss-cert-v01@openssh.com in defaultHostKeyAlgos and defaultPubKeyAuthAlgos, so DSA is enabled by default outside FIPS mode.
I reviewed the linked CL and left a few comments. That said, I would seriously consider implementing the proposal and removing DSA support altogether instead of merging this change.
Reacted by Daniel McCarney, Roland Bracewell Shoemaker, Tom Thorogood and Filippo Valsorda
@rolandshoemaker I would prefer to remove DSA entirely, and I say that fully aware that some of my users still rely on it and that I'll have to add it back to my fork.
If we want to be more conservative, we may consider a different approach.
Currently:
ParsePrivateKey, ParseRawPrivateKey and ParseRawPrivateKeyWithPassphrase transparently accept a DSA key.
ssh-dss and ssh-dss-cert-v01@openssh.com are in defaultHostKeyAlgos, so a client accepts DSA host keys out of the box.
Server side, ssh-dss is in defaultPubKeyAuthAlgos and is advertised in the server-sig-algs extension.
The agent client and server accept DSA keys.
Note that crypto/dsa itself is already marked Deprecated in the standard library.
Signing can be pushed to the user, but verification cannot: reading an ssh-dss key off the wire and verifying a DSA signature are inherently internal, so that code stays implemented and simply becomes opt-in.
We may start by changing the defaults:
Drop InsecureCertAlgoDSAv01 and InsecureKeyAlgoDSA from defaultHostKeyAlgos.
Drop InsecureKeyAlgoDSA from defaultPubKeyAuthAlgos.
Leave insecureHostKeyAlgos and insecurePubKeyAuthAlgos unchanged; NewServerConn validates PublicKeyAuthAlgorithms against SupportedAlgorithms() plus InsecureAlgorithms(), so removing them there would break the opt-in itself.
Opt-in is then ClientConfig.HostKeyAlgorithms on the client and ServerConfig.PublicKeyAuthAlgorithms on the server.
Loading a DSA key should be explicit:
In the "DSA PRIVATE KEY" case in ParseRawPrivateKey and ParseRawPrivateKeyWithPassphrase, return an explicit error instead of parsing a DSA key.
Keep the *dsa.PrivateKey case in NewSignerFromKey and the *dsa.PublicKey case in NewPublicKey: a caller needs a way to build an ssh.PublicKey of type ssh-dss for a custom signer. Document DSA support in both as deprecated.
For the agent I would remove DSA entirely. One thing this does not cover: agent.Client.List and Signers would still enumerate ssh-dss identities held by a remote agent, because that we read the format string off the wire.
We should still fix this issue: ParseDSAPrivateKey stays exported and becomes the only entry point for a DSA private key, so it still has to validate its input.
Breaking changes:
ssh.ParsePrivateKey on a DSA PEM starts failing. The migration path is pem.Decode(pemBytes) + ParseDSAPrivateKey + NewSignerFromKey.
Servers stop accepting DSA client authentication unless PublicKeyAuthAlgorithms is set explicitly.
Clients stop accepting DSA host keys unless HostKeyAlgorithms is set explicitly.
OpenSSH is (in my understanding) generally quite conservative. If they have dropped DSA support, I would assume the user base is small enough that we can also remove it. If we think there are still some reasonable number of users we still need to support, then the conservative path seems reasonable, but if its really quite small I'd suggest just dropping it outright at this point. All that said, my handle on the SSH ecosystem is quite weak, so I'd defer to you here.
Activity
gabyhelp commentedon Jul 15, 2026
Related Issues
Related Discussions
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
gopherbot commentedon Jul 16, 2026
Change https://go.dev/cl/801440 mentions this issue:
ssh: validate DSA parameters in ParseDSAPrivateKeyprattmic commentedon Jul 17, 2026
cc @golang/security
gopherbot commentedon Jul 19, 2026
Change https://go.dev/cl/802860 mentions this issue:
ssh/agent: validate DSA private value X in parseDSAKey and parseDSACertdrakkan commentedon Jul 27, 2026
We have an accepted proposal to remove DSA support from x/crypto/ssh:
#40337
For context on how far behind upstream we are: OpenSSH disabled
ssh-dsshost and user keys by default at run time in 7.0(2015-08-11), stopped compiling DSA in by default in 9.8 (2024-07-01), and removed the code entirely in 10.0 (2025-04-09).On Red Hat systems DSA has not been usable with OpenSSH clients since RHEL 8: DSA host keys are not accepted even when the system-wide cryptographic policy is set to LEGACY.
We still lists
ssh-dssandssh-dss-cert-v01@openssh.comindefaultHostKeyAlgosanddefaultPubKeyAuthAlgos, so DSA is enabled by default outside FIPS mode.I reviewed the linked CL and left a few comments. That said, I would seriously consider implementing the proposal and removing DSA support altogether instead of merging this change.
rolandshoemaker commentedon Jul 27, 2026
Strongly in favor of just removing DSA if we can without hurting ecosystem compatibility too much (which it sounds like we can).
drakkan commentedon Jul 28, 2026
@rolandshoemaker I would prefer to remove DSA entirely, and I say that fully aware that some of my users still rely on it and that I'll have to add it back to my fork.
If we want to be more conservative, we may consider a different approach.
Currently:
ParsePrivateKey,ParseRawPrivateKeyandParseRawPrivateKeyWithPassphrasetransparently accept a DSA key.ssh-dssandssh-dss-cert-v01@openssh.comare indefaultHostKeyAlgos, so a client accepts DSA host keys out of the box.ssh-dssis indefaultPubKeyAuthAlgosand is advertised in theserver-sig-algsextension.Note that
crypto/dsaitself is already markedDeprecatedin the standard library.Signing can be pushed to the user, but verification cannot: reading an
ssh-dsskey off the wire and verifying a DSA signature are inherently internal, so that code stays implemented and simply becomes opt-in.We may start by changing the defaults:
InsecureCertAlgoDSAv01andInsecureKeyAlgoDSAfromdefaultHostKeyAlgos.InsecureKeyAlgoDSAfromdefaultPubKeyAuthAlgos.insecureHostKeyAlgosandinsecurePubKeyAuthAlgosunchanged;NewServerConnvalidatesPublicKeyAuthAlgorithmsagainstSupportedAlgorithms()plusInsecureAlgorithms(), so removing them there would break the opt-in itself.Opt-in is then
ClientConfig.HostKeyAlgorithmson the client andServerConfig.PublicKeyAuthAlgorithmson the server.Loading a DSA key should be explicit:
"DSA PRIVATE KEY"case inParseRawPrivateKeyandParseRawPrivateKeyWithPassphrase, return an explicit error instead of parsing a DSA key.ParseDSAPrivateKeyexported, marked// Deprecated.*dsa.PrivateKeycase inNewSignerFromKeyand the*dsa.PublicKeycase inNewPublicKey: a caller needs a way to build anssh.PublicKeyof typessh-dssfor a custom signer. Document DSA support in both as deprecated.For the agent I would remove DSA entirely. One thing this does not cover:
agent.Client.ListandSignerswould still enumeratessh-dssidentities held by a remote agent, because that we read the format string off the wire.We should still fix this issue:
ParseDSAPrivateKeystays exported and becomes the only entry point for a DSA private key, so it still has to validate its input.Breaking changes:
ssh.ParsePrivateKeyon a DSA PEM starts failing. The migration path ispem.Decode(pemBytes)+ParseDSAPrivateKey+NewSignerFromKey.PublicKeyAuthAlgorithmsis set explicitly.HostKeyAlgorithmsis set explicitly.ssh-addof a DSA key against a Go agent fails.rolandshoemaker commentedon Jul 28, 2026
OpenSSH is (in my understanding) generally quite conservative. If they have dropped DSA support, I would assume the user base is small enough that we can also remove it. If we think there are still some reasonable number of users we still need to support, then the conservative path seems reasonable, but if its really quite small I'd suggest just dropping it outright at this point. All that said, my handle on the SSH ecosystem is quite weak, so I'd defer to you here.
@FiloSottile do you have opinions on this?
gopherbot commentedon Oct 11, 2026
Change https://go.dev/cl/848607 mentions this issue:
ssh: remove DSA supportssh: remove DSA support