Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "log" "github.com/shuque/dane" ) func main() { var daneconfig *dane.Config servers := []*dane.Server{dane.NewServer("", "8.8.8.8", 53)} resolver := dane.NewResolver(servers) hostname := "www.example.com" tlsa, err := dane.GetTLSA(resolver, hostname, 443) if err != nil { log.Fatalf("%s", err) } if tlsa == nil { log.Fatalf("No TLSA records found, where expected.") } iplist, err := dane.GetAddresses(resolver, hostname, true) if err != nil { log.Fatalf("%s", err) } if len(iplist) < 1 { log.Fatalf("Got less than expected addresses.") } for _, ip := range iplist { daneconfig = dane.NewConfig(hostname, ip, 443) daneconfig.SetTLSA(tlsa) conn, err := dane.DialTLS(daneconfig) if daneconfig.TLSA != nil { daneconfig.TLSA.Results() } if err != nil { fmt.Printf("Result: FAILED: %s\n", err.Error()) continue } conn.Close() if daneconfig.Okdane { fmt.Printf("Result: DANE OK\n") } else if daneconfig.Okpkix { fmt.Printf("Result: PKIX OK\n") } else { fmt.Printf("Result: FAILED\n") } } }
Output:
Index ¶
- Constants
- Variables
- func AuthenticateAll(daneconfig *Config)
- func AuthenticateSingle(chain []*x509.Certificate, tr *TLSArdata, daneconfig *Config) bool
- func CertToPEMBytes(cert *x509.Certificate) []byte
- func ChainMatchesTLSA(chain []*x509.Certificate, tr *TLSArdata, daneconfig *Config) bool
- func ComputeTLSA(selector, mtype uint8, cert *x509.Certificate) (string, error)
- func DialStartTLS(daneconfig *Config) (*tls.Conn, error)
- func DialTLS(daneconfig *Config) (*tls.Conn, error)
- func DoIMAP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error)
- func DoPOP3(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error)
- func DoSMTP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error)
- func DoXMPP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error)
- func GetAddresses(resolver *Resolver, hostname string, secure bool) ([]net.IP, error)
- func GetHttpClient(pkixfallback bool) http.Client
- func GetTLSconfig(daneconfig *Config) *tls.Config
- func StartTLS(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error)
- func TLShandshake(conn net.Conn, config *tls.Config) (*tls.Conn, error)
- type Config
- func ConnectByName(hostname string, port int) (*tls.Conn, *Config, error)
- func ConnectByNameAsync(hostname string, port int) (*tls.Conn, *Config, error)
- func ConnectByNameAsync2(hostname string, port int, pkixfallback bool) (*tls.Conn, *Config, error)
- func ConnectByNameAsyncBase(hostname string, port int, pkixfallback bool) (*tls.Conn, *Config, error)
- func NewConfig(hostname string, ip interface{}, port int) *Config
- func (c *Config) NoPKIXfallback()
- func (c *Config) SetALPN(alpnStrings []string)
- func (c *Config) SetAppName(appname string)
- func (c *Config) SetDiagMode(value bool)
- func (c *Config) SetServer(server *Server)
- func (c *Config) SetServiceName(servicename string)
- func (c *Config) SetTLSA(tlsa *TLSAinfo)
- type Query
- type Resolver
- type Response
- type Server
- type TLSAinfo
- type TLSArdata
- type VersionStruct
Examples ¶
Constants ¶
const ( PkixTA = 0 // Certificate Authority Constraint PkixEE = 1 // Service Certificate Constraint DaneTA = 2 // Trust Anchor Assertion DaneEE = 3 // Domain Issued Certificate )
DANE Certificte Usage modes
Variables ¶
var IPv6Headstart = 25 * time.Millisecond
IPv6 connect headstart (delay IPv4 connections by this amount)
var MaxParallelConnections = 30
Maximum number of parallel connections attempted
var Version = VersionStruct{0, 2, 3}
Version - current version number
Functions ¶
func AuthenticateAll ¶
func AuthenticateAll(daneconfig *Config)
AuthenticateAll performs DANE authentication of a set of certificate chains. The TLSA RRset information is expected to be pre-initialized in the dane Config structure.
func AuthenticateSingle ¶
func AuthenticateSingle(chain []*x509.Certificate, tr *TLSArdata, daneconfig *Config) bool
AuthenticateSingle performs DANE authentication of a single certificate chain, using a single TLSA resource data. Returns true or false accordingly.
func CertToPEMBytes ¶ added in v0.2.0
func CertToPEMBytes(cert *x509.Certificate) []byte
CertToPEMBytes returns PEM encoded bytes corresponding to the given x.509 certificate.
func ChainMatchesTLSA ¶
func ChainMatchesTLSA(chain []*x509.Certificate, tr *TLSArdata, daneconfig *Config) bool
ChainMatchesTLSA checks that the TLSA record data (tr) has a corresponding match in the certificate chain (chain). Only one TLSA record needs to match for the chain to be considered matched. However, this function checks all available TLSA records and records the results of the match in the TLSArdata structure. These results can be useful to diagnostic tools using this package.
func ComputeTLSA ¶
func ComputeTLSA(selector, mtype uint8, cert *x509.Certificate) (string, error)
ComputeTLSA calculates the TLSA rdata hash value for the given certificate from the given DANE selector and matching type. Returns the hex encoded string form of the value, and sets error to non-nil on failure.
func DialStartTLS ¶
DialStartTLS takes a pointer to an initialized dane Config structure, connects to the defined server, speaks the necessary application protocol preamble to activate STARTTLS, then negotiates TLS and returns the TLS connection. The error return parameter is nil on success, and appropriately populated if not.
DialStartTLS obtains a TLS config structure, initialized with Dane verification callbacks, and connects to the server network address defined in Config using tls.DialWithDialer().
func DialTLS ¶
DialTLS takes a pointer to an initialized dane Config structure, establishes and returns a TLS connection. The error return parameter is nil on success, and appropriately populated if not.
DialTLS obtains a TLS config structure initialized with Dane verification callbacks, and connects to the server network address defined in Config using tls.DialWithDialer().
func DoIMAP ¶
DoIMAP connects to an IMAP server, issues a STARTTLS command, negotiates TLS, and returns a TLS connection.
func DoPOP3 ¶
DoPOP3 connects to a POP3 server, sends the STLS command, negotiates TLS, and returns a TLS connection.
func DoSMTP ¶
DoSMTP connects to an SMTP server, checks for STARTTLS support, negotiates TLS, and returns a TLS connection.
func DoXMPP ¶
DoXMPP connects to an XNPP server, issue a STARTTLS command, negotiates TLS and returns a TLS connection. See RFC 6120, Section 5.4.2 for details.
func GetAddresses ¶
GetAddresses obtains a list of IPv4 and IPv6 addresses for given hostname.
func GetHttpClient ¶ added in v0.1.12
GetHttpClient returns a net/http Client structure configured to perform DANE TLS authentication of the HTTPS server. If the argument pkixfallback is set to true, then PKIX authentication will be attempted if the server does not have any published secure DANE TLSA records.
func GetTLSconfig ¶
GetTLSconfig takes a dane Config structure, and returns a tls Config initialized with the ServerName, other specified TLS parameters, and a custom server certificate verification callback that performs DANE authentication.
Types ¶
type Config ¶
type Config struct { DiagMode bool // Diagnostic mode DiagError error // Holds possible error in Diagnostic mode Server *Server // Server structure (name, ip, port) TimeoutTCP int // TCP timeout in seconds NoVerify bool // Don't verify server certificate TLSversion uint16 // TLS version number (otherwise use best TLS version offered) PKIXRootCA []byte // Use PEM bytes as Root CA store for PKIX authentication ALPN []string // ALPN strings to send DaneEEname bool // Do name checks even for DANE-EE mode SMTPAnyMode bool // Allow any DANE modes for SMTP Appname string // STARTTLS application name Servicename string // Servicename, if different from server Transcript string // StartTLS transcript DANE bool // do DANE authentication PKIX bool // fall back to PKIX authentication Okdane bool // DANE authentication result Okpkix bool // PKIX authentication result TLSA *TLSAinfo // TLSA RRset information PeerChain []*x509.Certificate // Peer Certificate Chain PKIXChains [][]*x509.Certificate // PKIX Certificate Chains DANEChains [][]*x509.Certificate // DANE Certificate Chains }
Config contains a DANE configuration for a single Server.
func ConnectByName ¶ added in v0.1.2
ConnectByName takes a hostname and port, resolves the addresses for the hostname (IPv6 followed by IPv4), and then attempts to connect to them and establish TLS using DANE or PKIX authentication - DANE is attempted if there are secure TLSA records, otherwise it falls back to PKIX authentication. It returns a TLS connection and dane config for the first address that succeeds.
Uses a default DANE configuration. For a custom DANE configuration, use the DialTLS or DialStartTLS functions instead.
func ConnectByNameAsync ¶ added in v0.1.11
ConnectByNameAsync is an async version of ConnectByName that tries to connect to all server addresses in parallel, and returns the first successful connection. IPv4 connections are intentionally delayed by an IPv6HeadStart amount of time. Performs DANE authentication with fallback to PKIX if no secure TLSA records are found.
func ConnectByNameAsync2 ¶ added in v0.1.12
ConnectByNameAsync2 is the same as ConnectByNameAsync, but supports an additional argument to specify whether PKIX fallback should be performed. By setting that argument to false, we can require DANE only authentication.
func ConnectByNameAsyncBase ¶ added in v0.1.12
func ConnectByNameAsyncBase(hostname string, port int, pkixfallback bool) (*tls.Conn, *Config, error)
ConnectByNameAsyncBase. Should not be called directly. Instead call either ConnectByNameAsync or ConnectByNameAsync2
func NewConfig ¶
NewConfig initializes and returns a new dane Config structure for the given server name, ip address and port. The IP address can be specified either as a string or a net.IP structure. The initialized config does DANE authentication with fallback to PKIX.
func (*Config) NoPKIXfallback ¶
func (c *Config) NoPKIXfallback()
NoPKIXfallback sets Config to not allow PKIX fallback. Only DANE authentication is permitted.
func (*Config) SetAppName ¶
SetAppName sets the STARTTLS application name.
func (*Config) SetDiagMode ¶ added in v0.1.9
SetDiagMode sets the Diagnostic mode.
func (*Config) SetServiceName ¶
SetServiceName sets the STARTTLS service name.
type Resolver ¶
type Resolver struct { Servers []*Server // list of resolvers Rdflag bool // set RD flag Adflag bool // set AD flag Cdflag bool // set CD flag Timeout time.Duration // query timeout Retries int // query retries Payload uint16 // EDNS0 UDP payload size IPv6 bool // lookup AAAA records in getAddresses() IPv4 bool // look A records in getAddresses() Pkixfallback bool // whether to fallback to PKIX in getTLSA() }
Resolver contains a DNS resolver configuration
func GetResolver ¶
GetResolver returns a Resolver configuration structure containing a list of DNS resolver addresses obtained from a custom resolver configuration file or from the system default (/etc/resolv.conf) if the config file is unspecified.
func NewResolver ¶
NewResolver initializes a new Resolver structure from a given IP address (net.IP) and port number.
type Response ¶ added in v0.1.11
type Response struct {
// contains filtered or unexported fields
}
Response - response information
type Server ¶
Server contains information about a single server: hostname, IP address (net.IP) and port number.
func NewServer ¶
NewServer returns an initialized Server structure from given name, IP address, and port.
type TLSAinfo ¶
TLSAinfo contains details of the TLSA RRset.
func GetTLSA ¶
GetTLSA returns the DNS TLSA RRset information for the given hostname, port and resolver parameters.
func Message2TSLAinfo ¶ added in v0.1.4
Message2TSLAinfo returns a populated TLSAinfo structure from the contents of a given dns message that contains a response to a TLSA query. The qname parameter provides the expected TLSA query name string.
func (*TLSAinfo) Print ¶
func (t *TLSAinfo) Print()
Print prints information about the TLSAinfo TLSA RRset.
func (*TLSAinfo) Results ¶
func (t *TLSAinfo) Results()
Results prints TLSA RRset certificate matching results.
func (*TLSAinfo) ResultsString ¶ added in v0.2.3
ResultsString is like Results but returns a string.
type TLSArdata ¶
type TLSArdata struct { Usage uint8 // Certificate Usage Selector uint8 // Selector: 0: full cert, 1: subject public key Mtype uint8 // Matching Type: 0: full content, 1: SHA256, 2: SHA512 Data string // Certificate association Data field (hex encoding) Checked bool // Have we tried to match this TLSA rdata? Ok bool // Did it match? Message string // Diagnostic message for matching }
TLSArdata - TLSA rdata structure
type VersionStruct ¶
type VersionStruct struct {
Major, Minor, Patch int
}
VersionStruct - version structure
func (VersionStruct) String ¶
func (v VersionStruct) String() string
String representation of version