@@ -29,21 +29,19 @@ var identdRpc *identd.RpcClient
29
29
var Server net.Listener
30
30
31
31
type HandshakeMeta struct {
32
- Host string `json:"host"`
33
- Port int `json:"port"`
34
- TLS bool `json:"ssl"`
35
- Username string `json:"username"`
36
- Interface string `json:"interface"`
32
+ Host string `json:"host"`
33
+ Port int `json:"port"`
34
+ TLS bool `json:"ssl"`
35
+ Username string `json:"username"`
36
+ Interface string `json:"interface"`
37
+ WebircPemCert []byte `json:"webirc_cert"`
38
+ WebircPemKey []byte `json:"webirc_key"`
37
39
}
38
40
39
- func MakeClient (conn net.Conn , webircCert * tls. Certificate ) * Client {
40
- client := & Client {
41
+ func MakeClient (conn net.Conn ) * Client {
42
+ return & Client {
41
43
Client : conn ,
42
44
}
43
- if webircCert != nil {
44
- client .WebircCertificate = []tls.Certificate {* webircCert }
45
- }
46
- return client
47
45
}
48
46
49
47
type Client struct {
@@ -93,6 +91,13 @@ func (c *Client) Handshake() error {
93
91
return unmarshalErr
94
92
}
95
93
94
+ if len (meta .WebircPemCert ) > 0 && len (meta .WebircPemKey ) > 0 {
95
+ webircCert , err := tls .X509KeyPair (meta .WebircPemCert , meta .WebircPemKey )
96
+ if err == nil {
97
+ c .WebircCertificate = []tls.Certificate {webircCert }
98
+ }
99
+ }
100
+
96
101
if meta .Host == "" || meta .Port == 0 || meta .Username == "" || meta .Interface == "" {
97
102
c .Client .Write ([]byte (ResponseError ))
98
103
return fmt .Errorf ("missing args" )
@@ -148,7 +153,10 @@ func (c *Client) ConnectUpstream() error {
148
153
}
149
154
150
155
if c .TLS {
151
- tlsConfig := & tls.Config {InsecureSkipVerify : true }
156
+ tlsConfig := & tls.Config {
157
+ InsecureSkipVerify : true ,
158
+ Certificates : c .WebircCertificate ,
159
+ }
152
160
tlsConn := tls .Client (conn , tlsConfig )
153
161
err := tlsConn .Handshake ()
154
162
if err != nil {
@@ -190,7 +198,7 @@ func (c *Client) Pipe() {
190
198
}
191
199
}
192
200
193
- func Start (laddr string , webircCert * tls. Certificate ) {
201
+ func Start (laddr string ) {
194
202
srv , err := net .Listen ("tcp" , laddr )
195
203
if err != nil {
196
204
log .Fatal (err .Error ())
@@ -210,7 +218,7 @@ func Start(laddr string, webircCert *tls.Certificate) {
210
218
break
211
219
}
212
220
213
- c := MakeClient (conn , webircCert )
221
+ c := MakeClient (conn )
214
222
go c .Run ()
215
223
}
216
224
}
0 commit comments