diff --git a/README.md b/README.md index 92fecb3c58ee43c41e48aa87d09189163b68e60e..c89b714f0330336fac8c1bc6dbe88eb0587fef53 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,6 @@ Optional args: |--version|-V|Show the generated version information. Run `$ go generate cmd/version.go` if the information is out of date.|--version| |--sessionfile|-f|File path for storing the session. If not specified, the session will be stored in RAM and won't persist.|-f mySuperCoolSessionFile| |--noBlockingTransmission| |Disables transmission rate limiting (useful for dummy client)|--noBlockingTransmission| -|--mint| |Creates some coins for this user for testing and demos|--mint| |--help|-h|Prints a help message with all of these flags|-h| |--gwcertpath|-c|Enables TLS by passing in path to the gateway certificate file|-c "~/Documents/gateway.cert"| |--registrationcertpath|-r|Enables TLS by passing in path to the registration server certificate file|-r "~/Documents/registration.cert"| @@ -60,7 +59,7 @@ Optional args: |--nick| |Nickname to register for User Discovery (default "Default")|| |--ndfPubKey|-p|Path to the public key for the network definition JSON file| |--ndf|-n|Path to the network definition JSON file| -|--ndfVerifySignature| |Specifies if the NDF should be loaded without the signature| +|--ndfVerifySignature| |Specifies if the NDF should be loaded without the signature. defaults to true| |--ndfRegistration| |Overwrite the Registration values for the NDF| |--ndfUDB| |Overwrite the UDB values for the NDF| @@ -91,9 +90,7 @@ the client's part of the cipher. without seriously considering the alternatives. Most important is the Log variable: -```go globals.Log.ERROR.Println("this is an error") -``` Using this global Log variable allows external users of jww logging, like the console UI, to see and print log messages from the client library if they need diff --git a/api/client.go b/api/client.go index 20cd6370f129c3f3313d037a42bae99422ab15b3..e2080564e745e5342898c48780ee3d023dc7c97c 100644 --- a/api/client.go +++ b/api/client.go @@ -201,7 +201,10 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (* // Generate DSA keypair even for precanned users as it will probably // be needed for the new UDB flow - params := signature.GetDefaultDSAParams() + params := signature.CustomDSAParams( + cmixGrp.GetP(), + cmixGrp.GetQ(), + cmixGrp.GetG()) privateKey := params.PrivateKeyGen(rand.Reader) publicKey := privateKey.PublicKeyGen() @@ -211,10 +214,11 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (* globals.Log.DEBUG.Printf("Registering precanned user") UID, successLook = user.Users.LookupUser(registrationCode) + fmt.Println("UID:", UID, "success:", successLook) + if !successLook { globals.Log.ERROR.Printf("Register: HUID does not match") - err = errors.New("could not register due to invalid HUID") - return id.ZeroID, err + return id.ZeroID, errors.New("could not register due to invalid HUID") } var successGet bool @@ -412,7 +416,10 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (* return id.ZeroID, err } - nus.Immolate() + err = nus.Immolate() + if err != nil { + globals.Log.ERROR.Printf("Error on immolate: %+v", err) + } nus = nil return UID, nil @@ -604,7 +611,7 @@ func (cl *Client) LookupNick(user *id.User, func (cl *Client) registerUserE2E(partnerID *id.User, partnerPubKey []byte) { // Get needed variables from session - grp := cl.session.GetE2EGroup() + grp := cl.session.GetCmixGroup() userID := cl.session.GetCurrentUser().User // Create user private key and partner public key diff --git a/api/client_test.go b/api/client_test.go index 71cd232a0a9c21f599a9ea094dc48aad11c195b8..508da9cf8e98a9a18b00d10f4810c594a0d63546 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -10,6 +10,7 @@ import ( "bytes" "crypto/sha256" "encoding/gob" + "fmt" "github.com/golang/protobuf/proto" "gitlab.com/elixxir/client/cmixproto" "gitlab.com/elixxir/client/globals" @@ -23,6 +24,7 @@ import ( "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/signature" + "gitlab.com/elixxir/primitives/circuit" "gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/id" "reflect" @@ -59,41 +61,39 @@ func TestRegistrationGob(t *testing.T) { t.Error(err) } - VerifyRegisterGobUser(testClient, t) - VerifyRegisterGobKeys(testClient, t) + VerifyRegisterGobUser(&Session, t) + VerifyRegisterGobKeys(&Session, testClient.topology, t) } -func VerifyRegisterGobUser(testClient *Client, t *testing.T) { +func VerifyRegisterGobUser(session user.Session, t *testing.T) { - session := testClient.session + expectedUser := id.NewUserFromUint(5, t) - if session.GetCurrentUser().User != id.NewUserFromUint(5, t) { - t.Errorf("User's ID was %q, expected %v", - session.GetCurrentUser().User, 5) + if reflect.DeepEqual(session.GetCurrentUser().User, &expectedUser) { + t.Errorf("Incorrect User ID; \n expected %q \n recieved: %q", + expectedUser, session.GetCurrentUser().User) } } -func VerifyRegisterGobKeys(testClient *Client, t *testing.T) { +func VerifyRegisterGobKeys(session user.Session, topology *circuit.Circuit, t *testing.T) { cmixGrp, _ := getGroups() h := sha256.New() h.Write([]byte(string(20005))) expectedTransmissionBaseKey := cmixGrp.NewIntFromBytes(h.Sum(nil)) - session := testClient.session - - if session.GetKeys(testClient.topology)[0].TransmissionKey.Cmp( + if session.GetKeys(topology)[0].TransmissionKey.Cmp( expectedTransmissionBaseKey) != 0 { t.Errorf("Transmission base key was %v, expected %v", - session.GetKeys(testClient.topology)[0].TransmissionKey.Text(16), + session.GetKeys(topology)[0].TransmissionKey.Text(16), expectedTransmissionBaseKey.Text(16)) } h = sha256.New() h.Write([]byte(string(40005))) expectedReceptionBaseKey := cmixGrp.NewIntFromBytes(h.Sum(nil)) - if session.GetKeys(testClient.topology)[0].ReceptionKey.Cmp( + if session.GetKeys(topology)[0].ReceptionKey.Cmp( expectedReceptionBaseKey) != 0 { t.Errorf("Reception base key was %v, expected %v", - session.GetKeys(testClient.topology)[0].ReceptionKey.Text(16), + session.GetKeys(topology)[0].ReceptionKey.Text(16), expectedReceptionBaseKey.Text(16)) } } @@ -201,8 +201,8 @@ func TestRegisterUserE2E(t *testing.T) { partner := id.NewUserFromUint(14, t) params := signature.CustomDSAParams( cmixGrp.GetP(), - cmixGrp.GetG(), - cmixGrp.GetQ()) + cmixGrp.GetQ(), + cmixGrp.GetG()) rng := csprng.NewSystemRNG() myPrivKey := params.PrivateKeyGen(rng) myPrivKeyCyclic := cmixGrp.NewIntFromLargeInt(myPrivKey.GetKey()) @@ -216,9 +216,9 @@ func TestRegisterUserE2E(t *testing.T) { myUser, make(map[id.Node]user.NodeKeys), myPubKey, myPrivKey, cmixGrp, e2eGrp) testClient.session = session - + fmt.Println("runn") testClient.registerUserE2E(partner, partnerPubKeyCyclic.Bytes()) - + fmt.Println("dunn") // Confirm we can get all types of keys km := session.GetKeyStore().GetSendManager(partner) if km == nil { @@ -248,9 +248,9 @@ func TestRegisterUserE2E(t *testing.T) { // Generate one reception key of each type to test // fingerprint map - baseKey, _ := diffieHellman.CreateDHSessionKey(partnerPubKeyCyclic, myPrivKeyCyclic, e2eGrp) - recvKeys := e2e.DeriveKeys(e2eGrp, baseKey, partner, uint(1)) - recvReKeys := e2e.DeriveEmergencyKeys(e2eGrp, baseKey, partner, uint(1)) + baseKey, _ := diffieHellman.CreateDHSessionKey(partnerPubKeyCyclic, myPrivKeyCyclic, cmixGrp) + recvKeys := e2e.DeriveKeys(cmixGrp, baseKey, partner, uint(1)) + recvReKeys := e2e.DeriveEmergencyKeys(cmixGrp, baseKey, partner, uint(1)) h, _ := hash.NewCMixHash() h.Write(recvKeys[0].Bytes()) @@ -290,8 +290,8 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { partner := id.NewUserFromUint(14, t) params := signature.CustomDSAParams( cmixGrp.GetP(), - cmixGrp.GetG(), - cmixGrp.GetQ()) + cmixGrp.GetQ(), + cmixGrp.GetG()) rng := csprng.NewSystemRNG() myPrivKey := params.PrivateKeyGen(rng) myPrivKeyCyclic := cmixGrp.NewIntFromLargeInt(myPrivKey.GetKey()) @@ -311,15 +311,15 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { // Generate all keys and confirm they all match keyParams := testClient.GetKeyParams() - baseKey, _ := diffieHellman.CreateDHSessionKey(partnerPubKeyCyclic, myPrivKeyCyclic, e2eGrp) + baseKey, _ := diffieHellman.CreateDHSessionKey(partnerPubKeyCyclic, myPrivKeyCyclic, cmixGrp) keyTTL, numKeys := e2e.GenerateKeyTTL(baseKey.GetLargeInt(), keyParams.MinKeys, keyParams.MaxKeys, keyParams.TTLParams) - sendKeys := e2e.DeriveKeys(e2eGrp, baseKey, userID, uint(numKeys)) - sendReKeys := e2e.DeriveEmergencyKeys(e2eGrp, baseKey, + sendKeys := e2e.DeriveKeys(cmixGrp, baseKey, userID, uint(numKeys)) + sendReKeys := e2e.DeriveEmergencyKeys(cmixGrp, baseKey, userID, uint(keyParams.NumRekeys)) - recvKeys := e2e.DeriveKeys(e2eGrp, baseKey, partner, uint(numKeys)) - recvReKeys := e2e.DeriveEmergencyKeys(e2eGrp, baseKey, + recvKeys := e2e.DeriveKeys(cmixGrp, baseKey, partner, uint(numKeys)) + recvReKeys := e2e.DeriveEmergencyKeys(cmixGrp, baseKey, partner, uint(keyParams.NumRekeys)) // Confirm all keys @@ -503,19 +503,23 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { func getGroups() (*cyclic.Group, *cyclic.Group) { cmixGrp := cyclic.NewGroup( - large.NewIntFromString("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"+ - "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"+ - "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"+ - "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"+ - "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"+ - "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"+ - "83655D23DCA3AD961C62F356208552BB9ED529077096966D"+ - "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"+ - "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"+ - "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"+ - "15728E5A8AACAA68FFFFFFFFFFFFFFFF", 16), - large.NewIntFromString("2", 16), - large.NewIntFromString("2", 16)) + large.NewIntFromString("9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48"+ + "C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44F"+ + "FE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5"+ + "B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE2"+ + "35567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41"+ + "F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE"+ + "92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA15"+ + "3E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B", 16), + large.NewIntFromString("5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613"+ + "D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C4"+ + "6A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472"+ + "085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5"+ + "AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA"+ + "3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71"+ + "BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0"+ + "DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7", 16), + large.NewIntFromString("F2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F", 16)) e2eGrp := cyclic.NewGroup( large.NewIntFromString("E2EE983D031DC1DB6F1A7A67DF0E9A8E5561DB8E8D49413394C049B"+ diff --git a/api/mockserver_test.go b/api/mockserver_test.go index 3584d603734a2f6dad6058843aeaa3fc54bdeeba..5d91c396368a321cfc87a5bb138f3999d672c32e 100644 --- a/api/mockserver_test.go +++ b/api/mockserver_test.go @@ -16,11 +16,14 @@ import ( "gitlab.com/elixxir/comms/registration" "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/ndf" + "math/rand" "os" "testing" + "time" ) -const NumGWs = 3 +const NumNodes = 3 +const NumGWs = NumNodes const RegPort = 5000 const GWsStartPort = 10000 @@ -28,7 +31,7 @@ var RegHandler = MockRegistration{} var RegComms *registration.RegistrationComms const ValidRegCode = "UAV6IWD6" -const InvalidRegCode = "INVALID_REG_CODE" +const InvalidRegCode = "INVALID_REG_CODE_" var RegGWHandlers [3]*TestInterface = [NumGWs]*TestInterface{ {LastReceivedMessage: pb.Slot{}}, @@ -104,7 +107,7 @@ func TestRegister_ValidRegParams___(t *testing.T) { } if *regRes == *id.ZeroID { - t.Errorf("Invalid registration number received: %v", *regRes) + t.Errorf("Invalid registration number received: %+v", *regRes) } } @@ -126,9 +129,9 @@ func TestRegister_InvalidPrecannedRegCodeReturnsError(t *testing.T) { } // Register with invalid reg code - _, err = client.Register(true, InvalidRegCode, "", "") - if err != nil { - t.Error("Registration worked with invalid registration code!") + uid, err := client.Register(true, InvalidRegCode, "", "") + if err == nil { + t.Errorf("Registration worked with invalid registration code! UID: %v", uid) } } @@ -278,13 +281,17 @@ func TestLogout(t *testing.T) { // gateways used for registration and gateway used for session func testMainWrapper(m *testing.M) int { + rng := rand.New(rand.NewSource(time.Now().UnixNano())) + + rndPort := int(rng.Uint64() % 10000) + def = getNDF() // Start mock gateways used by registration and defer their shutdown (may not be needed) for i, handler := range RegGWHandlers { gw := ndf.Gateway{ - Address: fmtAddress(GWsStartPort + i), + Address: fmtAddress(GWsStartPort + i + rndPort), } def.Gateways = append(def.Gateways, gw) @@ -295,11 +302,20 @@ func testMainWrapper(m *testing.M) int { // Start mock registration server and defer its shutdown def.Registration = ndf.Registration{ - Address: fmtAddress(RegPort), + Address: fmtAddress(RegPort + rndPort), } RegComms = registration.StartRegistrationServer(def.Registration.Address, &RegHandler, "", "") + for i := 0; i < NumNodes; i++ { + nIdBytes := make([]byte, id.NodeIdLen) + nIdBytes[0] = byte(i) + n := ndf.Node{ + ID: nIdBytes, + } + def.Nodes = append(def.Nodes, n) + } + defer testWrapperShutdown() return m.Run() } @@ -333,19 +349,23 @@ func getNDF() *ndf.NetworkDefinition { Generator: "2", }, CMIX: ndf.Group{ - Prime: "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" + - "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" + - "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" + - "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" + - "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" + - "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" + - "83655D23DCA3AD961C62F356208552BB9ED529077096966D" + - "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" + - "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" + - "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" + - "15728E5A8AACAA68FFFFFFFFFFFFFFFF", - SmallPrime: "2", - Generator: "2", + Prime: "9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48" + + "C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44F" + + "FE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5" + + "B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE2" + + "35567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41" + + "F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE" + + "92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA15" + + "3E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B", + SmallPrime: "F2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F", + Generator: "5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613" + + "D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C4" + + "6A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472" + + "085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5" + + "AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA" + + "3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71" + + "BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0" + + "DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7", }, } } diff --git a/bindings/client_test.go b/bindings/client_test.go index 8cf0e84a0c2533ef75ef8c31fa344b323643d1b0..14c6f0fb4e38694e0be767d1517f9fcb59aae805 100644 --- a/bindings/client_test.go +++ b/bindings/client_test.go @@ -16,6 +16,7 @@ import ( "gitlab.com/elixxir/comms/gateway" "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/ndf" + "math/rand" "os" "reflect" "testing" @@ -23,11 +24,9 @@ import ( ) const NumGWs = 1 -const gwAddress = "localhost:5557" const GWsStartPort = 10000 const ValidRegCode = "UAV6IWD6" -const InvalidRegCode = "INVALID_REG_CODE" var GWComms [NumGWs]*gateway.GatewayComms @@ -62,22 +61,6 @@ func TestNewClient(t *testing.T) { } } -// BytesReceiver receives the last message and puts the data it received into -// byte slices -type BytesReceiver struct { - receptionBuffer []byte - lastSID []byte - lastRID []byte -} - -// This is the method that globals.Receive calls when you set a BytesReceiver -// as the global receiver -func (br *BytesReceiver) Receive(message Message) { - br.receptionBuffer = append(br.receptionBuffer, message.GetPayload()...) - br.lastRID = message.GetRecipient() - br.lastSID = message.GetSender() -} - func TestRegister(t *testing.T) { d := api.DummyStorage{Location: "Blah", LastSave: []byte{'a', 'b', 'c'}} @@ -269,13 +252,17 @@ func TestParse(t *testing.T) { // gateways used for registration and gateway used for session func testMainWrapper(m *testing.M) int { + rng := rand.New(rand.NewSource(time.Now().UnixNano())) + + rndPort := int(rng.Uint64() % 10000) + def = getNDF() // Start mock gateways used by registration and defer their shutdown (may not be needed) for i := 0; i < NumGWs; i++ { gw := ndf.Gateway{ - Address: fmtAddress(GWsStartPort + i), + Address: fmtAddress(GWsStartPort + i + rndPort), } def.Gateways = append(def.Gateways, gw) diff --git a/cmd/root.go b/cmd/root.go index 7f59a48dbe3136d7f12e1cd19f1ac07631cffa5c..0e009b221cc504b0547cd03a20d8ba44d93a5e77 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -41,7 +41,6 @@ var message string var sessionFile string var dummyFrequency float64 var noBlockingTransmission bool -var mint bool var rateLimiting uint32 var showVer bool var gwCertPath string @@ -177,7 +176,7 @@ func sessionInitialization() *id.User { globals.Log.INFO.Printf("Attempting to register with code %s...", regCode) - uid, err = client.Register(userId != 0, regCode, "", userEmail) + uid, err = client.Register(userId != 0, regCode, userNick, userEmail) if err != nil { globals.Log.ERROR.Printf("Could Not Register User: %s\n", err.Error()) return id.ZeroID @@ -301,7 +300,12 @@ func (l *ChannelListener) Hear(item switchboard.Item, isHeardElsewhere bool) { message := item.(*parse.Message) globals.Log.INFO.Println("Hearing a channel message") result := cmixproto.ChannelMessage{} - proto.Unmarshal(message.Body, &result) + err := proto.Unmarshal(message.Body, &result) + + if err != nil { + globals.Log.ERROR.Printf("Could not unmarhsal message, message "+ + "not processed: %+v", err) + } sender, ok := user.Users.GetUser(message.Sender) var senderNick string @@ -474,9 +478,6 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&noBlockingTransmission, "noBlockingTransmission", "", false, "Sets if transmitting messages blocks or not. "+ "Defaults to true if unset.") - rootCmd.PersistentFlags().BoolVarP(&mint, "mint", "", false, - "Mint some coins for testing") - rootCmd.PersistentFlags().Uint32VarP(&rateLimiting, "rateLimiting", "", 1000, "Sets the amount of time, in ms, "+ "that the client waits between sending messages. "+ diff --git a/crypto/encryptdecrypt_test.go b/crypto/encryptdecrypt_test.go index 97ae759d5a9cfe8ee87916ea1ee915669360bc83..d0f4c511653ee92802a31eabf0a402fdd7cbab4a 100644 --- a/crypto/encryptdecrypt_test.go +++ b/crypto/encryptdecrypt_test.go @@ -38,6 +38,8 @@ func setup() { cmixGrp, e2eGrp := getGroups() + user.InitUserRegistry(cmixGrp) + UID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 18}) u, _ := user.Users.GetUser(UID) diff --git a/io/collate.go b/io/collate.go index fb7774cae0920b6bf1097b6cfcb4897f84643b1a..86ae0a5536154a03aef58ce6d1f2a9a61e2d131c 100644 --- a/io/collate.go +++ b/io/collate.go @@ -49,7 +49,7 @@ func NewCollator() *Collator { func (mb *Collator) AddMessage(message *format.Message, timeout time.Duration) *parse.Message { - payload := message.Contents.Get() + payload := message.Contents.GetRightAligned() // There's currently no mechanism for knowing who sent an unencrypted // message, I think? // Let's just try ZeroID for now... diff --git a/io/collate_test.go b/io/collate_test.go index 0e71dcea756c4518b9efd926e4a6434b5000fb00..40790998f6b1587c9704ae46d75f648dbe33a264 100644 --- a/io/collate_test.go +++ b/io/collate_test.go @@ -41,7 +41,7 @@ func TestCollator_AddMessage(t *testing.T) { fm := format.NewMessage() fm.SetRecipient(id.NewUserFromUint(6, t)) - fm.Contents.Set(partitions[j]) + fm.Contents.SetRightAligned(partitions[j]) result = collator.AddMessage(fm, time.Minute) } @@ -53,7 +53,7 @@ func TestCollator_AddMessage(t *testing.T) { // already, and strings should respect null terminators, // so it's probably not actually that much of a problem. if !bytes.Contains(result.Body, typedBody.Body) { - t.Errorf("Input didn't match output for %v. Got: %v, expected %v", + t.Errorf("Input didn't match output for %v. \n Got: %v\n Expected %v", i, hex.EncodeToString(result.Body), hex.EncodeToString(typedBody.Body)) } @@ -74,7 +74,7 @@ func TestCollator_AddMessage_Timeout(t *testing.T) { for i := range partitions { fm := format.NewMessage() fm.SetRecipient(id.NewUserFromUint(6, t)) - fm.Contents.Set(partitions[i]) + fm.Contents.SetRightAligned(partitions[i]) result = collator.AddMessage(fm, 80*time.Millisecond) if result != nil { diff --git a/parse/partition_test.go b/parse/partition_test.go index 7663f880b503052993fabe9c3d643ca961aed02e..349ad3c75da2cae06d696afdce1d76a4f5f17163 100644 --- a/parse/partition_test.go +++ b/parse/partition_test.go @@ -8,8 +8,6 @@ package parse import ( "bytes" - "gitlab.com/elixxir/crypto/e2e" - "gitlab.com/elixxir/primitives/format" "math/rand" "testing" ) @@ -108,7 +106,7 @@ func TestPartitionLongest(t *testing.T) { t.Fatalf(err.Error()) } - expectedNumberOfPartitions := 143 + expectedNumberOfPartitions := 139 if len(actual) != expectedNumberOfPartitions { t.Errorf("Expected a 52480-byte message to split into %v partitions, got %v instead", @@ -118,7 +116,7 @@ func TestPartitionLongest(t *testing.T) { // check the index and max index of the last partition lastIndex := len(actual) - 1 - expectedIdx := byte(142) + expectedIdx := byte(138) idxLocation := len(id) maxIdxLocation := len(id) + 1 actualIdx := actual[lastIndex][idxLocation] @@ -137,7 +135,7 @@ func TestPartitionLongest(t *testing.T) { // message that's too long to partition func TestPartitionTooLong(t *testing.T) { id := []byte{0x1f, 0x2f, 0x3f, 0x4f, 0x5f} - _, err := Partition(randomString(0, 57856), id) + _, err := Partition(randomString(0, 257856), id) if err == nil { t.Error("Partition() processed a message that was too long to be" + @@ -157,12 +155,7 @@ func TestOnlyAssemble(t *testing.T) { partitions := make([][]byte, len(messageChunks)) for i := range partitions { - paddedChunk, err := e2e.Pad([]byte(messageChunks[i]), - format.ContentsLen) - if err != nil { - t.Error(err) - } - partitions[i] = append(partitions[i], paddedChunk...) + partitions[i] = append(partitions[i], []byte(messageChunks[i])...) } assembled, err := Assemble(partitions) @@ -170,7 +163,7 @@ func TestOnlyAssemble(t *testing.T) { t.Error(err.Error()) } if completeMessage != string(assembled) { - t.Errorf("TestOnlyAssemble: got \"%v\"; expected \"%v\".", + t.Errorf("TestOnlyAssemble: got \"%v\";\n expected \"%v\".", string(assembled), completeMessage) } } diff --git a/rekey/rekey_test.go b/rekey/rekey_test.go index 6be90259178b8745bd2c8dddec95113b8cb1ee4d..3e770747176348930859f02bdbaff44f5921dd11 100644 --- a/rekey/rekey_test.go +++ b/rekey/rekey_test.go @@ -58,8 +58,8 @@ func TestMain(m *testing.M) { user.InitUserRegistry(grp) params := signature.CustomDSAParams( grp.GetP(), - grp.GetG(), - grp.GetQ()) + grp.GetQ(), + grp.GetG()) rng := csprng.NewSystemRNG() u := &user.User{ User: id.NewUserFromUints(&[4]uint64{0, 0, 0, 18}), @@ -249,8 +249,8 @@ func TestRekey(t *testing.T) { grp, _ := getGroups() params := signature.CustomDSAParams( grp.GetP(), - grp.GetG(), - grp.GetQ()) + grp.GetQ(), + grp.GetG()) rng := csprng.NewSystemRNG() partnerPrivKey := params.PrivateKeyGen(rng) partnerPubKey := partnerPrivKey.PublicKeyGen() @@ -271,7 +271,7 @@ func TestRekey(t *testing.T) { t.Errorf("Rekey returned error: %v", rekeyList.err.Error()) } // Confirm hash of baseKey matches expected - value := <- ListenCh + value := <-ListenCh // Get hash as last 32 bytes of message bytes actual := value[len(value)-32:] km = session.GetKeyStore().GetRecvManager(partnerID) diff --git a/user/user_test.go b/user/user_test.go index 52067bab07e96084b849febafb1a4333cb29a91f..4de0d3cbf2049b3dcae955276554dd982d1027b1 100644 --- a/user/user_test.go +++ b/user/user_test.go @@ -14,43 +14,10 @@ import ( "testing" ) -// InitGroup sets up the cryptographic constants for cMix -func InitGroup() *cyclic.Group { - - base := 16 - - pString := "9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48" + - "C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44F" + - "FE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5" + - "B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE2" + - "35567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41" + - "F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE" + - "92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA15" + - "3E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B" - - gString := "5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613" + - "D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C4" + - "6A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472" + - "085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5" + - "AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA" + - "3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71" + - "BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0" + - "DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7" - - qString := "F2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F" - - p := large.NewIntFromString(pString, base) - g := large.NewIntFromString(gString, base) - q := large.NewIntFromString(qString, base) - - grp := cyclic.NewGroup(p, g, q) - - return grp -} - // TestUserRegistry tests the constructors/getters/setters // surrounding the User struct and the Registry interface func TestUserRegistry(t *testing.T) { + InitUserRegistry(InitGroup()) // Test if CountUsers correctly counts the hard-coded demo users if Users.CountUsers() != NumDemoUsers { t.Errorf("CountUsers: Start size of userRegistry not zero!") @@ -143,3 +110,37 @@ func TestPrintRegCodes(t *testing.T) { t.Logf("%v:\t%v", i, currentID.RegistrationCode()) } } + +// InitGroup sets up the cryptographic constants for cMix +func InitGroup() *cyclic.Group { + + base := 16 + + pString := "9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48" + + "C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44F" + + "FE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5" + + "B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE2" + + "35567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41" + + "F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE" + + "92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA15" + + "3E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B" + + gString := "5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613" + + "D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C4" + + "6A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472" + + "085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5" + + "AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA" + + "3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71" + + "BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0" + + "DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7" + + qString := "F2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F" + + p := large.NewIntFromString(pString, base) + g := large.NewIntFromString(gString, base) + q := large.NewIntFromString(qString, base) + + grp := cyclic.NewGroup(p, g, q) + + return grp +}