2019-03-18 10:55:06 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package signing
|
|
|
|
|
|
|
|
import (
|
2019-06-04 12:36:27 +01:00
|
|
|
"context"
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Signee is able to verify that the data signature belongs to the signee.
|
|
|
|
type Signee interface {
|
|
|
|
ID() storj.NodeID
|
|
|
|
HashAndVerifySignature(data, signature []byte) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyOrderLimitSignature verifies that the signature inside order limit belongs to the satellite.
|
2019-06-04 12:36:27 +01:00
|
|
|
func VerifyOrderLimitSignature(satellite Signee, signed *pb.OrderLimit2) (err error) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-03-18 10:55:06 +00:00
|
|
|
bytes, err := EncodeOrderLimit(signed)
|
|
|
|
if err != nil {
|
|
|
|
return Error.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return satellite.HashAndVerifySignature(bytes, signed.SatelliteSignature)
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyOrderSignature verifies that the signature inside order belongs to the uplink.
|
2019-06-04 12:36:27 +01:00
|
|
|
func VerifyOrderSignature(uplink Signee, signed *pb.Order2) (err error) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-03-18 10:55:06 +00:00
|
|
|
bytes, err := EncodeOrder(signed)
|
|
|
|
if err != nil {
|
|
|
|
return Error.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return uplink.HashAndVerifySignature(bytes, signed.UplinkSignature)
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyPieceHashSignature verifies that the signature inside piece hash belongs to the signer, which is either uplink or storage node.
|
2019-06-04 12:36:27 +01:00
|
|
|
func VerifyPieceHashSignature(signee Signee, signed *pb.PieceHash) (err error) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-03-18 10:55:06 +00:00
|
|
|
bytes, err := EncodePieceHash(signed)
|
|
|
|
if err != nil {
|
|
|
|
return Error.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return signee.HashAndVerifySignature(bytes, signed.Signature)
|
|
|
|
}
|