diff --git a/auth/callback.go b/auth/callback.go index 34f8eb064222a1d02a899a1e96b72e7a785b501d..70b9c2843406205198cdb439666741b193c52518 100644 --- a/auth/callback.go +++ b/auth/callback.go @@ -326,8 +326,8 @@ func (m *Manager) handleRequest(cmixMsg format.Message, //create the contact, note that no facts are sent in the payload c := contact.Contact{ - ID: partnerID, - DhPubKey: partnerPubKey, + ID: partnerID.DeepCopy(), + DhPubKey: partnerPubKey.DeepCopy(), OwnershipProof: copySlice(ecrFmt.ownership), Facts: facts, } @@ -369,7 +369,7 @@ func (m *Manager) handleRequest(cmixMsg format.Message, partnerID, rndNum) cbList := m.resetCallbacks.Get(c.ID) for _, cb := range cbList { - ccb := cb.(interfaces.ResetCallback) + ccb := cb.(interfaces.ResetNotificationCallback) go ccb(c) } } diff --git a/auth/confirm.go b/auth/confirm.go index ecc32ac304282ad123125b761916e3ea9af9e697..28a5292aec2ad83f888c35e1f19feb32a55acea7 100644 --- a/auth/confirm.go +++ b/auth/confirm.go @@ -35,7 +35,7 @@ func (m *Manager) ConfirmRequestAuth(partner contact.Contact) (id.Round, error) // Cannot confirm already established channels if _, err := m.storage.E2e().GetPartner(partner.ID); err == nil { - em := fmt.Sprintf("Cannot FonritmRequestAuth for %s, "+ + em := fmt.Sprintf("Cannot ConfirmRequestAuth for %s, "+ "channel already exists. Ignoring", partner.ID) jww.WARN.Print(em) m.net.GetEventManager().Report(5, "Auth", diff --git a/auth/manager.go b/auth/manager.go index 6be1c8bd1695af1ff5c5609ee6c58e4effea2b62..a2ba826141ccbcf3a25bbae0c1df00afbda42d79 100644 --- a/auth/manager.go +++ b/auth/manager.go @@ -102,7 +102,7 @@ func (m *Manager) RemoveSpecificConfirmCallback(id *id.ID) { } // Adds a general callback to be used on auth session renegotiations. -func (m *Manager) AddResetCallback(cb interfaces.ResetCallback) { +func (m *Manager) AddResetNotificationCallback(cb interfaces.ResetNotificationCallback) { m.resetCallbacks.AddOverride(cb) } diff --git a/bindings/authenticatedChannels.go b/bindings/authenticatedChannels.go index f52b9e7d6ddf4b0728b4499777cbd6e017632a09..af246b5408736224ec081ae7e45806b25b4a0a60 100644 --- a/bindings/authenticatedChannels.go +++ b/bindings/authenticatedChannels.go @@ -84,7 +84,7 @@ func (c *Client) ResetSession(recipientMarshaled, // RegisterAuthCallbacks registers all callbacks for authenticated channels. // This can only be called once func (c *Client) RegisterAuthCallbacks(request AuthRequestCallback, - confirm AuthConfirmCallback, reset AuthResetCallback) { + confirm AuthConfirmCallback, reset AuthResetNotificationCallback) { requestFunc := func(requestor contact.Contact) { requestorBind := &Contact{c: &requestor} @@ -103,7 +103,7 @@ func (c *Client) RegisterAuthCallbacks(request AuthRequestCallback, c.api.GetAuthRegistrar().AddGeneralConfirmCallback(confirmFunc) c.api.GetAuthRegistrar().AddGeneralRequestCallback(requestFunc) - c.api.GetAuthRegistrar().AddResetCallback(resetFunc) + c.api.GetAuthRegistrar().AddResetNotificationCallback(resetFunc) } // ConfirmAuthenticatedChannel creates an authenticated channel out of a valid diff --git a/bindings/callback.go b/bindings/callback.go index 53ed8f1e7482f09827552a56975c4f4015c5fec9..4ad87c94ae91e1dc5d688900d75d0b404f9a1765 100644 --- a/bindings/callback.go +++ b/bindings/callback.go @@ -62,7 +62,7 @@ type AuthConfirmCallback interface { // AuthRequestCallback notifies the register whenever they receive an auth // request -type AuthResetCallback interface { +type AuthResetNotificationCallback interface { Callback(requestor *Contact) } diff --git a/cmd/root.go b/cmd/root.go index 4427073ab096b3ad070f71db3ed53b0c0b880d07..d7bb3d6f5c65399751fb00a454752cc103c70902 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -525,7 +525,7 @@ func createClient() *api.Client { initLog(logLevel, viper.GetString("log")) jww.INFO.Printf(Version()) - pass := viper.GetString("password") + pass := parsePassword(viper.GetString("password")) storeDir := viper.GetString("session") regCode := viper.GetString("regcode") precannedID := viper.GetUint("sendid") @@ -544,17 +544,17 @@ func createClient() *api.Client { if precannedID != 0 { err = api.NewPrecannedClient(precannedID, - string(ndfJSON), storeDir, []byte(pass)) + string(ndfJSON), storeDir, pass) } else if protoUserPath != "" { protoUserJson, err := utils.ReadFile(protoUserPath) if err != nil { jww.FATAL.Panicf("%v", err) } err = api.NewProtoClient_Unsafe(string(ndfJSON), storeDir, - []byte(pass), protoUserJson) + pass, protoUserJson) } else if userIDprefix != "" { err = api.NewVanityClient(string(ndfJSON), storeDir, - []byte(pass), regCode, userIDprefix) + pass, regCode, userIDprefix) } else if backupPath != "" { b, backupFile := loadBackup(backupPath, string(backupPass)) @@ -573,7 +573,7 @@ func createClient() *api.Client { // Construct client from backup data backupIdList, _, err := api.NewClientFromBackup(string(ndfJSON), storeDir, - []byte(pass), backupPass, backupFile) + pass, backupPass, backupFile) backupIdListPath := viper.GetString("backupIdList") if backupIdListPath != "" { @@ -593,7 +593,7 @@ func createClient() *api.Client { } else { err = api.NewClient(string(ndfJSON), storeDir, - []byte(pass), regCode) + pass, regCode) } if err != nil { @@ -612,7 +612,7 @@ func createClient() *api.Client { netParams.ForceMessagePickupRetry = viper.GetBool("forceMessagePickupRetry") netParams.VerboseRoundTracking = viper.GetBool("verboseRoundTracking") - client, err := api.OpenClient(storeDir, []byte(pass), netParams) + client, err := api.OpenClient(storeDir, pass, netParams) if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -622,7 +622,7 @@ func createClient() *api.Client { func initClient() *api.Client { createClient() - pass := viper.GetString("password") + pass := parsePassword(viper.GetString("password")) storeDir := viper.GetString("session") jww.DEBUG.Printf("sessionDur: %v", storeDir) netParams := params.GetDefaultNetwork() @@ -642,7 +642,7 @@ func initClient() *api.Client { netParams.VerboseRoundTracking = viper.GetBool("verboseRoundTracking") // load the client - client, err := api.Login(storeDir, []byte(pass), netParams) + client, err := api.Login(storeDir, pass, netParams) if err != nil { jww.FATAL.Panicf("%+v", err) } @@ -853,6 +853,16 @@ func getPrecanID(recipientID *id.ID) uint { return uint(recipientID.Bytes()[7]) } +func parsePassword(pwStr string) []byte { + if strings.HasPrefix(pwStr, "0x") { + return getPWFromHexString(pwStr[2:]) + } else if strings.HasPrefix(pwStr, "b64:") { + return getPWFromb64String(pwStr[4:]) + } else { + return []byte(pwStr) + } +} + func parseRecipient(idStr string) (*id.ID, bool) { if idStr == "0" { return nil, false @@ -905,6 +915,23 @@ func getUIDFromb64String(idStr string) *id.ID { return ID } +func getPWFromHexString(pwStr string) []byte { + pwBytes, err := hex.DecodeString(fmt.Sprintf("%0*d%s", + 66-len(pwStr), 0, pwStr)) + if err != nil { + jww.FATAL.Panicf("%+v", err) + } + return pwBytes +} + +func getPWFromb64String(pwStr string) []byte { + pwBytes, err := base64.StdEncoding.DecodeString(pwStr) + if err != nil { + jww.FATAL.Panicf("%+v", err) + } + return pwBytes +} + func getUIDFromString(idStr string) *id.ID { idInt, err := strconv.Atoi(idStr) if err != nil { diff --git a/interfaces/auth.go b/interfaces/auth.go index 28443cf800727ad20cd9ff9586dcb5945e0a87e5..d82625c723150b433959d22c83241c909fb3781e 100644 --- a/interfaces/auth.go +++ b/interfaces/auth.go @@ -14,7 +14,7 @@ import ( type RequestCallback func(requestor contact.Contact) type ConfirmCallback func(partner contact.Contact) -type ResetCallback func(partner contact.Contact) +type ResetNotificationCallback func(partner contact.Contact) type Auth interface { // Adds a general callback to be used on auth requests. This will be preempted @@ -43,8 +43,8 @@ type Auth interface { AddSpecificConfirmCallback(id *id.ID, cb ConfirmCallback) // Removes a specific callback to be used on auth confirm. RemoveSpecificConfirmCallback(id *id.ID) - // Add a callback to receive session renegotiations - AddResetCallback(cb ResetCallback) + // Add a callback to receive session renegotiation notifications + AddResetNotificationCallback(cb ResetNotificationCallback) //Replays all pending received requests over tha callbacks ReplayRequests() }