Skip to content
Snippets Groups Projects
Commit afc2d64a authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

add unsafe channel creation flag and associated logic

parent 5ee6cd8f
No related branches found
No related tags found
No related merge requests found
...@@ -162,25 +162,9 @@ var rootCmd = &cobra.Command{ ...@@ -162,25 +162,9 @@ var rootCmd = &cobra.Command{
// Send unsafe messages or not? // Send unsafe messages or not?
unsafe := viper.GetBool("unsafe") unsafe := viper.GetBool("unsafe")
if isPrecanPartner && !unsafe { if !unsafe {
jww.WARN.Printf("Precanned user id detected: %s", addAuthenticatedChannel(client, recipientID,
recipientID) isPrecanPartner)
preUsr, err := client.MakePrecannedAuthenticatedChannel(
getPrecanID(recipientID))
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
// Sanity check, make sure user id's haven't changed
preBytes := preUsr.ID.Bytes()
idBytes := recipientID.Bytes()
for i := 0; i < len(preBytes); i++ {
if idBytes[i] != preBytes[i] {
jww.FATAL.Panicf("no id match: %v %v",
preBytes, idBytes)
}
}
} else if !unsafe {
jww.FATAL.Panicf("e2e unimplemented")
} }
msg := message.Send{ msg := message.Send{
...@@ -237,6 +221,40 @@ var rootCmd = &cobra.Command{ ...@@ -237,6 +221,40 @@ var rootCmd = &cobra.Command{
}, },
} }
func addAuthenticatedChannel(client *api.Client, recipientID *id.ID,
isPrecanPartner bool) {
var allowed bool
if viper.GetBool("unsafe-channel-creation") {
allowed = true
} else {
allowed = askToCreateChannel(recipientID)
}
if !allowed {
jww.FATAL.Panicf("User did not allow channel creation!")
}
if isPrecanPartner {
jww.WARN.Printf("Precanned user id detected: %s",
recipientID)
preUsr, err := client.MakePrecannedAuthenticatedChannel(
getPrecanID(recipientID))
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
// Sanity check, make sure user id's haven't changed
preBytes := preUsr.ID.Bytes()
idBytes := recipientID.Bytes()
for i := 0; i < len(preBytes); i++ {
if idBytes[i] != preBytes[i] {
jww.FATAL.Panicf("no id match: %v %v",
preBytes, idBytes)
}
}
} else {
jww.FATAL.Panicf("e2e unimplemented")
}
}
func waitUntilConnected(connected chan bool) { func waitUntilConnected(connected chan bool) {
waitTimeout := time.Duration(viper.GetUint("waitTimeout")) waitTimeout := time.Duration(viper.GetUint("waitTimeout"))
timeoutTimer := time.NewTimer(waitTimeout * time.Second) timeoutTimer := time.NewTimer(waitTimeout * time.Second)
...@@ -383,6 +401,22 @@ func isValidUser(usr []byte) (bool, *id.ID) { ...@@ -383,6 +401,22 @@ func isValidUser(usr []byte) (bool, *id.ID) {
return false, nil return false, nil
} }
func askToCreateChannel(recipientID *id.ID) bool {
for {
fmt.Printf("This is the first time you have messaged %v, " +
"are you sure? (yes/no) ")
var input string
fmt.Scanln(&input)
if input == "yes" {
return true
}
if input == "no" {
return false
}
fmt.Printf("Please answer 'yes' or 'no'\n")
}
}
// init is the initialization function for Cobra which defines commands // init is the initialization function for Cobra which defines commands
// and flags. // and flags.
func init() { func init() {
...@@ -451,6 +485,13 @@ func init() { ...@@ -451,6 +485,13 @@ func init() {
"Send raw, unsafe messages without e2e encryption.") "Send raw, unsafe messages without e2e encryption.")
viper.BindPFlag("unsafe", rootCmd.Flags().Lookup("unsafe")) viper.BindPFlag("unsafe", rootCmd.Flags().Lookup("unsafe"))
rootCmd.Flags().BoolP("unsafe-channel-creation", "", false,
"Turns off the user identity authenticated channel check, "+
"which prompts the user to answer yes or no "+
"to approve authenticated channels")
viper.BindPFlag("unsafe-channel-creation",
rootCmd.Flags().Lookup("unsafe-channel-creation"))
// 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(&notificationToken, "nbRegistration", "x", "", // rootCmd.Flags().StringVarP(&notificationToken, "nbRegistration", "x", "",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment