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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
afc2d64a
Commit
afc2d64a
authored
4 years ago
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
add unsafe channel creation flag and associated logic
parent
5ee6cd8f
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
+60
-19
60 additions, 19 deletions
cmd/root.go
with
60 additions
and
19 deletions
cmd/root.go
+
60
−
19
View file @
afc2d64a
...
@@ -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(¬ificationToken, "nbRegistration", "x", "",
// rootCmd.Flags().StringVarP(¬ificationToken, "nbRegistration", "x", "",
...
...
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