Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
a4e35b6b
Commit
a4e35b6b
authored
Apr 2, 2021
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Update client to wait for auth channel before sending messages, or error out loudly
parent
ef72f4a4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/root.go
+90
-62
90 additions, 62 deletions
cmd/root.go
with
90 additions
and
62 deletions
cmd/root.go
+
90
−
62
View file @
a4e35b6b
...
@@ -52,6 +52,24 @@ var rootCmd = &cobra.Command{
...
@@ -52,6 +52,24 @@ var rootCmd = &cobra.Command{
jww
.
INFO
.
Printf
(
"User: %s"
,
user
.
ReceptionID
)
jww
.
INFO
.
Printf
(
"User: %s"
,
user
.
ReceptionID
)
writeContact
(
user
.
GetContact
())
writeContact
(
user
.
GetContact
())
// Get Recipient and/or set it to myself
isPrecanPartner
:=
false
recipientContact
:=
readContact
()
recipientID
:=
recipientContact
.
ID
// Try to get recipientID from destid
if
recipientID
==
nil
{
recipientID
,
isPrecanPartner
=
parseRecipient
(
viper
.
GetString
(
"destid"
))
}
// Set it to myself
if
recipientID
==
nil
{
jww
.
INFO
.
Printf
(
"sending message to self"
)
recipientID
=
user
.
ReceptionID
recipientContact
=
user
.
GetContact
()
}
// Set up reception handler
// Set up reception handler
swboard
:=
client
.
GetSwitchboard
()
swboard
:=
client
.
GetSwitchboard
()
recvCh
:=
make
(
chan
message
.
Receive
,
10000
)
recvCh
:=
make
(
chan
message
.
Receive
,
10000
)
...
@@ -65,12 +83,12 @@ var rootCmd = &cobra.Command{
...
@@ -65,12 +83,12 @@ var rootCmd = &cobra.Command{
authMgr
.
AddGeneralRequestCallback
(
printChanRequest
)
authMgr
.
AddGeneralRequestCallback
(
printChanRequest
)
// If unsafe channels, add auto-acceptor
// If unsafe channels, add auto-acceptor
num_channels_c
onfirmed
:=
0
authC
onfirmed
:=
false
authMgr
.
AddGeneralConfirmCallback
(
func
(
authMgr
.
AddGeneralConfirmCallback
(
func
(
partner
contact
.
Contact
)
{
partner
contact
.
Contact
)
{
jww
.
INFO
.
Printf
(
"Channel Confirmed: %s"
,
jww
.
INFO
.
Printf
(
"Channel Confirmed: %s"
,
partner
.
ID
)
partner
.
ID
)
num_channels_confirmed
++
authConfirmed
=
recipientID
.
Cmp
(
partner
.
ID
)
})
})
if
viper
.
GetBool
(
"unsafe-channel-creation"
)
{
if
viper
.
GetBool
(
"unsafe-channel-creation"
)
{
authMgr
.
AddGeneralRequestCallback
(
func
(
authMgr
.
AddGeneralRequestCallback
(
func
(
...
@@ -82,7 +100,8 @@ var rootCmd = &cobra.Command{
...
@@ -82,7 +100,8 @@ var rootCmd = &cobra.Command{
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
}
num_channels_confirmed
++
authConfirmed
=
recipientID
.
Cmp
(
requestor
.
ID
)
})
})
}
}
...
@@ -113,39 +132,53 @@ var rootCmd = &cobra.Command{
...
@@ -113,39 +132,53 @@ var rootCmd = &cobra.Command{
// Send Messages
// Send Messages
msgBody
:=
viper
.
GetString
(
"message"
)
msgBody
:=
viper
.
GetString
(
"message"
)
isPrecanPartner
:=
false
recipientContact
:=
readContact
()
recipientID
:=
recipientContact
.
ID
// Try to get recipientID from destid
if
recipientID
==
nil
{
recipientID
,
isPrecanPartner
=
parseRecipient
(
viper
.
GetString
(
"destid"
))
}
// Set it to myself
if
recipientID
==
nil
{
jww
.
INFO
.
Printf
(
"sending message to self"
)
recipientID
=
user
.
ReceptionID
recipientContact
=
user
.
GetContact
()
}
time
.
Sleep
(
10
*
time
.
Second
)
time
.
Sleep
(
10
*
time
.
Second
)
// Accept auth request for this recipient
// Accept auth request for this recipient
if
viper
.
GetBool
(
"accept-channel"
)
{
if
viper
.
GetBool
(
"accept-channel"
)
{
acceptChannel
(
client
,
recipientID
)
acceptChannel
(
client
,
recipientID
)
// Do not wait for channel confirmations if we
// accepted one
authConfirmed
=
true
}
if
client
.
HasAuthenticatedChannel
(
recipientID
)
{
jww
.
INFO
.
Printf
(
"Authenticated channel already in "
+
"place for %s"
,
recipientID
)
authConfirmed
=
true
}
}
// Send unsafe messages or not?
// Send unsafe messages or not?
unsafe
:=
viper
.
GetBool
(
"unsafe"
)
unsafe
:=
viper
.
GetBool
(
"unsafe"
)
assumeAuth
:=
viper
.
GetBool
(
"assume-auth-channel"
)
if
!
unsafe
&&
!
assumeAuth
{
sendAuthReq
:=
viper
.
GetBool
(
"send-auth-request"
)
if
!
unsafe
&&
!
authConfirmed
&&
!
isPrecanPartner
&&
sendAuthReq
{
addAuthenticatedChannel
(
client
,
recipientID
,
addAuthenticatedChannel
(
client
,
recipientID
,
recipientContact
,
isPrecanPartner
)
recipientContact
)
// Do not wait for channel confirmations if we
}
else
if
!
unsafe
&&
!
authConfirmed
&&
isPrecanPartner
{
// tried to add a channel
addPrecanAuthenticatedChannel
(
client
,
num_channels_confirmed
++
recipientID
,
recipientContact
)
authConfirmed
=
true
}
if
!
unsafe
&&
!
authConfirmed
{
jww
.
INFO
.
Printf
(
"Waiting for authentication channel "
+
" confirmation with partner %s"
,
recipientID
)
scnt
:=
uint
(
0
)
waitSecs
:=
viper
.
GetUint
(
"auth-timeout"
)
for
!
authConfirmed
&&
scnt
<
waitSecs
{
time
.
Sleep
(
1
*
time
.
Second
)
scnt
++
}
if
scnt
==
waitSecs
{
jww
.
FATAL
.
Panicf
(
"Could not confirm "
+
"authentication channel for %s, "
+
"waited %d seconds."
,
recipientID
,
waitSecs
)
}
jww
.
INFO
.
Printf
(
"Authentication channel confirmation"
+
" took %d seconds"
,
waitSecs
)
}
}
msg
:=
message
.
Send
{
msg
:=
message
.
Send
{
...
@@ -216,13 +249,6 @@ var rootCmd = &cobra.Command{
...
@@ -216,13 +249,6 @@ var rootCmd = &cobra.Command{
}
}
}
}
fmt
.
Printf
(
"Received %d
\n
"
,
receiveCnt
)
fmt
.
Printf
(
"Received %d
\n
"
,
receiveCnt
)
if
receiveCnt
==
0
&&
sendCnt
==
0
{
scnt
:=
uint
(
0
)
for
num_channels_confirmed
==
0
&&
scnt
<
waitSecs
{
time
.
Sleep
(
1
*
time
.
Second
)
scnt
++
}
}
err
=
client
.
StopNetworkFollower
(
5
*
time
.
Second
)
err
=
client
.
StopNetworkFollower
(
5
*
time
.
Second
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
WARN
.
Printf
(
jww
.
WARN
.
Printf
(
...
@@ -390,14 +416,27 @@ func printChanRequest(requestor contact.Contact, message string) {
...
@@ -390,14 +416,27 @@ func printChanRequest(requestor contact.Contact, message string) {
//fmt.Printf(msg)
//fmt.Printf(msg)
}
}
func
addAuthenticatedChannel
(
client
*
api
.
Client
,
recipientID
*
id
.
ID
,
func
addPrecanAuthenticatedChannel
(
client
*
api
.
Client
,
recipientID
*
id
.
ID
,
recipient
contact
.
Contact
,
isPrecanPartner
bool
)
{
recipient
contact
.
Contact
)
{
if
client
.
HasAuthenticatedChannel
(
recipientID
)
{
jww
.
WARN
.
Printf
(
"Precanned user id detected: %s"
,
recipientID
)
jww
.
INFO
.
Printf
(
"Authenticated channel already in place for %s"
,
preUsr
,
err
:=
client
.
MakePrecannedAuthenticatedChannel
(
recipientID
)
getPrecanID
(
recipientID
))
return
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
)
}
}
}
}
func
addAuthenticatedChannel
(
client
*
api
.
Client
,
recipientID
*
id
.
ID
,
recipient
contact
.
Contact
)
{
var
allowed
bool
var
allowed
bool
if
viper
.
GetBool
(
"unsafe-channel-creation"
)
{
if
viper
.
GetBool
(
"unsafe-channel-creation"
)
{
msg
:=
"unsafe channel creation enabled
\n
"
msg
:=
"unsafe channel creation enabled
\n
"
...
@@ -418,24 +457,7 @@ func addAuthenticatedChannel(client *api.Client, recipientID *id.ID,
...
@@ -418,24 +457,7 @@ func addAuthenticatedChannel(client *api.Client, recipientID *id.ID,
recipientContact
:=
recipient
recipientContact
:=
recipient
if
isPrecanPartner
{
if
recipientContact
.
ID
!=
nil
&&
recipientContact
.
DhPubKey
!=
nil
{
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
if
recipientContact
.
ID
!=
nil
&&
recipientContact
.
DhPubKey
!=
nil
{
me
:=
client
.
GetUser
()
.
GetContact
()
me
:=
client
.
GetUser
()
.
GetContact
()
jww
.
INFO
.
Printf
(
"Requesting auth channel from: %s"
,
jww
.
INFO
.
Printf
(
"Requesting auth channel from: %s"
,
recipientID
)
recipientID
)
...
@@ -707,16 +729,22 @@ func init() {
...
@@ -707,16 +729,22 @@ func init() {
viper
.
BindPFlag
(
"unsafe-channel-creation"
,
viper
.
BindPFlag
(
"unsafe-channel-creation"
,
rootCmd
.
Flags
()
.
Lookup
(
"unsafe-channel-creation"
))
rootCmd
.
Flags
()
.
Lookup
(
"unsafe-channel-creation"
))
rootCmd
.
Flags
()
.
BoolP
(
"assume-auth-channel"
,
""
,
false
,
"Do not check for an authentication channel for this user"
)
viper
.
BindPFlag
(
"assume-auth-channel"
,
rootCmd
.
Flags
()
.
Lookup
(
"assume-auth-channel"
))
rootCmd
.
Flags
()
.
BoolP
(
"accept-channel"
,
""
,
false
,
rootCmd
.
Flags
()
.
BoolP
(
"accept-channel"
,
""
,
false
,
"Accept the channel request for the corresponding recipient ID"
)
"Accept the channel request for the corresponding recipient ID"
)
viper
.
BindPFlag
(
"accept-channel"
,
viper
.
BindPFlag
(
"accept-channel"
,
rootCmd
.
Flags
()
.
Lookup
(
"accept-channel"
))
rootCmd
.
Flags
()
.
Lookup
(
"accept-channel"
))
rootCmd
.
Flags
()
.
BoolP
(
"send-auth-request"
,
""
,
false
,
"Send an auth request to the specified destination and wait"
+
"for confirmation"
)
viper
.
BindPFlag
(
"send-auth-request"
,
rootCmd
.
Flags
()
.
Lookup
(
"send-auth-request"
))
rootCmd
.
Flags
()
.
UintP
(
"auth-timeout"
,
""
,
120
,
"The number of seconds to wait for an authentication channel"
+
"to confirm"
)
viper
.
BindPFlag
(
"auth-timeout"
,
rootCmd
.
Flags
()
.
Lookup
(
"auth-timeout"
))
rootCmd
.
Flags
()
.
BoolP
(
"forceHistoricalRounds"
,
""
,
false
,
rootCmd
.
Flags
()
.
BoolP
(
"forceHistoricalRounds"
,
""
,
false
,
"Force all rounds to be sent to historical round retrieval"
)
"Force all rounds to be sent to historical round retrieval"
)
viper
.
BindPFlag
(
"forceHistoricalRounds"
,
viper
.
BindPFlag
(
"forceHistoricalRounds"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment