-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtls.go
187 lines (168 loc) · 8.23 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package utils
import (
"crypto/tls"
"crypto/x509"
"errors"
"log"
"google.golang.org/grpc/credentials"
)
// WARNING: DO NOT USE THESE KEYS IN PRODUCTION!
var ServerPublicKeys = [...]string{
`-----BEGIN CERTIFICATE-----
MIIDXjCCAcagAwIBAgIQaQ6ZT/eUnVj3yI0zDmu1zDANBgkqhkiG9w0BAQsFADBl
MR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExHTAbBgNVBAsMFHNtc2Nv
bG9tQGRlZGlzMjAwMjA0MSQwIgYDVQQDDBtta2NlcnQgc21zY29sb21AZGVkaXMy
MDAyMDQwHhcNMjQxMDEyMTAzMTE0WhcNMjcwMTEyMTEzMTE0WjBEMScwJQYDVQQK
Ex5ta2NlcnQgZGV2ZWxvcG1lbnQgY2VydGlmaWNhdGUxGTAXBgNVBAsMEHNtc2Nv
bG9tQGRlZGlzcGMwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARFOsBHZVaVxg3l
pIxFyzdB8wt+xDB1GOlBYG4ODWvDLWiYfcgcBCQeuhgA2CVGBYqBj7vabgIRMQuA
OPMnlKdoo3YwdDAOBg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sMbGCsIPbYuDP0a7pwlKCfvv894nTblbXpAYmnjgTK39
Sy70Ugfx/DG/8enWYX17kDrqL38zpXZk/qul1nJn96P0Hue5xe00Qquw7rHeFsuT
9neYS36PYuCcf0yx4ADe2wNu4XirB0pwf+VpvRL7bbi/err31JAY6kUu90L2liWR
KQPTGlp0i+G5sEwqPbjT0FTmXDNEYZx4fykmiBEDe27Tyjsx3LSXXgJjk5gSx0kE
pPY=
-----END CERTIFICATE-----`,
}
var serverSecretKeys = [...]string{
`-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgNoDZwvdS/ScB/Z7m
sdCAXt2u4L9prHBXNiNCa10IYLmhRANCAARFOsBHZVaVxg3lpIxFyzdB8wt+xDB1
GOlBYG4ODWvDLWiYfcgcBCQeuhgA2CVGBYqBj7vabgIRMQuAOPMnlKdo
-----END PRIVATE KEY-----`,
`-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgIgGbBHOEdUqLDkc5
8mJ5PQcgB872WDdRWtQKm4cB7JihRANCAAS/BAvhfdzmnjBeWPaY9DUuDx6H8pnl
io3csl/HJvzeN0xMoUr2GrpH3i72v/t6xkIf4G05aFhYtQWTdE+DKSNE
-----END PRIVATE KEY-----`,
`-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgWBwLH3AqXx5Znx4/
0FteACwe5tjn80izrSVCcHumfY+hRANCAASwhEFeGjTueg3+e7xf2ZSA0EuGEBFU
CKjIeJ+QugKtAr/ovwokwQqSZLIturCvEIaqAPWVQNY7xFzrxR3gK2v1
-----END PRIVATE KEY-----`,
`-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgsNPka1QqZoiyELQl
LAz4+WNHHRsDYssTR9yT19XdyeOhRANCAASCjnCXs0D3Gw3+iRHeU5b/RwlzIPiD
dR3yDtziPzNMY8tZBE3fRxFiPtHycIO6Yh4OBqJKfUgzackl00WPCFrq
-----END PRIVATE KEY-----`,
`-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgcHIFHgufO4VJc8ZZ
Jh6VTiwmJE7cfF2K0d5MIsOS8GehRANCAAQZOF+0AyiK7k10TCE9WrCG43M53fUk
IS25uWzOhvWxGgedLoArZwXplBdYYpB3Bla7HOOqcq30iYk2BO1GVzjH
-----END PRIVATE KEY-----`,
}
// ServerCertificates holds the certificates for the servers
var ServerCertificates []tls.Certificate
func init() {
numServers := 5
ServerCertificates = make([]tls.Certificate, numServers)
var err error
for i := range ServerCertificates {
ServerCertificates[i], err = tls.X509KeyPair(
[]byte(ServerPublicKeys[i]),
[]byte(serverSecretKeys[i]))
if err != nil {
log.Fatalf("could not load certficate #%v %v", i, err)
}
}
}
func LoadServersCertificates() (credentials.TransportCredentials, error) {
cp := x509.NewCertPool()
for _, cert := range ServerPublicKeys {
if !cp.AppendCertsFromPEM([]byte(cert)) {
return nil, errors.New("credentials: failed to append certificates")
}
}
creds := credentials.NewClientTLSFromCert(cp, "127.0.0.1")
return creds, nil
}