diff --git a/README.md b/README.md index d1db8870f1d44ee31e5d677f9e4d78b1d89c7660..d546e85140536803b657303fad068a9d9436dfdd 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Optional args: |--registrationaddr|-a|Address:Port for connecting to the registration server|-a "localhost:11420"| |--dummyfrequency| |How often dummy messages should be sent per second. This flag is likely to be replaced when we implement better dummy message sending.|--dummyfrequency 0.5| |--end2end| |Send messages with E2E encryption to destination user|--end2end| +|--keyParams| |Set E2E key generation parameters. Pass values in comma separated list, with the following order: MinKeys,MaxKeys,NumRekeys,TTLScalar,MinNumKeys|--keyParams 100,200,32,1.2,50| ##Project Structure diff --git a/api/client.go b/api/client.go index a60843f5995678b68d2efaa557a319cd8bd181d0..efbc52355245e337d9cacbe3fbca391a95846ae3 100644 --- a/api/client.go +++ b/api/client.go @@ -403,6 +403,10 @@ func (cl *Client) GetCurrentUser() *id.User { return cl.sess.GetCurrentUser().User } +func (cl *Client) GetKeyParams() *keyStore.KeyParams { + return cl.sess.GetKeyStore().GetKeyParams() +} + // Logout closes the connection to the server at this time and does // nothing with the user id. In the future this will release resources // and safely release any sensitive memory. diff --git a/api/client_test.go b/api/client_test.go index 1bc1d5e223124c54bfbf99e34e6f7aa3d871621e..ec0af42b61f9c1ae336a98649136fb4d2484160a 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -301,7 +301,7 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { testClient.registerUserE2E(partner, partnerPubKeyCyclic.Bytes()) // Generate all keys and confirm they all match - keyParams := session.GetKeyStore().GetKeyParams() + keyParams := testClient.GetKeyParams() baseKey, _ := diffieHellman.CreateDHSessionKey(partnerPubKeyCyclic, myPrivKeyCyclic, grp) keyTTL, numKeys := e2e.GenerateKeyTTL(baseKey.GetLargeInt(), keyParams.MinKeys, keyParams.MaxKeys, keyParams.TTLParams) diff --git a/cmd/root.go b/cmd/root.go index a3fbc4ab9f8836031d421445ee69c10f0c8ba10d..fe5d64039d6a6d513df6d7fb7639ecdeee52dbcd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,6 +31,7 @@ import ( "log" "math/big" "os" + "strconv" "sync/atomic" "time" ) @@ -52,6 +53,7 @@ var registrationAddr string var registrationCode string var userEmail string var end2end bool +var keyParams []string var client *api.Client // Execute adds all child commands to the root command and sets flags @@ -173,6 +175,40 @@ func sessionInitialization() *id.User { return uid } +func setKeyParams() { + minKeys, err := strconv.Atoi(keyParams[0]) + if err != nil { + return + } + + maxKeys, err := strconv.Atoi(keyParams[1]) + if err != nil { + return + } + + numRekeys, err := strconv.Atoi(keyParams[2]) + if err != nil { + return + } + + ttlScalar, err := strconv.ParseFloat(keyParams[3], 64) + if err != nil { + return + } + + minNumKeys, err := strconv.Atoi(keyParams[4]) + if err != nil { + return + } + + params := client.GetKeyParams() + params.MinKeys = uint16(minKeys) + params.MaxKeys = uint16(maxKeys) + params.NumRekeys = uint16(numRekeys) + params.TTLScalar = ttlScalar + params.MinNumKeys = uint16(minNumKeys) +} + type FallbackListener struct { messagesReceived int64 } @@ -274,6 +310,10 @@ var rootCmd = &cobra.Command{ SetCertPaths(gwCertPath, registrationCertPath) userID := sessionInitialization() + // Set Key parameters if defined + if len(keyParams) == 5 { + setKeyParams() + } // Set up the listeners for both of the types the client needs for // the integration test // Normal text messages @@ -454,6 +494,10 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&end2end, "end2end", "", false, "Send messages with E2E encryption to destination user") + + rootCmd.PersistentFlags().StringArrayVarP(&keyParams, "keyParams", "", + make([]string, 0), "Define key generation parameters. Pass values in comma separated list"+ + " in the following order: MinKeys,MaxKeys,NumRekeys,TTLScalar,MinNumKeys") } // Sets the cert paths in comms diff --git a/keyStore/keyStore.go b/keyStore/keyStore.go index 868a892fcfa9aebbe0789a17a6e19ee6b0f56c34..85392d0e3257ba15b4ca90ce15f85dfd1a26f392 100644 --- a/keyStore/keyStore.go +++ b/keyStore/keyStore.go @@ -110,17 +110,17 @@ type KeyStore struct { // Reception Key Managers map recvKeyManagers map[id.User]*KeyManager - lock sync.Mutex + lock sync.Mutex } func NewStore() *KeyStore { ks := new(KeyStore) ks.params = &KeyParams{ - MinKeys: minKeys, - MaxKeys: maxKeys, + MinKeys: minKeys, + MaxKeys: maxKeys, NumRekeys: numReKeys, TTLParams: e2e.TTLParams{ - TTLScalar: ttlScalar, + TTLScalar: ttlScalar, MinNumKeys: threshold, }, }