Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace math/rand with crypto/rand for generating challenge #829

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions disperser/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package apiserver

import (
"context"
"crypto/rand"
"encoding/binary"
"errors"
"fmt"
"math/rand"
"net"
"slices"
"strings"
Expand Down Expand Up @@ -146,7 +147,14 @@ func (s *DispersalServer) DisperseBlobAuthenticated(stream pb.Disperser_Disperse
authenticatedAddress := crypto.PubkeyToAddress(*pubKey).String()

// Send back challenge to client
challenge := rand.Uint32()
challengeBytes := make([]byte, 32)
_, err = rand.Read(challengeBytes)
if err != nil {
s.metrics.HandleInvalidArgRpcRequest("DisperseBlobAuthenticated")
s.metrics.HandleInvalidArgRequest("DisperseBlobAuthenticated")
return api.NewInvalidArgError(fmt.Sprintf("failed to generate challenge: %v", err))
}
challenge := binary.LittleEndian.Uint32(challengeBytes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any preference to little or big endian

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that matters much here as we're converting one random byte array into uint32

err = stream.Send(&pb.AuthenticatedReply{Payload: &pb.AuthenticatedReply_BlobAuthHeader{
BlobAuthHeader: &pb.BlobAuthHeader{
ChallengeParameter: challenge,
Expand Down
Loading