|
@@ -367,6 +367,17 @@ func (r *dsaPublicKey) Type() string {
|
|
|
return "ssh-dss"
|
|
return "ssh-dss"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func checkDSAParams(param *dsa.Parameters) error {
|
|
|
|
|
+ // SSH specifies FIPS 186-2, which only provided a single size
|
|
|
|
|
+ // (1024 bits) DSA key. FIPS 186-3 allows for larger key
|
|
|
|
|
+ // sizes, which would confuse SSH.
|
|
|
|
|
+ if l := param.P.BitLen(); l != 1024 {
|
|
|
|
|
+ return fmt.Errorf("ssh: unsupported DSA key size %d", l)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// parseDSA parses an DSA key according to RFC 4253, section 6.6.
|
|
// parseDSA parses an DSA key according to RFC 4253, section 6.6.
|
|
|
func parseDSA(in []byte) (out PublicKey, rest []byte, err error) {
|
|
func parseDSA(in []byte) (out PublicKey, rest []byte, err error) {
|
|
|
var w struct {
|
|
var w struct {
|
|
@@ -377,13 +388,18 @@ func parseDSA(in []byte) (out PublicKey, rest []byte, err error) {
|
|
|
return nil, nil, err
|
|
return nil, nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ param := dsa.Parameters{
|
|
|
|
|
+ P: w.P,
|
|
|
|
|
+ Q: w.Q,
|
|
|
|
|
+ G: w.G,
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := checkDSAParams(¶m); err != nil {
|
|
|
|
|
+ return nil, nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
key := &dsaPublicKey{
|
|
key := &dsaPublicKey{
|
|
|
- Parameters: dsa.Parameters{
|
|
|
|
|
- P: w.P,
|
|
|
|
|
- Q: w.Q,
|
|
|
|
|
- G: w.G,
|
|
|
|
|
- },
|
|
|
|
|
- Y: w.Y,
|
|
|
|
|
|
|
+ Parameters: param,
|
|
|
|
|
+ Y: w.Y,
|
|
|
}
|
|
}
|
|
|
return key, w.Rest, nil
|
|
return key, w.Rest, nil
|
|
|
}
|
|
}
|
|
@@ -630,19 +646,28 @@ func (k *ecdsaPublicKey) CryptoPublicKey() crypto.PublicKey {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// NewSignerFromKey takes an *rsa.PrivateKey, *dsa.PrivateKey,
|
|
// NewSignerFromKey takes an *rsa.PrivateKey, *dsa.PrivateKey,
|
|
|
-// *ecdsa.PrivateKey or any other crypto.Signer and returns a corresponding
|
|
|
|
|
-// Signer instance. ECDSA keys must use P-256, P-384 or P-521.
|
|
|
|
|
|
|
+// *ecdsa.PrivateKey or any other crypto.Signer and returns a
|
|
|
|
|
+// corresponding Signer instance. ECDSA keys must use P-256, P-384 or
|
|
|
|
|
+// P-521. DSA keys must use parameter size L1024N160.
|
|
|
func NewSignerFromKey(key interface{}) (Signer, error) {
|
|
func NewSignerFromKey(key interface{}) (Signer, error) {
|
|
|
switch key := key.(type) {
|
|
switch key := key.(type) {
|
|
|
case crypto.Signer:
|
|
case crypto.Signer:
|
|
|
return NewSignerFromSigner(key)
|
|
return NewSignerFromSigner(key)
|
|
|
case *dsa.PrivateKey:
|
|
case *dsa.PrivateKey:
|
|
|
- return &dsaPrivateKey{key}, nil
|
|
|
|
|
|
|
+ return newDSAPrivateKey(key)
|
|
|
default:
|
|
default:
|
|
|
return nil, fmt.Errorf("ssh: unsupported key type %T", key)
|
|
return nil, fmt.Errorf("ssh: unsupported key type %T", key)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func newDSAPrivateKey(key *dsa.PrivateKey) (Signer, error) {
|
|
|
|
|
+ if err := checkDSAParams(&key.PublicKey.Parameters); err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return &dsaPrivateKey{key}, nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
type wrappedSigner struct {
|
|
type wrappedSigner struct {
|
|
|
signer crypto.Signer
|
|
signer crypto.Signer
|
|
|
pubKey PublicKey
|
|
pubKey PublicKey
|