-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
47 lines (40 loc) · 932 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package config
import (
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"github.com/marcboeker/dns/plugin"
)
type Config struct {
Plugins []plugin.Plugin
DNSOverHTTP *DNSOverHTTP
DNSOverTLS *DNSOverTLS
ListenUDP bool
ListenTCP bool
TLSConfig *tls.Config
}
type DNSOverHTTP struct {
Hostname string
Path string
}
type DNSOverTLS struct {
Hostname string
}
// Use `dev` as the current config environment.
var Get = dev
// newTLSConfig loads certs and returns a TLS config.
func newTLSConfig(caCert, cert, key []byte) (*tls.Config, error) {
caCertPool := x509.NewCertPool()
if ok := caCertPool.AppendCertsFromPEM(caCert); !ok {
return nil, errors.New("could not read CA cert")
}
c, err := tls.X509KeyPair(cert, key)
if err != nil {
return nil, fmt.Errorf("could not read cert key pair: %s", err)
}
return &tls.Config{
Certificates: []tls.Certificate{c},
ClientCAs: caCertPool,
}, nil
}