Skip to content

Commit 07b0c64

Browse files
committed
DNSSEC: reorganize the files, add a go13 tag
1 parent 2e5a43c commit 07b0c64

File tree

9 files changed

+970
-969
lines changed

9 files changed

+970
-969
lines changed

dnssec.go

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ import (
77
"crypto/ecdsa"
88
"crypto/elliptic"
99
_ "crypto/md5"
10-
"crypto/rand"
1110
"crypto/rsa"
1211
_ "crypto/sha1"
1312
_ "crypto/sha256"
1413
_ "crypto/sha512"
15-
"encoding/asn1"
1614
"encoding/hex"
1715
"math/big"
1816
"sort"
@@ -232,119 +230,6 @@ func (k *DNSKEY) ToDS(h uint8) *DS {
232230
return ds
233231
}
234232

235-
// Sign signs an RRSet. The signature needs to be filled in with
236-
// the values: Inception, Expiration, KeyTag, SignerName and Algorithm.
237-
// The rest is copied from the RRset. Sign returns true when the signing went OK,
238-
// otherwise false.
239-
// There is no check if RRSet is a proper (RFC 2181) RRSet.
240-
// If OrigTTL is non zero, it is used as-is, otherwise the TTL of the RRset
241-
// is used as the OrigTTL.
242-
func (rr *RRSIG) Sign(k crypto.Signer, rrset []RR) error {
243-
if k == nil {
244-
return ErrPrivKey
245-
}
246-
// s.Inception and s.Expiration may be 0 (rollover etc.), the rest must be set
247-
if rr.KeyTag == 0 || len(rr.SignerName) == 0 || rr.Algorithm == 0 {
248-
return ErrKey
249-
}
250-
251-
rr.Hdr.Rrtype = TypeRRSIG
252-
rr.Hdr.Name = rrset[0].Header().Name
253-
rr.Hdr.Class = rrset[0].Header().Class
254-
if rr.OrigTtl == 0 { // If set don't override
255-
rr.OrigTtl = rrset[0].Header().Ttl
256-
}
257-
rr.TypeCovered = rrset[0].Header().Rrtype
258-
rr.Labels = uint8(CountLabel(rrset[0].Header().Name))
259-
260-
if strings.HasPrefix(rrset[0].Header().Name, "*") {
261-
rr.Labels-- // wildcard, remove from label count
262-
}
263-
264-
sigwire := new(rrsigWireFmt)
265-
sigwire.TypeCovered = rr.TypeCovered
266-
sigwire.Algorithm = rr.Algorithm
267-
sigwire.Labels = rr.Labels
268-
sigwire.OrigTtl = rr.OrigTtl
269-
sigwire.Expiration = rr.Expiration
270-
sigwire.Inception = rr.Inception
271-
sigwire.KeyTag = rr.KeyTag
272-
// For signing, lowercase this name
273-
sigwire.SignerName = strings.ToLower(rr.SignerName)
274-
275-
// Create the desired binary blob
276-
signdata := make([]byte, DefaultMsgSize)
277-
n, err := PackStruct(sigwire, signdata, 0)
278-
if err != nil {
279-
return err
280-
}
281-
signdata = signdata[:n]
282-
wire, err := rawSignatureData(rrset, rr)
283-
if err != nil {
284-
return err
285-
}
286-
signdata = append(signdata, wire...)
287-
288-
hash, ok := AlgorithmToHash[rr.Algorithm]
289-
if !ok {
290-
return ErrAlg
291-
}
292-
293-
h := hash.New()
294-
h.Write(signdata)
295-
296-
signature, err := sign(k, h.Sum(nil), hash, rr.Algorithm)
297-
if err != nil {
298-
return err
299-
}
300-
301-
rr.Signature = toBase64(signature)
302-
303-
return nil
304-
}
305-
306-
func sign(k crypto.Signer, hashed []byte, hash crypto.Hash, alg uint8) ([]byte, error) {
307-
signature, err := k.Sign(rand.Reader, hashed, hash)
308-
if err != nil {
309-
return nil, err
310-
}
311-
312-
switch alg {
313-
case RSASHA1, RSASHA1NSEC3SHA1, RSASHA256, RSASHA512:
314-
return signature, nil
315-
316-
case ECDSAP256SHA256, ECDSAP384SHA384:
317-
ecdsaSignature := &struct {
318-
R, S *big.Int
319-
}{}
320-
if _, err := asn1.Unmarshal(signature, ecdsaSignature); err != nil {
321-
return nil, err
322-
}
323-
324-
var intlen int
325-
switch alg {
326-
case ECDSAP256SHA256:
327-
intlen = 32
328-
case ECDSAP384SHA384:
329-
intlen = 48
330-
}
331-
332-
signature := intToBytes(ecdsaSignature.R, intlen)
333-
signature = append(signature, intToBytes(ecdsaSignature.S, intlen)...)
334-
return signature, nil
335-
336-
// There is no defined interface for what a DSA backed crypto.Signer returns
337-
case DSA, DSANSEC3SHA1:
338-
// t := divRoundUp(divRoundUp(p.PublicKey.Y.BitLen(), 8)-64, 8)
339-
// signature := []byte{byte(t)}
340-
// signature = append(signature, intToBytes(r1, 20)...)
341-
// signature = append(signature, intToBytes(s1, 20)...)
342-
// rr.Signature = signature
343-
}
344-
345-
return nil, ErrAlg
346-
}
347-
348233
// Verify validates an RRSet with the signature and key. This is only the
349234
// cryptographic test, the signature validity period must be checked separately.
350235
// This function copies the rdata of some RRs (to lowercase domain names) for the validation to work.

dnssec_keygen.go

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)