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
75d96a8e
Commit
75d96a8e
authored
Nov 6, 2020
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Add authenticated channel support to CLI
parent
83d5c7af
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/root.go
+86
-9
86 additions, 9 deletions
cmd/root.go
interfaces/user/user.go
+2
-2
2 additions, 2 deletions
interfaces/user/user.go
with
88 additions
and
11 deletions
cmd/root.go
+
86
−
9
View file @
75d96a8e
...
...
@@ -16,6 +16,7 @@ import (
jww
"github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/client/switchboard"
...
...
@@ -145,6 +146,23 @@ var rootCmd = &cobra.Command{
switchboard
.
AnyUser
(),
message
.
Text
,
recvCh
)
jww
.
INFO
.
Printf
(
"Message ListenerID: %v"
,
listenerID
)
// Set up auth request handler, which simply prints the
// user id of the requestor.
authMgr
:=
client
.
GetAuthRegistrar
()
authMgr
.
AddGeneralRequestCallback
(
printChanRequest
)
// If unsafe channels, add auto-acceptor
if
viper
.
GetBool
(
"unsafe-channel-creation"
)
{
authMgr
.
AddGeneralRequestCallback
(
func
(
requestor
contact
.
Contact
,
message
string
)
{
err
:=
client
.
ConfirmAuthenticatedChannel
(
requestor
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
})
}
err
=
client
.
StartNetworkFollower
()
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
...
...
@@ -159,19 +177,35 @@ var rootCmd = &cobra.Command{
msgBody
:=
viper
.
GetString
(
"message"
)
recipientID
,
isPrecanPartner
:=
parseRecipient
(
viper
.
GetString
(
"destid"
))
if
recipientID
==
nil
{
jww
.
INFO
.
Printf
(
"sending message to self"
)
recipientID
=
user
.
ID
}
// Accept auth requests then exit
acceptChan
:=
viper
.
GetString
(
"accept-channel"
)
if
acceptChan
!=
""
{
recipientContact
,
err
:=
(
client
.
GetAuthenticatedChannelRequest
(
recipientID
))
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
err
=
client
.
ConfirmAuthenticatedChannel
(
recipientContact
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
return
}
// Send unsafe messages or not?
unsafe
:=
viper
.
GetBool
(
"unsafe"
)
if
!
unsafe
{
addAuthenticatedChannel
(
client
,
recipientID
,
isPrecanPartner
)
}
if
recipientID
==
nil
{
jww
.
INFO
.
Printf
(
"sending message to self"
)
recipientID
=
user
.
ID
}
msg
:=
message
.
Send
{
Recipient
:
recipientID
,
Payload
:
[]
byte
(
msgBody
),
...
...
@@ -226,6 +260,16 @@ var rootCmd = &cobra.Command{
},
}
func
printChanRequest
(
requestor
contact
.
Contact
,
message
string
)
{
msg
:=
fmt
.
Sprintf
(
"Authentication channel request from: %s
\n
"
,
requestor
.
ID
)
jww
.
INFO
.
Printf
(
msg
)
fmt
.
Printf
(
msg
)
msg
=
fmt
.
Sprintf
(
"Authentication channel request message: %s"
,
message
)
jww
.
INFO
.
Printf
(
msg
)
fmt
.
Printf
(
msg
)
}
func
addAuthenticatedChannel
(
client
*
api
.
Client
,
recipientID
*
id
.
ID
,
isPrecanPartner
bool
)
{
if
client
.
HasAuthenticatedChannel
(
recipientID
)
{
...
...
@@ -247,6 +291,18 @@ func addAuthenticatedChannel(client *api.Client, recipientID *id.ID,
jww
.
FATAL
.
Panicf
(
"User did not allow channel creation!"
)
}
recipientContact
,
err
:=
client
.
GetAuthenticatedChannelRequest
(
recipientID
)
if
err
==
nil
{
jww
.
INFO
.
Printf
(
"Accepting existing channel request for %s"
,
recipientID
)
err
:=
client
.
ConfirmAuthenticatedChannel
(
recipientContact
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
return
}
msg
:=
fmt
.
Sprintf
(
"Adding authenticated channel for: %s
\n
"
,
recipientID
)
jww
.
INFO
.
Printf
(
msg
)
...
...
@@ -270,7 +326,24 @@ func addAuthenticatedChannel(client *api.Client, recipientID *id.ID,
}
}
}
else
{
jww
.
FATAL
.
Panicf
(
"e2e unimplemented"
)
me
:=
client
.
GetUser
()
.
GetContact
()
// Look up contact object via UDB
data
:=
fmt
.
Sprintf
(
"%s"
,
recipientID
)
separator
:=
","
searchTypes
:=
[]
byte
(
"UID"
)
foundUsers
:=
client
.
Search
(
data
,
separator
,
searchTypes
)
if
len
(
foundUsers
)
==
0
{
jww
.
FATAL
.
Panicf
(
"No users found for %s"
,
recipientID
)
}
msg
:=
fmt
.
Sprintf
(
"%s requesting auth channel"
,
me
.
ID
)
for
_
,
them
:=
range
foundUsers
{
jww
.
INFO
.
Printf
(
"Requesting auth channel from: %s"
,
recipientID
)
err
:=
client
.
RequestAuthenticatedChannel
(
them
,
me
,
msg
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"%+v"
,
err
)
}
}
}
}
...
...
@@ -510,11 +583,15 @@ func init() {
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"
)
"automatically approving authenticated channels"
)
viper
.
BindPFlag
(
"unsafe-channel-creation"
,
rootCmd
.
Flags
()
.
Lookup
(
"unsafe-channel-creation"
))
rootCmd
.
Flags
()
.
StringP
(
"accept-channel"
,
""
,
""
,
"Accept the specified channel request"
)
viper
.
BindPFlag
(
"accept-channel"
,
rootCmd
.
Flags
()
.
Lookup
(
"accept-channel"
))
// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().StringVarP(¬ificationToken, "nbRegistration", "x", "",
...
...
This diff is collapsed.
Click to expand it.
interfaces/user/user.go
+
2
−
2
View file @
75d96a8e
...
...
@@ -23,7 +23,7 @@ type User struct {
E2eDhPublicKey
*
cyclic
.
Int
}
func
(
u
*
User
)
GetContact
()
contact
.
Contact
{
func
(
u
User
)
GetContact
()
contact
.
Contact
{
return
contact
.
Contact
{
ID
:
u
.
ID
.
DeepCopy
(),
DhPubKey
:
u
.
E2eDhPublicKey
,
...
...
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