Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow using self signed certificates #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done, for example, as a method on the Connection object. It should not be done for everyone.

Then people who want this behaviour can call the method. Make sense?

Copy link
Author

@geosoft1 geosoft1 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, in fact the init function was more a quick fix than an elegant solution. Meanwhile, I put a logger on gorqlite and I identified that error come from Open function.

log.SetFlags(log.LstdFlags | log.Lshortfile)
func Open(connURL string) (Connection, error) {
...
	err = conn.updateClusterInfo()  // this line return that error

Open function create and return a Connection variable. So, setting InsecureSkipVerify should be done before that but conn variable is still private (perhaps to allow multiple connections from the same application). A global variable setted by Open function only for https connections works (like in the example bellow), but I can't figured out if can be set it with a method of Connection object, here maybe you have a better idea..

var InsecureSkipVerify bool

func Open(connURL string) (Connection, error) {
	...
	if conn.wantsHTTPS {
		// allow using self signed certificates only for https connections
		http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: InsecureSkipVerify}
	}
	...
	err = conn.updateClusterInfo()

// client application code
rq.InsecureSkipVerify = true
if db, err = rq.Open(node); err != nil {
	log.Fatal(err)
	return
}

}

/* *****************************************************************

Expand Down