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 ( ...@@ -27,6 +27,7 @@ import (
type authCallbacks struct { type authCallbacks struct {
autoConfirm bool autoConfirm bool
confCh chan *id.ID confCh chan *id.ID
reqCh chan *id.ID
params xxdk.E2EParams params xxdk.E2EParams
} }
...@@ -34,6 +35,7 @@ func makeAuthCallbacks(autoConfirm bool, params xxdk.E2EParams) *authCallbacks { ...@@ -34,6 +35,7 @@ func makeAuthCallbacks(autoConfirm bool, params xxdk.E2EParams) *authCallbacks {
return &authCallbacks{ return &authCallbacks{
autoConfirm: autoConfirm, autoConfirm: autoConfirm,
confCh: make(chan *id.ID, 10), confCh: make(chan *id.ID, 10),
reqCh: make(chan *id.ID, 10),
params: params, params: params,
} }
} }
...@@ -44,7 +46,7 @@ func (a *authCallbacks) Request(requestor contact.Contact, ...@@ -44,7 +46,7 @@ func (a *authCallbacks) Request(requestor contact.Contact,
msg := fmt.Sprintf("Authentication channel request from: %s\n", msg := fmt.Sprintf("Authentication channel request from: %s\n",
requestor.ID) requestor.ID)
jww.INFO.Printf(msg) jww.INFO.Printf(msg)
fmt.Printf(msg) fmt.Print(msg)
if a.autoConfirm { if a.autoConfirm {
jww.INFO.Printf("Channel Request: %s", jww.INFO.Printf("Channel Request: %s",
requestor.ID) requestor.ID)
...@@ -55,8 +57,9 @@ func (a *authCallbacks) Request(requestor contact.Contact, ...@@ -55,8 +57,9 @@ func (a *authCallbacks) Request(requestor contact.Contact,
} }
a.confCh <- requestor.ID a.confCh <- requestor.ID
} else {
a.reqCh <- requestor.ID
} }
} }
func (a *authCallbacks) Confirm(requestor contact.Contact, func (a *authCallbacks) Confirm(requestor contact.Contact,
...@@ -72,7 +75,7 @@ func (a *authCallbacks) Reset(requestor contact.Contact, ...@@ -72,7 +75,7 @@ func (a *authCallbacks) Reset(requestor contact.Contact,
msg := fmt.Sprintf("Authentication channel reset from: %s\n", msg := fmt.Sprintf("Authentication channel reset from: %s\n",
requestor.ID) requestor.ID)
jww.INFO.Printf(msg) jww.INFO.Printf(msg)
fmt.Printf(msg) fmt.Print(msg)
} }
func registerMessageListener(user *xxdk.E2e) chan receive.Message { func registerMessageListener(user *xxdk.E2e) chan receive.Message {
......
...@@ -14,11 +14,12 @@ import ( ...@@ -14,11 +14,12 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
cryptoE2e "gitlab.com/elixxir/crypto/e2e"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
cryptoE2e "gitlab.com/elixxir/crypto/e2e"
"github.com/pkg/profile" "github.com/pkg/profile"
"strconv" "strconv"
...@@ -76,8 +77,13 @@ var rootCmd = &cobra.Command{ ...@@ -76,8 +77,13 @@ var rootCmd = &cobra.Command{
cmixParams, e2eParams := initParams() cmixParams, e2eParams := initParams()
authCbs := makeAuthCallbacks( autoConfirm := viper.GetBool(unsafeChannelCreationFlag)
viper.GetBool(unsafeChannelCreationFlag), e2eParams) acceptChannels := viper.GetBool(acceptChannelFlag)
if acceptChannels {
autoConfirm = false
}
authCbs := makeAuthCallbacks(autoConfirm, e2eParams)
user := initE2e(cmixParams, e2eParams, authCbs) user := initE2e(cmixParams, e2eParams, authCbs)
jww.INFO.Printf("Client Initialized...") jww.INFO.Printf("Client Initialized...")
...@@ -96,12 +102,14 @@ var rootCmd = &cobra.Command{ ...@@ -96,12 +102,14 @@ var rootCmd = &cobra.Command{
recipientContact = readContact(destFile) recipientContact = readContact(destFile)
recipientID = recipientContact.ID recipientID = recipientContact.ID
} else if destId == "0" || sendId == destId { } 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 recipientID = receptionIdentity.ID
recipientContact = receptionIdentity.GetContact() recipientContact = receptionIdentity.GetContact()
} else { } else {
recipientID = parseRecipient(destId) recipientID = parseRecipient(destId)
jww.INFO.Printf("destId: %v\nrecipientId: %v", destId, recipientID) jww.INFO.Printf("destId: %v\nrecipientId: %v", destId,
recipientID)
} }
isPrecanPartner := isPrecanID(recipientID) isPrecanPartner := isPrecanID(recipientID)
...@@ -151,11 +159,42 @@ var rootCmd = &cobra.Command{ ...@@ -151,11 +159,42 @@ var rootCmd = &cobra.Command{
// Send Messages // Send Messages
msgBody := viper.GetString(messageFlag) msgBody := viper.GetString(messageFlag)
hasMsgs := true
if msgBody == "" {
hasMsgs = false
}
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
// Accept auth request for this recipient // Accept auth request for this recipient
waitSecs := viper.GetUint(authTimeoutFlag)
authConfirmed := false 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 // Verify that the confirmation message makes it to the
// original sender // original sender
if viper.GetBool(verifySendFlag) { if viper.GetBool(verifySendFlag) {
...@@ -171,16 +210,6 @@ var rootCmd = &cobra.Command{ ...@@ -171,16 +210,6 @@ var rootCmd = &cobra.Command{
authConfirmed = true 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? // Send unsafe messages or not?
unsafe := viper.GetBool(unsafeFlag) unsafe := viper.GetBool(unsafeFlag)
sendAuthReq := viper.GetBool(sendAuthRequestFlag) sendAuthReq := viper.GetBool(sendAuthRequestFlag)
...@@ -200,7 +229,7 @@ var rootCmd = &cobra.Command{ ...@@ -200,7 +229,7 @@ var rootCmd = &cobra.Command{
authConfirmed = false authConfirmed = false
} }
if !unsafe && !authConfirmed { if !unsafe && !authConfirmed && hasMsgs {
// Signal for authConfirm callback in a separate thread // Signal for authConfirm callback in a separate thread
go func() { go func() {
for { for {
...@@ -216,7 +245,6 @@ var rootCmd = &cobra.Command{ ...@@ -216,7 +245,6 @@ var rootCmd = &cobra.Command{
scnt := uint(0) scnt := uint(0)
// Wait until authConfirmed // Wait until authConfirmed
waitSecs := viper.GetUint(authTimeoutFlag)
for !authConfirmed && scnt < waitSecs { for !authConfirmed && scnt < waitSecs {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
scnt++ scnt++
...@@ -278,6 +306,13 @@ var rootCmd = &cobra.Command{ ...@@ -278,6 +306,13 @@ var rootCmd = &cobra.Command{
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
sendCnt := int(viper.GetUint(sendCountFlag)) 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) wg.Add(sendCnt)
go func() { go func() {
sendDelay := time.Duration(viper.GetUint(sendDelayFlag)) sendDelay := time.Duration(viper.GetUint(sendDelayFlag))
...@@ -324,7 +359,6 @@ var rootCmd = &cobra.Command{ ...@@ -324,7 +359,6 @@ var rootCmd = &cobra.Command{
// TODO: Actually check for how many messages we've received // TODO: Actually check for how many messages we've received
expectedCnt := viper.GetUint(receiveCountFlag) expectedCnt := viper.GetUint(receiveCountFlag)
receiveCnt := uint(0) receiveCnt := uint(0)
waitSecs := viper.GetUint(waitTimeoutFlag)
waitTimeout := time.Duration(waitSecs) * time.Second waitTimeout := time.Duration(waitSecs) * time.Second
done := false done := false
...@@ -556,7 +590,7 @@ func addAuthenticatedChannel(user *xxdk.E2e, recipientID *id.ID, ...@@ -556,7 +590,7 @@ func addAuthenticatedChannel(user *xxdk.E2e, recipientID *id.ID,
msg := fmt.Sprintf("Adding authenticated channel for: %s\n", msg := fmt.Sprintf("Adding authenticated channel for: %s\n",
recipientID) recipientID)
jww.INFO.Printf(msg) jww.INFO.Printf(msg)
fmt.Printf(msg) fmt.Print(msg)
recipientContact := recipient recipientContact := recipient
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment