Skip to content

Commit

Permalink
Made requested changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <[email protected]>
  • Loading branch information
cody-littley committed Nov 20, 2024
1 parent 0372ee9 commit 97cc318
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions relay/auth/authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func TestValidRequest(t *testing.T) {

request := randomGetChunksRequest()
request.OperatorId = operatorID[:]
SignGetChunksRequest(ics.KeyPairs[operatorID], request)
signature := request.OperatorSignature
signature := SignGetChunksRequest(ics.KeyPairs[operatorID], request)
request.OperatorSignature = signature

now := time.Now()

Expand Down Expand Up @@ -125,8 +125,8 @@ func TestAuthenticationSavingDisabled(t *testing.T) {

request := randomGetChunksRequest()
request.OperatorId = operatorID[:]
SignGetChunksRequest(ics.KeyPairs[operatorID], request)
signature := request.OperatorSignature
signature := SignGetChunksRequest(ics.KeyPairs[operatorID], request)
request.OperatorSignature = signature

now := time.Now()

Expand Down Expand Up @@ -199,7 +199,7 @@ func TestBadSignature(t *testing.T) {

request := randomGetChunksRequest()
request.OperatorId = operatorID[:]
SignGetChunksRequest(ics.KeyPairs[operatorID], request)
request.OperatorSignature = SignGetChunksRequest(ics.KeyPairs[operatorID], request)

now := time.Now()

Expand Down
7 changes: 4 additions & 3 deletions relay/auth/request_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ func HashGetChunksRequest(request *pb.GetChunksRequest) []byte {
return hasher.Sum(nil)
}

// SignGetChunksRequest signs the given GetChunksRequest with the given private key.
func SignGetChunksRequest(keys *core.KeyPair, request *pb.GetChunksRequest) {
// SignGetChunksRequest signs the given GetChunksRequest with the given private key. Does not
// write the signature into the request.
func SignGetChunksRequest(keys *core.KeyPair, request *pb.GetChunksRequest) []byte {
hash := HashGetChunksRequest(request)
signature := keys.SignMessage(([32]byte)(hash))
request.OperatorSignature = signature.G1Point.Serialize()
return signature.G1Point.Serialize()
}
12 changes: 6 additions & 6 deletions relay/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ func (s *Server) GetChunks(ctx context.Context, request *pb.GetChunksRequest) (*
"too many chunk requests provided, max is %d", s.config.MaxKeysPerGetChunksRequest)
}

client, ok := peer.FromContext(ctx)
if !ok {
return nil, errors.New("could not get peer information")
}
clientAddress := client.Addr.String()

if s.authenticator != nil {
client, ok := peer.FromContext(ctx)
if !ok {
return nil, errors.New("could not get peer information")
}
clientAddress := client.Addr.String()

err := s.authenticator.AuthenticateGetChunksRequest(clientAddress, request, time.Now())
if err != nil {
return nil, fmt.Errorf("auth failed: %w", err)
Expand Down

0 comments on commit 97cc318

Please sign in to comment.