summaryrefslogtreecommitdiffstats
path: root/sms-service/src/quorumclient/quorumclient.go
diff options
context:
space:
mode:
Diffstat (limited to 'sms-service/src/quorumclient/quorumclient.go')
-rw-r--r--sms-service/src/quorumclient/quorumclient.go46
1 files changed, 33 insertions, 13 deletions
diff --git a/sms-service/src/quorumclient/quorumclient.go b/sms-service/src/quorumclient/quorumclient.go
index 3f3c70b..e3e6e40 100644
--- a/sms-service/src/quorumclient/quorumclient.go
+++ b/sms-service/src/quorumclient/quorumclient.go
@@ -25,6 +25,8 @@ import (
"log"
"net/http"
"os"
+ smsauth "sms/auth"
+ smslogger "sms/log"
"strings"
"time"
)
@@ -33,6 +35,8 @@ import (
//calls necessary initialization endpoints on the
//SMS webservice
func main() {
+ smslogger.Init("quorumclient.log")
+
//Struct to read json configuration file
type config struct {
BackEndURL string `json:"url"`
@@ -41,7 +45,9 @@ func main() {
ClientKey string `json:"clientkey"`
B64Key string `json:"key"`
TimeOut string `json:"timeout"`
+ DisableTLS bool `json:"disable_tls"`
}
+
//Load the config File for reading
vcf, err := os.Open("config.json")
if err != nil {
@@ -55,32 +61,44 @@ func main() {
log.Fatalf("Error while parsing config file %v", err)
}
- duration, _ := time.ParseDuration(cfg.TimeOut)
- ticker := time.NewTicker(duration)
-
- for _ = range ticker.C {
+ transport := http.Transport{}
+ if cfg.DisableTLS {
+ // Read the CA cert. This can be the self-signed CA
+ // or CA cert provided by AAF
caCert, err := ioutil.ReadFile(cfg.CAFile)
if err != nil {
log.Fatalf("Error while reading CA file %v ", err)
}
+
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
+
+ // Load the client certificate files
cert, err := tls.LoadX509KeyPair(cfg.ClientCert, cfg.ClientKey)
if err != nil {
log.Fatalf("Error while loading key pair %v ", err)
}
- client := &http.Client{
- Transport: &http.Transport{
- TLSClientConfig: &tls.Config{
- RootCAs: caCertPool,
- Certificates: []tls.Certificate{cert},
- },
- },
+ transport.TLSClientConfig = &tls.Config{
+ RootCAs: caCertPool,
+ Certificates: []tls.Certificate{cert},
}
+ }
+
+ client := &http.Client{
+ Transport: &transport,
+ }
+
+ smsauth.GeneratePGPKeyPair()
+
+ duration, _ := time.ParseDuration(cfg.TimeOut)
+ ticker := time.NewTicker(duration)
+
+ for _ = range ticker.C {
+
//URL and Port is configured in config file
- response, err := client.Get(cfg.BackEndURL + "v1/sms/status")
+ response, err := client.Get(cfg.BackEndURL + "/v1/sms/status")
if err != nil {
log.Fatalf("Error while connecting to SMS webservice %v", err)
}
@@ -89,15 +107,17 @@ func main() {
if err != nil {
log.Fatalf("Error while reading response %v", err)
}
+
var data map[string]interface{}
json.Unmarshal(responseData, &data)
sealed := data["sealed"].(bool)
+
// Unseal the vault if sealed
if sealed {
decdB64Key, _ := base64.StdEncoding.DecodeString(cfg.B64Key)
body := strings.NewReader(`{"key":"` + string(decdB64Key) + `"}`)
//URL and PORT is configured via config file
- response, err = client.Post(cfg.BackEndURL+"v1/sms/unseal", "application/json", body)
+ response, err = client.Post(cfg.BackEndURL+"/v1/sms/unseal", "application/json", body)
if err != nil {
log.Fatalf("Error while unsealing %v", err)
}