diff --git a/cmd/broadcast.go b/cmd/broadcast.go index 5d98893bd533444b459563bc22c7ed4790a67784..feef96ad5a0da677faba41f2ecc4e12e56a7f762 100644 --- a/cmd/broadcast.go +++ b/cmd/broadcast.go @@ -25,7 +25,9 @@ var broadcastCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // Write user contact to file user := client.GetReceptionIdentity() diff --git a/cmd/dumpRounds.go b/cmd/dumpRounds.go index 401d894ad12dc1003798849d970c7b287c75425a..4aa2f7ee8e96ff40a4708ba74f6193e199c6844c 100644 --- a/cmd/dumpRounds.go +++ b/cmd/dumpRounds.go @@ -11,6 +11,7 @@ package cmd import ( "encoding/base64" "fmt" + "github.com/spf13/viper" "strconv" "time" @@ -32,7 +33,9 @@ var dumpRoundsCmd = &cobra.Command{ roundIDs := parseRoundIDs(args) cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) err := client.StartNetworkFollower(5 * time.Second) if err != nil { jww.FATAL.Panicf("%+v", err) diff --git a/cmd/fileTransfer.go b/cmd/fileTransfer.go index 20e8968bf9e4e2ef69556ad7cd1459984c07bee9..f9cdc7be85e7e50012b8c04e2bc2ec4b43a18e0c 100644 --- a/cmd/fileTransfer.go +++ b/cmd/fileTransfer.go @@ -36,7 +36,9 @@ var ftCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // Print user's reception ID and save contact file user := client.GetReceptionIdentity() diff --git a/cmd/group.go b/cmd/group.go index 8564ded98edc282e180df484d394a136455cb1ac..ba15c6d08c5c2cb609563fb795c8dcfd54120898 100644 --- a/cmd/group.go +++ b/cmd/group.go @@ -35,7 +35,9 @@ var groupCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // Print user's reception ID user := client.GetReceptionIdentity() diff --git a/cmd/root.go b/cmd/root.go index ba5e285ac55aed54ce0dc1480dacc807fdb7a7ec..cbe4a562ef3de96791e04a383b73a7a4d3acb205 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -165,8 +165,6 @@ EnretBzQkeKeBwoB2u6NTiOmUjk= // Key used for storing xxdk.ReceptionIdentity objects const identityStorageKey = "identityStorageKey" -var authCbs *authCallbacks - // Execute adds all child commands to the root command and sets flags // appropriately. This is called by main.main(). It only needs to // happen once to the rootCmd. @@ -194,7 +192,9 @@ var rootCmd = &cobra.Command{ cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) jww.INFO.Printf("Client Initialized...") @@ -572,7 +572,8 @@ func initParams() (xxdk.CMIXParams, xxdk.E2EParams) { } // initE2e returns a fully-formed xxdk.E2e object -func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) *xxdk.E2e { +func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, + callbacks *authCallbacks) *xxdk.E2e { initLog(viper.GetUint("logLevel"), viper.GetString("log")) jww.INFO.Printf(Version()) @@ -588,22 +589,18 @@ func initE2e(cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) *xxdk.E2e { forceLegacy := viper.GetBool("force-legacy") jww.DEBUG.Printf("sessionDir: %v", storeDir) - // TODO: This probably shouldn't be initialized globally. - authCbs = makeAuthCallbacks( - viper.GetBool("unsafe-channel-creation"), e2eParams) - // Initialize the client of the proper type var messenger *xxdk.E2e if precanId != 0 { - messenger = loadOrInitPrecan(precanId, storePassword, storeDir, cmixParams, e2eParams, authCbs) + messenger = loadOrInitPrecan(precanId, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else if protoUserPath != "" { - messenger = loadOrInitProto(protoUserPath, storePassword, storeDir, cmixParams, e2eParams, authCbs) + messenger = loadOrInitProto(protoUserPath, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else if userIdPrefix != "" { - messenger = loadOrInitVanity(storePassword, storeDir, regCode, userIdPrefix, cmixParams, e2eParams, authCbs) + messenger = loadOrInitVanity(storePassword, storeDir, regCode, userIdPrefix, cmixParams, e2eParams, callbacks) } else if backupPath != "" { - messenger = loadOrInitBackup(backupPath, backupPass, storePassword, storeDir, cmixParams, e2eParams, authCbs) + messenger = loadOrInitBackup(backupPath, backupPass, storePassword, storeDir, cmixParams, e2eParams, callbacks) } else { - messenger = loadOrInitMessenger(forceLegacy, storePassword, storeDir, regCode, cmixParams, e2eParams, authCbs) + messenger = loadOrInitMessenger(forceLegacy, storePassword, storeDir, regCode, cmixParams, e2eParams, callbacks) } // Handle protoUser output diff --git a/cmd/single.go b/cmd/single.go index 6a7e99575ff163f03c82bb2cc9799fa884e8775e..849c747e6ee63ffcf94ac7639674ddb4a88d2a47 100644 --- a/cmd/single.go +++ b/cmd/single.go @@ -34,7 +34,9 @@ var singleCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // Write user contact to file user := client.GetReceptionIdentity() diff --git a/cmd/ud.go b/cmd/ud.go index d49b3d79507d30bc4f4e1469c42977549fee8020..17a6c7466fc372bb3b86b989ddc1153f93aace3f 100644 --- a/cmd/ud.go +++ b/cmd/ud.go @@ -35,7 +35,9 @@ var udCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmixParams, e2eParams := initParams() - client := initE2e(cmixParams, e2eParams) + authCbs := makeAuthCallbacks( + viper.GetBool("unsafe-channel-creation"), e2eParams) + client := initE2e(cmixParams, e2eParams, authCbs) // get user and save contact to file user := client.GetReceptionIdentity()