Skip to content
Snippets Groups Projects
Commit 114f3b35 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

added code to disable TLS via API and command line

parent c9e50032
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ type Client struct { ...@@ -47,6 +47,7 @@ type Client struct {
comm io.Communications comm io.Communications
ndf *ndf.NetworkDefinition ndf *ndf.NetworkDefinition
topology *circuit.Circuit topology *circuit.Circuit
tls bool
} }
var PermissioningAddrID = "registration" var PermissioningAddrID = "registration"
...@@ -146,9 +147,17 @@ func NewClient(s globals.Storage, loc string, ndfJSON *ndf.NetworkDefinition) (* ...@@ -146,9 +147,17 @@ func NewClient(s globals.Storage, loc string, ndfJSON *ndf.NetworkDefinition) (*
cl.topology = circuit.New(nodeIDs) cl.topology = circuit.New(nodeIDs)
cl.tls = true
return cl, nil return cl, nil
} }
// DisableTLS makes the client run with TLS disabled
// Must be called before Connect
func (cl *Client) DisableTLS() {
cl.tls = false
}
// Connects to gateways and registration server (if needed) // Connects to gateways and registration server (if needed)
// using TLS filepaths to create credential information // using TLS filepaths to create credential information
// for connection establishment // for connection establishment
...@@ -161,7 +170,7 @@ func (cl *Client) Connect() error { ...@@ -161,7 +170,7 @@ func (cl *Client) Connect() error {
// connect to all gateways // connect to all gateways
for i, gateway := range cl.ndf.Gateways { for i, gateway := range cl.ndf.Gateways {
var gwCreds []byte var gwCreds []byte
if gateway.TlsCertificate != "" { if gateway.TlsCertificate != "" && cl.tls {
gwCreds = []byte(gateway.TlsCertificate) gwCreds = []byte(gateway.TlsCertificate)
} }
...@@ -181,7 +190,7 @@ func (cl *Client) Connect() error { ...@@ -181,7 +190,7 @@ func (cl *Client) Connect() error {
//connect to the registration server //connect to the registration server
if cl.ndf.Registration.Address != "" { if cl.ndf.Registration.Address != "" {
var regCert []byte var regCert []byte
if cl.ndf.Registration.TlsCertificate != "" { if cl.ndf.Registration.TlsCertificate != "" && cl.tls {
regCert = []byte(cl.ndf.Registration.TlsCertificate) regCert = []byte(cl.ndf.Registration.TlsCertificate)
} }
addr := io.ConnAddr(PermissioningAddrID) addr := io.ConnAddr(PermissioningAddrID)
......
...@@ -97,6 +97,7 @@ func FormatTextMessage(message string) []byte { ...@@ -97,6 +97,7 @@ func FormatTextMessage(message string) []byte {
// this would be the filename of the file that you're storing the user // this would be the filename of the file that you're storing the user
// session in. // session in.
func NewClient(storage Storage, loc string, ndfStr, ndfPubKey string) (*Client, error) { func NewClient(storage Storage, loc string, ndfStr, ndfPubKey string) (*Client, error) {
globals.Log.INFO.Printf("Binding call: NewClient()")
if storage == nil { if storage == nil {
return nil, errors.New("could not init client: Storage was nil") return nil, errors.New("could not init client: Storage was nil")
} }
...@@ -109,10 +110,18 @@ func NewClient(storage Storage, loc string, ndfStr, ndfPubKey string) (*Client, ...@@ -109,10 +110,18 @@ func NewClient(storage Storage, loc string, ndfStr, ndfPubKey string) (*Client,
return &Client{client: cl}, err return &Client{client: cl}, err
} }
// DisableTLS makes the client run with TLS disabled
// Must be called before Connect
func (cl *Client) DisableTLS() {
globals.Log.INFO.Printf("Binding call: DisableTLS()")
cl.DisableTLS()
}
// Connects to gateways and registration server (if needed) // Connects to gateways and registration server (if needed)
// using TLS filepaths to create credential information // using TLS filepaths to create credential information
// for connection establishment // for connection establishment
func (cl *Client) Connect() error { func (cl *Client) Connect() error {
globals.Log.INFO.Printf("Binding call: Connect()")
return cl.client.Connect() return cl.client.Connect()
} }
...@@ -124,6 +133,9 @@ func (cl *Client) Connect() error { ...@@ -124,6 +133,9 @@ func (cl *Client) Connect() error {
// gwAddressesList is CSV of gateway addresses // gwAddressesList is CSV of gateway addresses
// grp is the CMIX group needed for keys generation in JSON string format // grp is the CMIX group needed for keys generation in JSON string format
func (cl *Client) Register(preCan bool, registrationCode, nick, email, password string) ([]byte, error) { func (cl *Client) Register(preCan bool, registrationCode, nick, email, password string) ([]byte, error) {
globals.Log.INFO.Printf("Binding call: Register()\n"+
" preCan: %v\n registrationCode: %s\n nick: %s\n email: %s\n"+
" Password: ********", preCan, registrationCode, nick, email)
fmt.Println("calling client reg") fmt.Println("calling client reg")
UID, err := cl.client.Register(preCan, registrationCode, nick, email) UID, err := cl.client.Register(preCan, registrationCode, nick, email)
...@@ -138,6 +150,8 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email, password ...@@ -138,6 +150,8 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email, password
// Returns an empty string and an error // Returns an empty string and an error
// UID is a uint64 BigEndian serialized into a byte slice // UID is a uint64 BigEndian serialized into a byte slice
func (cl *Client) Login(UID []byte, password string) (string, error) { func (cl *Client) Login(UID []byte, password string) (string, error) {
globals.Log.INFO.Printf("Binding call: Login()\n"+
" UID: %v\n Password: ********", UID)
userID := id.NewUserFromBytes(UID) userID := id.NewUserFromBytes(UID)
return cl.client.Login(userID) return cl.client.Login(userID)
} }
...@@ -145,6 +159,7 @@ func (cl *Client) Login(UID []byte, password string) (string, error) { ...@@ -145,6 +159,7 @@ func (cl *Client) Login(UID []byte, password string) (string, error) {
// Starts the polling of the external servers. // Starts the polling of the external servers.
// Must be done after listeners are set up. // Must be done after listeners are set up.
func (cl *Client) StartMessageReceiver() error { func (cl *Client) StartMessageReceiver() error {
globals.Log.INFO.Printf("Binding call: StartMessageReceiver()")
return cl.client.StartMessageReceiver() return cl.client.StartMessageReceiver()
} }
......
...@@ -22,7 +22,6 @@ import ( ...@@ -22,7 +22,6 @@ import (
"gitlab.com/elixxir/client/user" "gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/elixxir/primitives/switchboard" "gitlab.com/elixxir/primitives/switchboard"
"io/ioutil" "io/ioutil"
"log" "log"
...@@ -50,8 +49,6 @@ var end2end bool ...@@ -50,8 +49,6 @@ var end2end bool
var keyParams []string var keyParams []string
var ndfPath string var ndfPath string
var skipNDFVerification bool var skipNDFVerification bool
var ndfRegistration []string
var ndfUDB []string
var ndfPubKey string var ndfPubKey string
var noTLS bool var noTLS bool
...@@ -91,7 +88,6 @@ func sessionInitialization() (*id.User, string, *api.Client) { ...@@ -91,7 +88,6 @@ func sessionInitialization() (*id.User, string, *api.Client) {
globals.Log.DEBUG.Printf("NDF Verified: %v", ndfJSON) globals.Log.DEBUG.Printf("NDF Verified: %v", ndfJSON)
// Overwrite the network definition with any specified flags // Overwrite the network definition with any specified flags
overwriteNDF(ndfJSON)
globals.Log.DEBUG.Printf("Overwrote NDF Vars: %v", ndfJSON) globals.Log.DEBUG.Printf("Overwrote NDF Vars: %v", ndfJSON)
//If no session file is passed initialize with RAM Storage //If no session file is passed initialize with RAM Storage
...@@ -147,6 +143,10 @@ func sessionInitialization() (*id.User, string, *api.Client) { ...@@ -147,6 +143,10 @@ func sessionInitialization() (*id.User, string, *api.Client) {
return id.ZeroID, "", nil return id.ZeroID, "", nil
} }
if noTLS {
client.DisableTLS()
}
// Connect to gateways and reg server // Connect to gateways and reg server
err = client.Connect() err = client.Connect()
if err != nil { if err != nil {
...@@ -551,16 +551,6 @@ func init() { ...@@ -551,16 +551,6 @@ func init() {
false, false,
"Specifies if the NDF should be loaded without the signature") "Specifies if the NDF should be loaded without the signature")
rootCmd.PersistentFlags().StringSliceVar(&ndfRegistration,
"ndfRegistration",
nil,
"Overwrite the Registration values for the NDF")
rootCmd.PersistentFlags().StringSliceVar(&ndfUDB,
"ndfUDB",
nil,
"Overwrite the UDB values for the NDF")
// Cobra also supports local flags, which will only run // Cobra also supports local flags, which will only run
// when this action is called directly. // when this action is called directly.
rootCmd.Flags().StringVarP(&message, "message", "m", "", "Message to send") rootCmd.Flags().StringVarP(&message, "message", "m", "", "Message to send")
...@@ -611,37 +601,3 @@ func initLog() { ...@@ -611,37 +601,3 @@ func initLog() {
} }
} }
} }
// overwriteNDF replaces fields in the NetworkDefinition structure with values
// specified from the commandline.
func overwriteNDF(n *ndf.NetworkDefinition) {
if len(ndfRegistration) == 3 {
n.Registration.Address = ndfRegistration[1]
n.Registration.TlsCertificate = ndfRegistration[2]
globals.Log.WARN.Println("Overwrote Registration values in the " +
"NetworkDefinition from the commandline")
}
if len(ndfUDB) == 2 {
udbIdString, err := base64.StdEncoding.DecodeString(ndfUDB[0])
if err != nil {
globals.Log.WARN.Printf("Could not decode USB ID: %v", err)
}
n.UDB.ID = udbIdString
globals.Log.WARN.Println("Overwrote UDB values in the " +
"NetworkDefinition from the commandline")
}
if noTLS {
for i := 0; i < len(n.Nodes); i++ {
n.Nodes[i].TlsCertificate = ""
}
n.Registration.TlsCertificate = ""
for i := 0; i < len(n.Gateways); i++ {
n.Gateways[i].TlsCertificate = ""
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment