Skip to content

Commit

Permalink
config: display an error message and abort if user cert missing
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift committed Apr 17, 2019
1 parent 5bdfe7d commit 1af99f4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,24 @@ func init() {
ourCAPool := x509.NewCertPool()
chainFile, err := ioutil.ReadFile(viper.GetString("certs.cachain"))
if err != nil {
fmt.Println(err)
log.Fatal(err)
}
ok := ourCAPool.AppendCertsFromPEM(chainFile)
if !ok {
fmt.Println("Error when loading certificate chain file")
log.Fatal("Error when loading certificate chain file")
}

// TODO: Check if the client certificate file is present
certFile := viper.GetString("certs.cert")
if _, err = os.Stat(certFile); err != nil {
log.Fatalf("Please download your client certificate from DBHub.io, then update the configuration " +
"file '%s' with its path", cfgFile)
}

// Load a client certificate file
cert, err := tls.LoadX509KeyPair(viper.GetString("certs.cert"), viper.GetString("certs.cert"))
cert, err := tls.LoadX509KeyPair(certFile, certFile)
if err != nil {
fmt.Println(err)
log.Fatal(err)
}

// Load our self signed CA Cert chain, and set TLS1.2 as minimum
Expand All @@ -139,7 +146,7 @@ func init() {
var email string
certUser, email, _, err = getUserAndServer()
if err != nil {
fmt.Println(err)
log.Fatal(err)
}
viper.Set("user.email", email)
}

0 comments on commit 1af99f4

Please sign in to comment.