-
Notifications
You must be signed in to change notification settings - Fork 3
/
tls.go
37 lines (30 loc) · 761 Bytes
/
tls.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
package security
import (
"crypto/tls"
)
// NewTLSConfig for security.
func NewTLSConfig(sec Config) (*tls.Config, error) {
cert, err := tls.LoadX509KeyPair(sec.CertFile, sec.KeyFile)
if err != nil {
return nil, err
}
conf := &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{cert},
ClientAuth: tls.RequireAndVerifyClientCert,
}
return conf, nil
}
// NewClientTLSConfig for security.
func NewClientTLSConfig(sec Config) (*tls.Config, error) {
cert, err := tls.LoadX509KeyPair(sec.CertFile, sec.KeyFile)
if err != nil {
return nil, err
}
conf := &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{cert},
ClientAuth: tls.RequireAndVerifyClientCert,
}
return conf, nil
}