@@ -29,21 +29,19 @@ var identdRpc *identd.RpcClient
2929var Server net.Listener
3030
3131type 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"`
3739}
3840
39- func MakeClient (conn net.Conn , webircCert * tls. Certificate ) * Client {
40- client := & Client {
41+ func MakeClient (conn net.Conn ) * Client {
42+ return & Client {
4143 Client : conn ,
4244 }
43- if webircCert != nil {
44- client .WebircCertificate = []tls.Certificate {* webircCert }
45- }
46- return client
4745}
4846
4947type Client struct {
@@ -93,6 +91,13 @@ func (c *Client) Handshake() error {
9391 return unmarshalErr
9492 }
9593
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+
96101 if meta .Host == "" || meta .Port == 0 || meta .Username == "" || meta .Interface == "" {
97102 c .Client .Write ([]byte (ResponseError ))
98103 return fmt .Errorf ("missing args" )
@@ -148,7 +153,10 @@ func (c *Client) ConnectUpstream() error {
148153 }
149154
150155 if c .TLS {
151- tlsConfig := & tls.Config {InsecureSkipVerify : true }
156+ tlsConfig := & tls.Config {
157+ InsecureSkipVerify : true ,
158+ Certificates : c .WebircCertificate ,
159+ }
152160 tlsConn := tls .Client (conn , tlsConfig )
153161 err := tlsConn .Handshake ()
154162 if err != nil {
@@ -190,7 +198,7 @@ func (c *Client) Pipe() {
190198 }
191199}
192200
193- func Start (laddr string , webircCert * tls. Certificate ) {
201+ func Start (laddr string ) {
194202 srv , err := net .Listen ("tcp" , laddr )
195203 if err != nil {
196204 log .Fatal (err .Error ())
@@ -210,7 +218,7 @@ func Start(laddr string, webircCert *tls.Certificate) {
210218 break
211219 }
212220
213- c := MakeClient (conn , webircCert )
221+ c := MakeClient (conn )
214222 go c .Run ()
215223 }
216224}
0 commit comments