From b23b10609055a5b65ead35426a5ccce3e6209774 Mon Sep 17 00:00:00 2001 From: geosoft1 Date: Thu, 24 Sep 2020 16:16:15 +0300 Subject: [PATCH 1/2] allow using self signed certificates --- api.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/api.go b/api.go index ef52078..a79a1f4 100644 --- a/api.go +++ b/api.go @@ -13,13 +13,21 @@ package gorqlite */ -import "bytes" -import "encoding/json" -import "errors" -import "fmt" -import "io/ioutil" -import "net/http" -import "time" +import ( + "bytes" + "crypto/tls" + "encoding/json" + "errors" + "fmt" + "io/ioutil" + "net/http" + "time" +) + +func init() { + // allow using self signed certificates + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} +} /* ***************************************************************** From eee3247a5347e1866ca774d320744aaf69e009f7 Mon Sep 17 00:00:00 2001 From: geosoft1 Date: Fri, 25 Sep 2020 20:26:25 +0300 Subject: [PATCH 2/2] - --- api.go | 6 ------ gorqlite.go | 21 ++++++++++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/api.go b/api.go index a79a1f4..bf4ccb0 100644 --- a/api.go +++ b/api.go @@ -15,7 +15,6 @@ package gorqlite import ( "bytes" - "crypto/tls" "encoding/json" "errors" "fmt" @@ -24,11 +23,6 @@ import ( "time" ) -func init() { - // allow using self signed certificates - http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} -} - /* ***************************************************************** method: rqliteApiGet() - for api_STATUS diff --git a/gorqlite.go b/gorqlite.go index 89aece3..b529793 100644 --- a/gorqlite.go +++ b/gorqlite.go @@ -19,11 +19,15 @@ package gorqlite Open, TraceOn(), TraceOff() */ -import "crypto/rand" -import "fmt" -import "io" -import "io/ioutil" -import "strings" +import ( + "crypto/rand" + "crypto/tls" + "fmt" + "io" + "io/ioutil" + "net/http" + "strings" +) /* ***************************************************************** @@ -51,6 +55,8 @@ const ( api_WRITE ) +var InsecureSkipVerify bool + /* ***************************************************************** init() @@ -112,6 +118,11 @@ func Open(connURL string) (Connection, error) { return conn, err } + if conn.wantsHTTPS { + // allow using self signed certificates + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: InsecureSkipVerify} + } + // call updateClusterInfo() to populate the cluster // also tests the user's default