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

Merge branch 'hotfix/unsafe_send_to_self' into 'release'

Modify default behavior to make --accept-channel work as expected

See merge request !366
parents a9465e95 263342a0
No related branches found
No related tags found
2 merge requests!510Release,!366Modify default behavior to make --accept-channel work as expected
......@@ -27,6 +27,7 @@ import (
type authCallbacks struct {
autoConfirm bool
confCh chan *id.ID
reqCh chan *id.ID
params xxdk.E2EParams
}
......@@ -34,6 +35,7 @@ func makeAuthCallbacks(autoConfirm bool, params xxdk.E2EParams) *authCallbacks {
return &authCallbacks{
autoConfirm: autoConfirm,
confCh: make(chan *id.ID, 10),
reqCh: make(chan *id.ID, 10),
params: params,
}
}
......@@ -44,7 +46,7 @@ func (a *authCallbacks) Request(requestor contact.Contact,
msg := fmt.Sprintf("Authentication channel request from: %s\n",
requestor.ID)
jww.INFO.Printf(msg)
fmt.Printf(msg)
fmt.Print(msg)
if a.autoConfirm {
jww.INFO.Printf("Channel Request: %s",
requestor.ID)
......@@ -55,8 +57,9 @@ func (a *authCallbacks) Request(requestor contact.Contact,
}
a.confCh <- requestor.ID
} else {
a.reqCh <- requestor.ID
}
}
func (a *authCallbacks) Confirm(requestor contact.Contact,
......@@ -72,7 +75,7 @@ func (a *authCallbacks) Reset(requestor contact.Contact,
msg := fmt.Sprintf("Authentication channel reset from: %s\n",
requestor.ID)
jww.INFO.Printf(msg)
fmt.Printf(msg)
fmt.Print(msg)
}
func registerMessageListener(user *xxdk.E2e) chan receive.Message {
......
......@@ -14,11 +14,12 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
cryptoE2e "gitlab.com/elixxir/crypto/e2e"
"io/ioutil"
"log"
"os"
cryptoE2e "gitlab.com/elixxir/crypto/e2e"
"github.com/pkg/profile"
"strconv"
......@@ -76,8 +77,13 @@ var rootCmd = &cobra.Command{
cmixParams, e2eParams := initParams()
authCbs := makeAuthCallbacks(
viper.GetBool(unsafeChannelCreationFlag), e2eParams)
autoConfirm := viper.GetBool(unsafeChannelCreationFlag)
acceptChannels := viper.GetBool(acceptChannelFlag)
if acceptChannels {
autoConfirm = false
}
authCbs := makeAuthCallbacks(autoConfirm, e2eParams)
user := initE2e(cmixParams, e2eParams, authCbs)
jww.INFO.Printf("Client Initialized...")
......@@ -96,12 +102,14 @@ var rootCmd = &cobra.Command{
recipientContact = readContact(destFile)
recipientID = recipientContact.ID
} else if destId == "0" || sendId == destId {
jww.INFO.Printf("Sending message to self")
jww.INFO.Printf("Sending message to self, " +
"this will timeout unless authrequest is sent")
recipientID = receptionIdentity.ID
recipientContact = receptionIdentity.GetContact()
} else {
recipientID = parseRecipient(destId)
jww.INFO.Printf("destId: %v\nrecipientId: %v", destId, recipientID)
jww.INFO.Printf("destId: %v\nrecipientId: %v", destId,
recipientID)
}
isPrecanPartner := isPrecanID(recipientID)
......@@ -151,11 +159,42 @@ var rootCmd = &cobra.Command{
// Send Messages
msgBody := viper.GetString(messageFlag)
hasMsgs := true
if msgBody == "" {
hasMsgs = false
}
time.Sleep(10 * time.Second)
// Accept auth request for this recipient
waitSecs := viper.GetUint(authTimeoutFlag)
authConfirmed := false
if viper.GetBool(acceptChannelFlag) {
jww.INFO.Printf("Preexisting E2e partners: %+v", user.GetE2E().GetAllPartnerIDs())
if user.GetE2E().HasAuthenticatedChannel(recipientID) {
jww.INFO.Printf("Authenticated channel already in "+
"place for %s", recipientID)
authConfirmed = true
} else {
jww.INFO.Printf("No authenticated channel in "+
"place for %s", recipientID)
}
if acceptChannels && !authConfirmed {
for reqDone := false; !reqDone; {
select {
case reqID := <-authCbs.reqCh:
if recipientID.Cmp(reqID) {
reqDone = true
} else {
fmt.Printf(
"unexpected request:"+
" %s", reqID)
}
case <-time.After(time.Duration(waitSecs) *
time.Second):
fmt.Print("timed out on auth request")
reqDone = true
}
}
// Verify that the confirmation message makes it to the
// original sender
if viper.GetBool(verifySendFlag) {
......@@ -171,16 +210,6 @@ var rootCmd = &cobra.Command{
authConfirmed = true
}
jww.INFO.Printf("Preexisting E2e partners: %+v", user.GetE2E().GetAllPartnerIDs())
if user.GetE2E().HasAuthenticatedChannel(recipientID) {
jww.INFO.Printf("Authenticated channel already in "+
"place for %s", recipientID)
authConfirmed = true
} else {
jww.INFO.Printf("No authenticated channel in "+
"place for %s", recipientID)
}
// Send unsafe messages or not?
unsafe := viper.GetBool(unsafeFlag)
sendAuthReq := viper.GetBool(sendAuthRequestFlag)
......@@ -200,7 +229,7 @@ var rootCmd = &cobra.Command{
authConfirmed = false
}
if !unsafe && !authConfirmed {
if !unsafe && !authConfirmed && hasMsgs {
// Signal for authConfirm callback in a separate thread
go func() {
for {
......@@ -216,7 +245,6 @@ var rootCmd = &cobra.Command{
scnt := uint(0)
// Wait until authConfirmed
waitSecs := viper.GetUint(authTimeoutFlag)
for !authConfirmed && scnt < waitSecs {
time.Sleep(1 * time.Second)
scnt++
......@@ -278,6 +306,13 @@ var rootCmd = &cobra.Command{
wg := &sync.WaitGroup{}
sendCnt := int(viper.GetUint(sendCountFlag))
if !hasMsgs && sendCnt != 0 {
msg := "No message to send, please set your message" +
"or set sendCount to 0 to suppress this warning"
jww.WARN.Printf(msg)
fmt.Print(msg)
sendCnt = 0
}
wg.Add(sendCnt)
go func() {
sendDelay := time.Duration(viper.GetUint(sendDelayFlag))
......@@ -324,7 +359,6 @@ var rootCmd = &cobra.Command{
// TODO: Actually check for how many messages we've received
expectedCnt := viper.GetUint(receiveCountFlag)
receiveCnt := uint(0)
waitSecs := viper.GetUint(waitTimeoutFlag)
waitTimeout := time.Duration(waitSecs) * time.Second
done := false
......@@ -556,7 +590,7 @@ func addAuthenticatedChannel(user *xxdk.E2e, recipientID *id.ID,
msg := fmt.Sprintf("Adding authenticated channel for: %s\n",
recipientID)
jww.INFO.Printf(msg)
fmt.Printf(msg)
fmt.Print(msg)
recipientContact := recipient
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment