From 72c0dbd8e553976dafc52dcf73ffa2ecf4c6b216 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Tue, 3 Mar 2020 13:23:06 -0800 Subject: [PATCH] fix(markets): fix sig verification fix handling of signatures in the adapters --- markets/storageadapter/client.go | 28 +++++++++++++++++----------- markets/storageadapter/provider.go | 7 ++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 9e99b0128..0c0c0fa18 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -23,6 +23,7 @@ import ( "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/node/impl/full" ) @@ -92,8 +93,8 @@ func (n *ClientNodeAdapter) ListStorageProviders(ctx context.Context) ([]*storag } func (n *ClientNodeAdapter) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool { - log.Warn("stub VerifySignature") - return true + err := sigs.Verify(&sig, addr, input) + return err == nil } func (n *ClientNodeAdapter) ListClientDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) { @@ -328,13 +329,19 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider func (n *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal samarket.DealProposal) (*samarket.ClientDealProposal, error) { // TODO: output spec signed proposal - log.Warn("TODO: stub SignProposal") + buf, err := cborutil.Dump(&proposal) + if err != nil { + return nil, err + } + + sig, err := n.Wallet.Sign(ctx, signer, buf) + if err != nil { + return nil, err + } + return &samarket.ClientDealProposal{ - Proposal: proposal, - ClientSignature: crypto.Signature{ - Type: crypto.SigTypeBLS, - Data: []byte{}, - }, + Proposal: proposal, + ClientSignature: *sig, }, nil } @@ -356,9 +363,8 @@ func (n *ClientNodeAdapter) ValidateAskSignature(ask *storagemarket.SignedStorag return xerrors.Errorf("failed to re-serialize ask") } - _ = w - _ = sigb - panic("verify signature") + return sigs.Verify(ask.Signature, w, sigb) + } var _ storagemarket.StorageClientNode = &ClientNodeAdapter{} diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 55ded4553..0a03d3094 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -13,7 +13,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/ipfs/go-cid" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -23,6 +23,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/storage/sealing" @@ -109,8 +110,8 @@ func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagema } func (n *ProviderNodeAdapter) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool { - log.Warn("stub VerifySignature") - return true + err := sigs.Verify(&sig, addr, input) + return err == nil } func (n *ProviderNodeAdapter) ListProviderDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {