Skip to content

Commit be51022

Browse files
authored
Remove the remnants of DSA support (miekg#1184)
crypto/dsa is formally deprecated as of go1.16 and DSA support was largely removed from this library in 9c315c5, but some remnants remained.
1 parent 6d41f43 commit be51022

6 files changed

+13
-88
lines changed

dnssec.go

+4-39
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package dns
33
import (
44
"bytes"
55
"crypto"
6-
"crypto/dsa"
76
"crypto/ecdsa"
87
"crypto/elliptic"
98
_ "crypto/md5"
@@ -318,6 +317,7 @@ func (rr *RRSIG) Sign(k crypto.Signer, rrset []RR) error {
318317
}
319318

320319
rr.Signature = toBase64(signature)
320+
return nil
321321
case RSAMD5, DSA, DSANSEC3SHA1:
322322
// See RFC 6944.
323323
return ErrAlg
@@ -332,9 +332,8 @@ func (rr *RRSIG) Sign(k crypto.Signer, rrset []RR) error {
332332
}
333333

334334
rr.Signature = toBase64(signature)
335+
return nil
335336
}
336-
337-
return nil
338337
}
339338

340339
func sign(k crypto.Signer, hashed []byte, hash crypto.Hash, alg uint8) ([]byte, error) {
@@ -346,7 +345,6 @@ func sign(k crypto.Signer, hashed []byte, hash crypto.Hash, alg uint8) ([]byte,
346345
switch alg {
347346
case RSASHA1, RSASHA1NSEC3SHA1, RSASHA256, RSASHA512:
348347
return signature, nil
349-
350348
case ECDSAP256SHA256, ECDSAP384SHA384:
351349
ecdsaSignature := &struct {
352350
R, S *big.Int
@@ -366,20 +364,11 @@ func sign(k crypto.Signer, hashed []byte, hash crypto.Hash, alg uint8) ([]byte,
366364
signature := intToBytes(ecdsaSignature.R, intlen)
367365
signature = append(signature, intToBytes(ecdsaSignature.S, intlen)...)
368366
return signature, nil
369-
370-
// There is no defined interface for what a DSA backed crypto.Signer returns
371-
case DSA, DSANSEC3SHA1:
372-
// t := divRoundUp(divRoundUp(p.PublicKey.Y.BitLen(), 8)-64, 8)
373-
// signature := []byte{byte(t)}
374-
// signature = append(signature, intToBytes(r1, 20)...)
375-
// signature = append(signature, intToBytes(s1, 20)...)
376-
// rr.Signature = signature
377-
378367
case ED25519:
379368
return signature, nil
369+
default:
370+
return nil, ErrAlg
380371
}
381-
382-
return nil, ErrAlg
383372
}
384373

385374
// Verify validates an RRSet with the signature and key. This is only the
@@ -600,30 +589,6 @@ func (k *DNSKEY) publicKeyECDSA() *ecdsa.PublicKey {
600589
return pubkey
601590
}
602591

603-
func (k *DNSKEY) publicKeyDSA() *dsa.PublicKey {
604-
keybuf, err := fromBase64([]byte(k.PublicKey))
605-
if err != nil {
606-
return nil
607-
}
608-
if len(keybuf) < 22 {
609-
return nil
610-
}
611-
t, keybuf := int(keybuf[0]), keybuf[1:]
612-
size := 64 + t*8
613-
q, keybuf := keybuf[:20], keybuf[20:]
614-
if len(keybuf) != 3*size {
615-
return nil
616-
}
617-
p, keybuf := keybuf[:size], keybuf[size:]
618-
g, y := keybuf[:size], keybuf[size:]
619-
pubkey := new(dsa.PublicKey)
620-
pubkey.Parameters.Q = new(big.Int).SetBytes(q)
621-
pubkey.Parameters.P = new(big.Int).SetBytes(p)
622-
pubkey.Parameters.G = new(big.Int).SetBytes(g)
623-
pubkey.Y = new(big.Int).SetBytes(y)
624-
return pubkey
625-
}
626-
627592
func (k *DNSKEY) publicKeyED25519() ed25519.PublicKey {
628593
keybuf, err := fromBase64([]byte(k.PublicKey))
629594
if err != nil {

dnssec_keygen.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
// bits should be set to the size of the algorithm.
2020
func (k *DNSKEY) Generate(bits int) (crypto.PrivateKey, error) {
2121
switch k.Algorithm {
22-
case RSAMD5, DSA, DSANSEC3SHA1:
23-
return nil, ErrAlg
2422
case RSASHA1, RSASHA256, RSASHA1NSEC3SHA1:
2523
if bits < 512 || bits > 4096 {
2624
return nil, ErrKeySize
@@ -41,6 +39,8 @@ func (k *DNSKEY) Generate(bits int) (crypto.PrivateKey, error) {
4139
if bits != 256 {
4240
return nil, ErrKeySize
4341
}
42+
default:
43+
return nil, ErrAlg
4444
}
4545

4646
switch k.Algorithm {

dnssec_keyscan.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,7 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, er
4343
return nil, ErrPrivKey
4444
}
4545
switch uint8(algo) {
46-
case RSAMD5, DSA, DSANSEC3SHA1:
47-
return nil, ErrAlg
48-
case RSASHA1:
49-
fallthrough
50-
case RSASHA1NSEC3SHA1:
51-
fallthrough
52-
case RSASHA256:
53-
fallthrough
54-
case RSASHA512:
46+
case RSASHA1, RSASHA1NSEC3SHA1, RSASHA256, RSASHA512:
5547
priv, err := readPrivateKeyRSA(m)
5648
if err != nil {
5749
return nil, err
@@ -62,11 +54,7 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, er
6254
}
6355
priv.PublicKey = *pub
6456
return priv, nil
65-
case ECCGOST:
66-
return nil, ErrPrivKey
67-
case ECDSAP256SHA256:
68-
fallthrough
69-
case ECDSAP384SHA384:
57+
case ECDSAP256SHA256, ECDSAP384SHA384:
7058
priv, err := readPrivateKeyECDSA(m)
7159
if err != nil {
7260
return nil, err
@@ -80,7 +68,7 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, er
8068
case ED25519:
8169
return readPrivateKeyED25519(m)
8270
default:
83-
return nil, ErrPrivKey
71+
return nil, ErrAlg
8472
}
8573
}
8674

dnssec_privkey.go

+2-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dns
22

33
import (
44
"crypto"
5-
"crypto/dsa"
65
"crypto/ecdsa"
76
"crypto/rsa"
87
"math/big"
@@ -17,8 +16,8 @@ var bigIntOne = big.NewInt(1)
1716

1817
// PrivateKeyString converts a PrivateKey to a string. This string has the same
1918
// format as the private-key-file of BIND9 (Private-key-format: v1.3).
20-
// It needs some info from the key (the algorithm), so its a method of the DNSKEY
21-
// It supports rsa.PrivateKey, ecdsa.PrivateKey and dsa.PrivateKey
19+
// It needs some info from the key (the algorithm), so its a method of the DNSKEY.
20+
// It supports *rsa.PrivateKey, *ecdsa.PrivateKey and ed25519.PrivateKey.
2221
func (r *DNSKEY) PrivateKeyString(p crypto.PrivateKey) string {
2322
algorithm := strconv.Itoa(int(r.Algorithm))
2423
algorithm += " (" + AlgorithmToString[r.Algorithm] + ")"
@@ -67,21 +66,6 @@ func (r *DNSKEY) PrivateKeyString(p crypto.PrivateKey) string {
6766
"Algorithm: " + algorithm + "\n" +
6867
"PrivateKey: " + private + "\n"
6968

70-
case *dsa.PrivateKey:
71-
T := divRoundUp(divRoundUp(p.PublicKey.Parameters.G.BitLen(), 8)-64, 8)
72-
prime := toBase64(intToBytes(p.PublicKey.Parameters.P, 64+T*8))
73-
subprime := toBase64(intToBytes(p.PublicKey.Parameters.Q, 20))
74-
base := toBase64(intToBytes(p.PublicKey.Parameters.G, 64+T*8))
75-
priv := toBase64(intToBytes(p.X, 20))
76-
pub := toBase64(intToBytes(p.PublicKey.Y, 64+T*8))
77-
return format +
78-
"Algorithm: " + algorithm + "\n" +
79-
"Prime(p): " + prime + "\n" +
80-
"Subprime(q): " + subprime + "\n" +
81-
"Base(g): " + base + "\n" +
82-
"Private_value(x): " + priv + "\n" +
83-
"Public_value(y): " + pub + "\n"
84-
8569
case ed25519.PrivateKey:
8670
private := toBase64(p.Seed())
8771
return format +

doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ From RFC 2931:
260260
on requests and responses, and protection of the overall integrity of a response.
261261
262262
It works like TSIG, except that SIG(0) uses public key cryptography, instead of
263-
the shared secret approach in TSIG. Supported algorithms: DSA, ECDSAP256SHA256,
263+
the shared secret approach in TSIG. Supported algorithms: ECDSAP256SHA256,
264264
ECDSAP384SHA384, RSASHA1, RSASHA256 and RSASHA512.
265265
266266
Signing subsequent messages in multi-message sessions is not implemented.

sig0.go

+1-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dns
22

33
import (
44
"crypto"
5-
"crypto/dsa"
65
"crypto/ecdsa"
76
"crypto/rsa"
87
"encoding/binary"
@@ -85,7 +84,7 @@ func (rr *SIG) Verify(k *KEY, buf []byte) error {
8584

8685
var hash crypto.Hash
8786
switch rr.Algorithm {
88-
case DSA, RSASHA1:
87+
case RSASHA1:
8988
hash = crypto.SHA1
9089
case RSASHA256, ECDSAP256SHA256:
9190
hash = crypto.SHA256
@@ -178,17 +177,6 @@ func (rr *SIG) Verify(k *KEY, buf []byte) error {
178177
hashed := hasher.Sum(nil)
179178
sig := buf[sigend:]
180179
switch k.Algorithm {
181-
case DSA:
182-
pk := k.publicKeyDSA()
183-
sig = sig[1:]
184-
r := new(big.Int).SetBytes(sig[:len(sig)/2])
185-
s := new(big.Int).SetBytes(sig[len(sig)/2:])
186-
if pk != nil {
187-
if dsa.Verify(pk, hashed, r, s) {
188-
return nil
189-
}
190-
return ErrSig
191-
}
192180
case RSASHA1, RSASHA256, RSASHA512:
193181
pk := k.publicKeyRSA()
194182
if pk != nil {

0 commit comments

Comments
 (0)