Skip to content
Snippets Groups Projects
Commit 8d6986eb authored by Josh Brooks's avatar Josh Brooks
Browse files

Fix build issues from pulling release

parent e1d8c4e4
No related branches found
No related tags found
1 merge request!58Draft: Projects/crust RELEASE
...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment