-
Notifications
You must be signed in to change notification settings - Fork 3
/
tls.go
49 lines (40 loc) · 879 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
38
39
40
41
42
43
44
45
46
47
48
49
package security
import (
"crypto/tls"
)
// NewTLSConfig for security.
//
//nolint:nilnil
func NewTLSConfig(sec *Config) (*tls.Config, error) {
if sec == nil {
return nil, nil
}
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.
//
//nolint:nilnil
func NewClientTLSConfig(sec *Config) (*tls.Config, error) {
if sec == nil {
return nil, nil
}
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
}