Add initial support for choosing to still connect when the server uses a self-signed cert and verify_vertificates is turned on

This commit is contained in:
Ken-Håvard Lieng 2017-07-04 11:28:56 +02:00
parent 3f70567d56
commit c005fc7cae
7 changed files with 81 additions and 22 deletions

View file

@ -1,6 +1,7 @@
package server
import (
"crypto/x509"
"encoding/json"
"github.com/khlieng/dispatch/irc"
@ -27,10 +28,16 @@ type ServerName struct {
Name string `json:"name"`
}
type ReconnectSettings struct {
Server string `json:"server"`
SkipVerify bool `json:"skipVerify"`
}
type ConnectionUpdate struct {
Server string `json:"server"`
Connected bool `json:"connected"`
Error string `json:"error,omitempty"`
ErrorType string `json:"errorType,omitempty"`
}
func newConnectionUpdate(server string, state irc.ConnectionState) ConnectionUpdate {
@ -40,6 +47,9 @@ func newConnectionUpdate(server string, state irc.ConnectionState) ConnectionUpd
}
if state.Error != nil {
status.Error = state.Error.Error()
if _, ok := state.Error.(x509.UnknownAuthorityError); ok {
status.ErrorType = "verify"
}
}
return status
}

View file

@ -95,6 +95,18 @@ func (h *wsHandler) connect(b []byte) {
}
}
func (h *wsHandler) reconnect(b []byte) {
var data ReconnectSettings
json.Unmarshal(b, &data)
if i, ok := h.session.getIRC(data.Server); ok && !i.Connected() {
if i.TLS {
i.TLSConfig.InsecureSkipVerify = data.SkipVerify
}
i.Reconnect()
}
}
func (h *wsHandler) join(b []byte) {
var data Join
json.Unmarshal(b, &data)
@ -252,6 +264,7 @@ func (h *wsHandler) setServerName(b []byte) {
func (h *wsHandler) initHandlers() {
h.handlers = map[string]func([]byte){
"connect": h.connect,
"reconnect": h.reconnect,
"join": h.join,
"part": h.part,
"quit": h.quit,