~hduran-8/+junk/caddy

« back to all changes in this revision

Viewing changes to debian/gocode/src/github.com/miekg/dns/smimea.go

  • Committer: Horacio Durán
  • Date: 2017-01-20 16:21:20 UTC
  • Revision ID: horacio.duran@canonical.com-20170120162120-l82mfqwmsclnk838
Upgrade to 0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package dns
 
2
 
 
3
import (
 
4
        "crypto/sha256"
 
5
        "crypto/x509"
 
6
        "encoding/hex"
 
7
)
 
8
 
 
9
// Sign creates a SMIMEA record from an SSL certificate.
 
10
func (r *SMIMEA) Sign(usage, selector, matchingType int, cert *x509.Certificate) (err error) {
 
11
        r.Hdr.Rrtype = TypeSMIMEA
 
12
        r.Usage = uint8(usage)
 
13
        r.Selector = uint8(selector)
 
14
        r.MatchingType = uint8(matchingType)
 
15
 
 
16
        r.Certificate, err = CertificateToDANE(r.Selector, r.MatchingType, cert)
 
17
        if err != nil {
 
18
                return err
 
19
        }
 
20
        return nil
 
21
}
 
22
 
 
23
// Verify verifies a SMIMEA record against an SSL certificate. If it is OK
 
24
// a nil error is returned.
 
25
func (r *SMIMEA) Verify(cert *x509.Certificate) error {
 
26
        c, err := CertificateToDANE(r.Selector, r.MatchingType, cert)
 
27
        if err != nil {
 
28
                return err // Not also ErrSig?
 
29
        }
 
30
        if r.Certificate == c {
 
31
                return nil
 
32
        }
 
33
        return ErrSig // ErrSig, really?
 
34
}
 
35
 
 
36
// SIMEAName returns the ownername of a SMIMEA resource record as per the
 
37
// format specified in RFC 'draft-ietf-dane-smime-12' Section 2 and 3
 
38
func SMIMEAName(email_address string, domain_name string) (string, error) {
 
39
        hasher := sha256.New()
 
40
        hasher.Write([]byte(email_address))
 
41
 
 
42
        // RFC Section 3: "The local-part is hashed using the SHA2-256
 
43
        // algorithm with the hash truncated to 28 octets and
 
44
        // represented in its hexadecimal representation to become the
 
45
        // left-most label in the prepared domain name"
 
46
        return hex.EncodeToString(hasher.Sum(nil)[:28]) + "." + "_smimecert." + domain_name, nil
 
47
}