| 1 | package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ |
| 2 | |
| 3 | import ( |
| 4 | "crypto/sha256scip-go gomod github.com/golang/go/src go1.25.0 `crypto/sha256`/" |
| 5 | "crypto/x509scip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/" |
| 6 | "encoding/hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/" |
| 7 | ) |
| 8 | |
| 9 | // Sign creates a SMIMEA record from an SSL certificate. |
| 10 | func (r *SMIMEAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#) Signscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Sign().(usage, selector, matchingType int, cert *x509scip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/Certificate#) (err error) { |
| 11 | r.Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Hdr..Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype. = TypeSMIMEAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeSMIMEA. |
| 12 | r.Usagescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Usage. = uint8(usage) |
| 13 | r.Selectorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Selector. = uint8(selector) |
| 14 | r.MatchingTypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#MatchingType. = uint8(matchingType) |
| 15 | |
| 16 | r.Certificatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Certificate., err = CertificateToDANEscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CertificateToDANE().(r.Selectorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Selector., r.MatchingTypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#MatchingType., cert) |
| 17 | return err |
| 18 | } |
| 19 | |
| 20 | // Verify verifies a SMIMEA record against an SSL certificate. If it is OK |
| 21 | // a nil error is returned. |
| 22 | func (r *SMIMEAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#) Verifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Verify().(cert *x509scip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/Certificate#) error { |
| 23 | c, err := CertificateToDANEscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CertificateToDANE().(r.Selectorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Selector., r.MatchingTypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#MatchingType., cert) |
| 24 | if err != nil { |
| 25 | return err // Not also ErrSig? |
| 26 | } |
| 27 | if r.Certificatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEA#Certificate. == c { |
| 28 | return nil |
| 29 | } |
| 30 | return ErrSigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ErrSig. // ErrSig, really? |
| 31 | } |
| 32 | |
| 33 | // SMIMEAName returns the ownername of a SMIMEA resource record as per the |
| 34 | // format specified in RFC 'draft-ietf-dane-smime-12' Section 2 and 3 |
| 35 | func SMIMEANamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SMIMEAName().(email, domain string) (string, error) { |
| 36 | hasher := sha256scip-go gomod github.com/golang/go/src go1.25.0 `crypto/sha256`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `crypto/sha256`/New().() |
| 37 | hasher.Writescip-go gomod github.com/golang/go/src go1.25.0 io/Writer#Write().([]byte(email)) |
| 38 | |
| 39 | // RFC Section 3: "The local-part is hashed using the SHA2-256 |
| 40 | // algorithm with the hash truncated to 28 octets and |
| 41 | // represented in its hexadecimal representation to become the |
| 42 | // left-most label in the prepared domain name" |
| 43 | return hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/.EncodeToStringscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/EncodeToString().(hasher.Sumscip-go gomod github.com/golang/go/src go1.25.0 hash/Hash#Sum().(nil)[:28]) + "." + "_smimecert." + domain, nil |
| 44 | } |