Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
user-discovery-bot
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package 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
archives
user-discovery-bot
Commits
8d6986eb
Commit
8d6986eb
authored
Nov 9, 2022
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Fix build issues from pulling release
parent
e1d8c4e4
No related branches found
No related tags found
1 merge request
!58
Draft: Projects/crust RELEASE
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
io/validateUsername.go
+20
-9
20 additions, 9 deletions
io/validateUsername.go
with
20 additions
and
9 deletions
io/validateUsername.go
+
20
−
9
View file @
8d6986eb
...
@@ -21,36 +21,47 @@ const (
...
@@ -21,36 +21,47 @@ const (
usernameNotAssociatedWithUser
=
"username %s is not associated with user ID %s"
usernameNotAssociatedWithUser
=
"username %s is not associated with user ID %s"
)
)
// ValidateUsername validates that a user owns a username by signing the
contents of the
// ValidateUsername validates that a user owns a username by signing the
// mixmessages.UsernameValidationRequest.
//
contents of the
mixmessages.UsernameValidationRequest.
func
validateUsername
(
request
*
pb
.
UsernameValidationRequest
,
func
validateUsername
(
request
*
pb
.
UsernameValidationRequest
,
store
*
storage
.
Storage
,
privKey
*
rsa
.
PrivateKey
,
rng
io
.
Reader
)
(
*
pb
.
UsernameValidation
,
error
)
{
store
*
storage
.
Storage
,
privKey
*
rsa
.
PrivateKey
,
rng
io
.
Reader
)
(
*
pb
.
UsernameValidation
,
error
)
{
// Return an error if the request is invalid
// Return an error if the request is invalid
if
request
==
nil
||
request
.
UserId
==
nil
{
if
request
==
nil
||
request
.
UserId
==
nil
{
return
&
pb
.
UsernameValidation
{},
errors
.
New
(
"Unable to parse
required
"
+
return
&
pb
.
UsernameValidation
{},
errors
.
New
(
"Unable to parse "
+
"fields in registration message"
)
"
required
fields in registration message"
)
}
}
// Marshal user ID
// Marshal user ID
userID
,
err
:=
id
.
Unmarshal
(
request
.
UserId
)
userID
,
err
:=
id
.
Unmarshal
(
request
.
UserId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
&
pb
.
UsernameValidation
{},
errors
.
WithMessage
(
err
,
invalidUserIdError
)
return
&
pb
.
UsernameValidation
{},
errors
.
WithMessage
(
err
,
invalidUserIdError
)
}
}
// Return an error if the user is not registered
// Return an error if the user is not registered
user
,
err
:=
store
.
GetUser
(
request
.
UserId
)
user
,
err
:=
store
.
GetUser
(
request
.
UserId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
&
pb
.
UsernameValidation
{},
errors
.
WithMessage
(
err
,
getUserFailureError
)
return
&
pb
.
UsernameValidation
{},
errors
.
WithMessage
(
err
,
getUserFailureError
)
}
else
if
user
==
nil
{
}
else
if
user
==
nil
{
return
&
pb
.
UsernameValidation
{},
errors
.
Errorf
(
noUserError
,
return
&
pb
.
UsernameValidation
{},
errors
.
Errorf
(
noUserError
,
userID
)
userID
)
}
}
// Parse the client's public key
clientPubKey
,
err
:=
rsa
.
LoadPublicKeyFromPem
([]
byte
(
user
.
RsaPub
))
if
err
!=
nil
{
return
&
pb
.
UsernameValidation
{},
errors
.
New
(
"Could not parse key from storage"
)
}
// Create a signature verifying the user owns their username
// Create a signature verifying the user owns their username
verificationSignature
,
err
:=
crust
.
SignVerification
(
rng
,
privKey
,
verificationSignature
,
err
:=
crust
.
SignVerification
(
rng
,
privKey
,
user
.
Username
,
[]
byte
(
user
.
RsaPub
)
)
user
.
Username
,
clientPubKey
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Errorf
(
"Failed to create verification signature: %v"
,
err
)
return
nil
,
errors
.
Errorf
(
"Failed to create verification signature: %v"
,
err
)
}
}
// Return signature to user
// Return signature to user
...
...
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