You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tlsa.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package dns
  2. import (
  3. "crypto/x509"
  4. "net"
  5. "strconv"
  6. )
  7. // Sign creates a TLSA record from an SSL certificate.
  8. func (r *TLSA) Sign(usage, selector, matchingType int, cert *x509.Certificate) (err error) {
  9. r.Hdr.Rrtype = TypeTLSA
  10. r.Usage = uint8(usage)
  11. r.Selector = uint8(selector)
  12. r.MatchingType = uint8(matchingType)
  13. r.Certificate, err = CertificateToDANE(r.Selector, r.MatchingType, cert)
  14. return err
  15. }
  16. // Verify verifies a TLSA record against an SSL certificate. If it is OK
  17. // a nil error is returned.
  18. func (r *TLSA) Verify(cert *x509.Certificate) error {
  19. c, err := CertificateToDANE(r.Selector, r.MatchingType, cert)
  20. if err != nil {
  21. return err // Not also ErrSig?
  22. }
  23. if r.Certificate == c {
  24. return nil
  25. }
  26. return ErrSig // ErrSig, really?
  27. }
  28. // TLSAName returns the ownername of a TLSA resource record as per the
  29. // rules specified in RFC 6698, Section 3.
  30. func TLSAName(name, service, network string) (string, error) {
  31. if !IsFqdn(name) {
  32. return "", ErrFqdn
  33. }
  34. p, err := net.LookupPort(network, service)
  35. if err != nil {
  36. return "", err
  37. }
  38. return "_" + strconv.Itoa(p) + "._" + network + "." + name, nil
  39. }