-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcommon.go
64 lines (50 loc) · 1.4 KB
/
common.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package common
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"os"
)
func MustLoadCertificates() (tls.Certificate, *x509.CertPool) {
l := len(os.Args)
privateKeyFile := os.Args[l-3]
certificateFile := os.Args[l-2]
caFile := os.Args[l-1]
mycert, err := tls.LoadX509KeyPair(certificateFile, privateKeyFile)
if err != nil {
panic(err)
}
pem, err := ioutil.ReadFile(caFile)
if err != nil {
panic(err)
}
certPool := x509.NewCertPool()
if !certPool.AppendCertsFromPEM(pem) {
panic("Failed appending certs")
}
return mycert, certPool
}
func MustGetTlsConfiguration() *tls.Config {
config := &tls.Config{}
mycert, certPool := MustLoadCertificates()
config.Certificates = make([]tls.Certificate, 1)
config.Certificates[0] = mycert
config.RootCAs = certPool
config.ClientCAs = certPool
config.ClientAuth = tls.RequireAndVerifyClientCert
//Optional stuff
//Use only modern ciphers
config.CipherSuites = []uint16{tls.TLS_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}
//Use only TLS v1.2
config.MinVersion = tls.VersionTLS12
//Don't allow session resumption
config.SessionTicketsDisabled = true
return config
}