2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-05 14:03:23 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-25 23:06:38 +00:00
|
|
|
package bwagreement_test
|
2018-12-05 14:03:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-02-07 20:39:20 +00:00
|
|
|
"crypto"
|
2019-01-25 18:05:21 +00:00
|
|
|
"crypto/tls"
|
|
|
|
"crypto/x509"
|
|
|
|
"net"
|
2018-12-05 14:03:23 +00:00
|
|
|
"testing"
|
2019-01-15 04:44:56 +00:00
|
|
|
"time"
|
2018-12-05 14:03:23 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2018-12-05 14:03:23 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-01-28 19:45:25 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-12-07 12:11:35 +00:00
|
|
|
"go.uber.org/zap"
|
2019-01-25 18:05:21 +00:00
|
|
|
"google.golang.org/grpc/credentials"
|
|
|
|
"google.golang.org/grpc/peer"
|
2018-12-07 12:11:35 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
2019-01-02 17:39:17 +00:00
|
|
|
"storj.io/storj/internal/testidentity"
|
2019-01-25 18:05:21 +00:00
|
|
|
"storj.io/storj/pkg/auth"
|
2018-12-07 12:11:35 +00:00
|
|
|
"storj.io/storj/pkg/bwagreement"
|
2019-01-25 23:06:38 +00:00
|
|
|
"storj.io/storj/pkg/bwagreement/testbwagreement"
|
2019-01-25 18:05:21 +00:00
|
|
|
"storj.io/storj/pkg/identity"
|
2018-12-05 14:03:23 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2019-02-07 20:39:20 +00:00
|
|
|
"storj.io/storj/pkg/pkcrypto"
|
2019-01-25 18:05:21 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-12-27 09:56:25 +00:00
|
|
|
"storj.io/storj/satellite"
|
2018-12-10 14:50:12 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2018-12-05 14:03:23 +00:00
|
|
|
)
|
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
func TestBandwidthAgreement(t *testing.T) {
|
2018-12-27 09:56:25 +00:00
|
|
|
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
2018-12-07 12:11:35 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2019-02-07 19:22:49 +00:00
|
|
|
testDatabase(ctx, t, db)
|
2019-01-15 04:44:56 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
func getPeerContext(ctx context.Context, t *testing.T) (context.Context, storj.NodeID) {
|
|
|
|
ident, err := testidentity.NewTestIdentity(ctx)
|
|
|
|
if !assert.NoError(t, err) || !assert.NotNil(t, ident) {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
grpcPeer := &peer.Peer{
|
|
|
|
Addr: &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 5},
|
|
|
|
AuthInfo: credentials.TLSInfo{
|
|
|
|
State: tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-04-08 19:15:19 +01:00
|
|
|
nodeID, err := identity.NodeIDFromCert(ident.CA)
|
2019-01-25 18:05:21 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
return peer.NewContext(ctx, grpcPeer), nodeID
|
|
|
|
}
|
|
|
|
|
2019-02-07 19:22:49 +00:00
|
|
|
func testDatabase(ctx context.Context, t *testing.T, db satellite.DB) {
|
2019-01-25 18:05:21 +00:00
|
|
|
upID, err := testidentity.NewTestIdentity(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
satID, err := testidentity.NewTestIdentity(ctx)
|
|
|
|
assert.NoError(t, err)
|
2019-02-07 20:39:20 +00:00
|
|
|
satellite := bwagreement.NewServer(db.BandwidthAgreement(), db.CertDB(), satID.Leaf.PublicKey, zap.NewNop(), satID.ID)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
{ // TestSameSerialNumberBandwidthAgreements
|
2019-02-22 21:17:35 +00:00
|
|
|
pbaFile1, err := testbwagreement.GenerateOrderLimit(pb.BandwidthAction_GET, satID, upID, time.Hour)
|
2019-01-07 15:19:05 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-07 20:39:20 +00:00
|
|
|
err = db.CertDB().SavePublicKey(ctx, pbaFile1.UplinkId, upID.Leaf.PublicKey)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-02-22 21:17:35 +00:00
|
|
|
rbaNode1, err := testbwagreement.GenerateOrder(pbaFile1, storageNode1, upID, 666)
|
2019-01-07 15:19:05 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN2, storageNode2 := getPeerContext(ctx, t)
|
2019-02-22 21:17:35 +00:00
|
|
|
rbaNode2, err := testbwagreement.GenerateOrder(pbaFile1, storageNode2, upID, 666)
|
2019-01-07 15:19:05 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
/* More than one storage node can submit bwagreements with the same serial number.
|
|
|
|
Uplink would like to download a file from 2 storage nodes.
|
2019-02-22 21:17:35 +00:00
|
|
|
Uplink requests a OrderLimit from the satellite. One serial number for all storage nodes.
|
|
|
|
Uplink signes 2 Order for both storage node. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rbaNode1)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err = satellite.BandwidthAgreements(ctxSN2, rbaNode2)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
|
|
|
|
}
|
2019-01-07 15:19:05 +00:00
|
|
|
|
|
|
|
/* Storage node can submit a second bwagreement with a different sequence value.
|
2019-02-22 21:17:35 +00:00
|
|
|
Uplink downloads another file. New OrderLimit with a new sequence. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-02-22 21:17:35 +00:00
|
|
|
pbaFile2, err := testbwagreement.GenerateOrderLimit(pb.BandwidthAction_GET, satID, upID, time.Hour)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-07 20:39:20 +00:00
|
|
|
err = db.CertDB().SavePublicKey(ctx, pbaFile2.UplinkId, upID.Leaf.PublicKey)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-02-22 21:17:35 +00:00
|
|
|
rbaNode1, err := testbwagreement.GenerateOrder(pbaFile2, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rbaNode1)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
|
|
|
|
}
|
2019-01-07 15:19:05 +00:00
|
|
|
|
|
|
|
/* Storage nodes can't submit a second bwagreement with the same sequence. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-02-22 21:17:35 +00:00
|
|
|
rbaNode1, err := testbwagreement.GenerateOrder(pbaFile1, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rbaNode1)
|
2019-02-01 18:50:12 +00:00
|
|
|
assert.True(t, auth.ErrSerial.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
2019-01-07 15:19:05 +00:00
|
|
|
|
|
|
|
/* Storage nodes can't submit the same bwagreement twice.
|
|
|
|
This test is kind of duplicate cause it will most likely trigger the same sequence error.
|
|
|
|
For safety we will try it anyway to make sure nothing strange will happen */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN2, rbaNode2)
|
2019-03-08 12:23:43 +00:00
|
|
|
assert.True(t, auth.ErrSerial.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // TestExpiredBandwidthAgreements
|
2019-01-25 23:06:38 +00:00
|
|
|
{ // storage nodes can submit a bwagreement that will expire in 30 seconds
|
2019-02-22 21:17:35 +00:00
|
|
|
pba, err := testbwagreement.GenerateOrderLimit(pb.BandwidthAction_GET, satID, upID, 30*time.Second)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-07 20:39:20 +00:00
|
|
|
err = db.CertDB().SavePublicKey(ctx, pba.UplinkId, upID.Leaf.PublicKey)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-15 04:44:56 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-02-22 21:17:35 +00:00
|
|
|
rba, err := testbwagreement.GenerateOrder(pba, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rba)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // storage nodes can't submit a bwagreement that expires right now
|
2019-02-22 21:17:35 +00:00
|
|
|
pba, err := testbwagreement.GenerateOrderLimit(pb.BandwidthAction_GET, satID, upID, 0*time.Second)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-07 20:39:20 +00:00
|
|
|
err = db.CertDB().SavePublicKey(ctx, pba.UplinkId, upID.Leaf.PublicKey)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-15 04:44:56 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-02-22 21:17:35 +00:00
|
|
|
rba, err := testbwagreement.GenerateOrder(pba, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rba)
|
2019-03-08 12:23:43 +00:00
|
|
|
assert.True(t, auth.ErrExpired.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // storage nodes can't submit a bwagreement that expires yesterday
|
2019-02-22 21:17:35 +00:00
|
|
|
pba, err := testbwagreement.GenerateOrderLimit(pb.BandwidthAction_GET, satID, upID, -23*time.Hour-55*time.Second)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-07 20:39:20 +00:00
|
|
|
err = db.CertDB().SavePublicKey(ctx, pba.UplinkId, upID.Leaf.PublicKey)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-15 04:44:56 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-02-22 21:17:35 +00:00
|
|
|
rba, err := testbwagreement.GenerateOrder(pba, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rba)
|
2019-03-08 12:23:43 +00:00
|
|
|
assert.True(t, auth.ErrExpired.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // TestManipulatedBandwidthAgreements
|
2019-02-22 21:17:35 +00:00
|
|
|
pba, err := testbwagreement.GenerateOrderLimit(pb.BandwidthAction_GET, satID, upID, time.Hour)
|
2019-01-25 18:05:21 +00:00
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-02-07 20:39:20 +00:00
|
|
|
err = db.CertDB().SavePublicKey(ctx, pba.UplinkId, upID.Leaf.PublicKey)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.NoError(t, err)
|
2018-12-07 12:11:35 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-02-22 21:17:35 +00:00
|
|
|
rba, err := testbwagreement.GenerateOrder(pba, storageNode1, upID, 666)
|
2018-12-10 14:50:12 +00:00
|
|
|
assert.NoError(t, err)
|
2018-12-07 12:11:35 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
// Storage node manipulates the bwagreement
|
2019-01-28 19:45:25 +00:00
|
|
|
rba.Total = 1337
|
2019-01-10 18:30:55 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
// Generate a new keypair for self signing bwagreements
|
2019-01-25 18:05:21 +00:00
|
|
|
manipID, err := testidentity.NewTestIdentity(ctx)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-03-04 20:03:33 +00:00
|
|
|
manipCerts := manipID.RawChain()
|
2019-02-07 20:39:20 +00:00
|
|
|
manipPrivKey := manipID.Key
|
2019-01-10 18:30:55 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
/* Storage node can't manipulate the bwagreement size (or any other field)
|
2019-01-25 18:05:21 +00:00
|
|
|
Satellite will verify Renter's Signature. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA := *rba
|
2019-01-15 04:44:56 +00:00
|
|
|
// Using uplink signature
|
2019-01-28 19:45:25 +00:00
|
|
|
reply, err := callBWA(ctxSN1, t, satellite, rba.GetSignature(), &manipRBA, rba.GetCerts())
|
|
|
|
assert.True(t, auth.ErrVerify.Has(err) && pb.ErrRenter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Storage node can't sign the manipulated bwagreement
|
2019-01-25 18:05:21 +00:00
|
|
|
Satellite will verify Renter's Signature. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA := *rba
|
|
|
|
manipSignature := GetSignature(t, &manipRBA, manipPrivKey)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
// Using self created signature
|
2019-01-28 19:45:25 +00:00
|
|
|
reply, err := callBWA(ctxSN1, t, satellite, manipSignature, rba, rba.GetCerts())
|
|
|
|
assert.True(t, auth.ErrVerify.Has(err) && pb.ErrRenter.Has(err), err.Error())
|
2019-01-25 18:05:21 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
2019-01-15 04:44:56 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
/* Storage node can't replace uplink Certs
|
|
|
|
Satellite will check uplink Certs against uplinkeId. */
|
|
|
|
{
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA := *rba
|
|
|
|
manipSignature := GetSignature(t, &manipRBA, manipPrivKey)
|
2019-01-25 18:05:21 +00:00
|
|
|
// Using self created signature + public key
|
2019-01-28 19:45:25 +00:00
|
|
|
reply, err := callBWA(ctxSN1, t, satellite, manipSignature, &manipRBA, manipCerts)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.True(t, pb.ErrRenter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
/* Storage node can't replace uplink NodeId
|
|
|
|
Satellite will verify the Payer's Signature. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA := *rba
|
2019-01-25 18:05:21 +00:00
|
|
|
// Overwrite the uplinkId with our own keypair
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA.PayerAllocation.UplinkId = manipID.ID
|
|
|
|
manipSignature := GetSignature(t, &manipRBA, manipPrivKey)
|
2019-01-15 04:44:56 +00:00
|
|
|
// Using self created signature + public key
|
2019-01-28 19:45:25 +00:00
|
|
|
reply, err := callBWA(ctxSN1, t, satellite, manipSignature, &manipRBA, manipCerts)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.True(t, auth.ErrVerify.Has(err) && pb.ErrRenter.Has(err), err.Error())
|
2019-01-25 18:05:21 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
2019-02-22 21:17:35 +00:00
|
|
|
/* Storage node can't self sign the OrderLimit.
|
2019-01-25 18:05:21 +00:00
|
|
|
Satellite will verify the Payer's Signature. */
|
|
|
|
{
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA := *rba
|
2019-01-25 18:05:21 +00:00
|
|
|
// Overwrite the uplinkId with our own keypair
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA.PayerAllocation.UplinkId = manipID.ID
|
|
|
|
manipSignature := GetSignature(t, &manipRBA.PayerAllocation, manipPrivKey)
|
|
|
|
manipRBA.PayerAllocation.Signature = manipSignature
|
|
|
|
manipSignature = GetSignature(t, &manipRBA, manipPrivKey)
|
2019-01-25 18:05:21 +00:00
|
|
|
// Using self created Payer and Renter bwagreement signatures
|
2019-01-28 19:45:25 +00:00
|
|
|
reply, err := callBWA(ctxSN1, t, satellite, manipSignature, &manipRBA, manipCerts)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.True(t, auth.ErrVerify.Has(err) && pb.ErrRenter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
/* Storage node can't replace the satellite Certs.
|
|
|
|
Satellite will check satellite certs against satelliteId. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA := *rba
|
2019-01-25 18:05:21 +00:00
|
|
|
// Overwrite the uplinkId with our own keypair
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA.PayerAllocation.UplinkId = manipID.ID
|
|
|
|
manipSignature := GetSignature(t, &manipRBA.PayerAllocation, manipPrivKey)
|
|
|
|
manipRBA.PayerAllocation.Signature = manipSignature
|
|
|
|
manipRBA.PayerAllocation.Certs = manipCerts
|
|
|
|
manipSignature = GetSignature(t, &manipRBA, manipPrivKey)
|
2019-01-15 04:44:56 +00:00
|
|
|
// Using self created Payer and Renter bwagreement signatures
|
2019-01-28 19:45:25 +00:00
|
|
|
reply, err := callBWA(ctxSN1, t, satellite, manipSignature, &manipRBA, manipCerts)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.True(t, pb.ErrRenter.Has(err), err.Error())
|
2019-01-25 18:05:21 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Storage node can't replace the satellite.
|
|
|
|
Satellite will verify the Satellite Id. */
|
|
|
|
{
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA := *rba
|
2019-01-25 18:05:21 +00:00
|
|
|
// Overwrite the uplinkId and satelliteID with our own keypair
|
2019-01-28 19:45:25 +00:00
|
|
|
manipRBA.PayerAllocation.UplinkId = manipID.ID
|
|
|
|
manipRBA.PayerAllocation.SatelliteId = manipID.ID
|
|
|
|
manipSignature := GetSignature(t, &manipRBA.PayerAllocation, manipPrivKey)
|
|
|
|
manipRBA.PayerAllocation.Signature = manipSignature
|
|
|
|
manipRBA.PayerAllocation.Certs = manipCerts
|
|
|
|
manipSignature = GetSignature(t, &manipRBA, manipPrivKey)
|
2019-01-25 18:05:21 +00:00
|
|
|
// Using self created Payer and Renter bwagreement signatures
|
2019-01-28 19:45:25 +00:00
|
|
|
reply, err := callBWA(ctxSN1, t, satellite, manipSignature, &manipRBA, manipCerts)
|
|
|
|
assert.True(t, pb.ErrPayer.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ //TestInvalidBandwidthAgreements
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
|
|
|
ctxSN2, storageNode2 := getPeerContext(ctx, t)
|
2019-02-22 21:17:35 +00:00
|
|
|
pba, err := testbwagreement.GenerateOrderLimit(pb.BandwidthAction_GET, satID, upID, time.Hour)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-07 20:39:20 +00:00
|
|
|
err = db.CertDB().SavePublicKey(ctx, pba.UplinkId, upID.Leaf.PublicKey)
|
2019-02-07 19:22:49 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
{ // Storage node sends an corrupted signuature to force a satellite crash
|
2019-02-22 21:17:35 +00:00
|
|
|
rba, err := testbwagreement.GenerateOrder(pba, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
rba.Signature = []byte("invalid")
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rba)
|
2019-02-07 18:40:28 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, pb.ErrRenter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
2019-01-11 03:31:47 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
{ // Storage node sends an corrupted uplink Certs to force a crash
|
2019-02-22 21:17:35 +00:00
|
|
|
rba, err := testbwagreement.GenerateOrder(pba, storageNode2, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-28 19:45:25 +00:00
|
|
|
rba.PayerAllocation.Certs = nil
|
|
|
|
reply, err := callBWA(ctxSN2, t, satellite, rba.GetSignature(), rba, rba.GetCerts())
|
|
|
|
assert.True(t, auth.ErrVerify.Has(err) && pb.ErrRenter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
}
|
2018-12-07 12:11:35 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 21:17:35 +00:00
|
|
|
func callBWA(ctx context.Context, t *testing.T, sat *bwagreement.Server, signature []byte, rba *pb.Order, certs [][]byte) (*pb.AgreementsSummary, error) {
|
2019-01-28 19:45:25 +00:00
|
|
|
rba.SetCerts(certs)
|
|
|
|
rba.SetSignature(signature)
|
2019-01-25 18:05:21 +00:00
|
|
|
return sat.BandwidthAgreements(ctx, rba)
|
2018-12-05 14:03:23 +00:00
|
|
|
}
|
2019-01-28 19:45:25 +00:00
|
|
|
|
|
|
|
//GetSignature returns the signature of the signed message
|
2019-02-07 20:39:20 +00:00
|
|
|
func GetSignature(t *testing.T, msg auth.SignableMessage, privKey crypto.PrivateKey) []byte {
|
2019-01-28 19:45:25 +00:00
|
|
|
require.NotNil(t, msg)
|
|
|
|
oldSignature := msg.GetSignature()
|
|
|
|
certs := msg.GetCerts()
|
|
|
|
msg.SetSignature(nil)
|
|
|
|
msg.SetCerts(nil)
|
|
|
|
msgBytes, err := proto.Marshal(msg)
|
|
|
|
require.NoError(t, err)
|
2019-02-07 20:39:20 +00:00
|
|
|
signature, err := pkcrypto.HashAndSign(privKey, msgBytes)
|
2019-01-28 19:45:25 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
msg.SetSignature(oldSignature)
|
|
|
|
msg.SetCerts(certs)
|
|
|
|
return signature
|
|
|
|
}
|