-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.go
196 lines (186 loc) · 8.05 KB
/
main.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
188
189
190
191
192
193
194
195
196
package main
import (
"crypto/tls"
"gitee.com/Trisia/gotlcp/pa"
"gitee.com/Trisia/gotlcp/tlcp"
"io"
"net"
)
var (
sigCert tlcp.Certificate
encCert tlcp.Certificate
rsaCert tls.Certificate
)
func main() {
var err error
tlcpCfg := &tlcp.Config{
Certificates: []tlcp.Certificate{sigCert, encCert},
}
tlsCfg := &tls.Config{
Certificates: []tls.Certificate{rsaCert},
}
listen, err := pa.Listen("tcp", ":9443", tlcpCfg, tlsCfg)
if err != nil {
panic(err)
}
defer listen.Close()
for {
conn, err := listen.Accept()
if err != nil {
panic(err)
}
go echo(conn)
}
}
func echo(conn net.Conn) {
defer conn.Close()
_, _ = io.Copy(conn, conn)
}
func init() {
var err error
sigCert, err = tlcp.X509KeyPair([]byte(SIG_CERT_PEM), []byte(SIG_KEY_PEM))
if err != nil {
panic(err)
}
encCert, err = tlcp.X509KeyPair([]byte(ENC_CERT_PEM), []byte(ENC_KEY_PEM))
if err != nil {
panic(err)
}
rsaCert, err = tls.X509KeyPair([]byte(RSA_CERT_PEM), []byte(RSA_KEY_PEM))
if err != nil {
panic(err)
}
}
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ZY8wqQwDwYDVR0RBAgwBocEfwAAATAKBggqgRzPVQGDdQNIADBFAiAD
29ovbTAIhZgfvAYKXphZSvcMnQ3QdCDyCqb4j8KMQwIhAINoMaInvyMB86C/aa7P
gqBZDVjZd/X+yWxzRGtLG/AT
-----END CERTIFICATE-----
`
SIG_KEY_PEM = `-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgC1Sw2Ptopr75mxS/
R+lT45og/55WuueomJKSXqTmAfKgCgYIKoEcz1UBgi2hRANCAASVy6EufNqqMxsI
YECDpBlMDqIwKxyT3STCHg0rSuj5djRfDNhoPk9CrtV6Fy5wca+tQvZUrZ36/XqL
UnZoP43l
-----END PRIVATE KEY-----
`
ENC_KEY_PEM = `-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgpcgOKHIjr+jDTNjc
mfeSZuYZlwi344P7s7bz1ofThjigCgYIKoEcz1UBgi2hRANCAAR6IMq/LhqYYxJT
qVKaiFTBwjihEBUZJbqS0va/eaqmzwn0kMR8yySScRVaN+svs5P4RpibSs7u2/Hq
gmquZR3m
-----END PRIVATE KEY-----
`
RSA_CERT_PEM = `-----BEGIN CERTIFICATE-----
MIIDmzCCAoOgAwIBAgIIAs5k+q7pWb8wDQYJKoZIhvcNAQELBQAwQjELMAkGA1UE
BhMCQ04xDzANBgNVBAgMBua1meaxnzEPMA0GA1UEBwwG5p2t5beeMREwDwYDVQQK
DAjmtYvor5VDQTAeFw0yMjEwMDYwMzE3MzhaFw0yMzEwMDYwMzE3MzhaMGIxCzAJ
BgNVBAYTAmNuMQ8wDQYDVQQIDAbmtZnmsZ8xDzANBgNVBAcMBuadreW3njEPMA0G
A1UEChMGR29UTENQMQ8wDQYDVQQLEwZHb1RMQ1AxDzANBgNVBAMTBkdvVExDUDCC
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANKp8SDLQIM5OY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