diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e7736d6..a3f3c8ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,22 @@ # Changelog This is the changelog for NeoFS Proto +## [0.2.3] - 2019-11-28 + +### Removed +- service: SignRequest / VerifyRequest and accompanying code +- proto: Signature field from requests +- object: bytefmt package not used anymore + +### Changed +- service: rename EpochRequest to EpochHeader and merge with MetaHeader +- service: get status error even if it is wrapped + +### Added +- service: RequestVerificationHeader's method to validate owner +- service: test coverage for CheckOwner +- service: test coverage for wrapped status errors + ## [0.2.2] - 2019-11-22 ### Changed @@ -33,3 +49,4 @@ Initial public release [0.2.0]: https://github.com/nspcc-dev/neofs-proto/compare/v0.1.0...v0.2.0 [0.2.1]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.0...v0.2.1 [0.2.2]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.1...v0.2.2 +[0.2.3]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.2...v0.2.3 diff --git a/accounting/withdraw.go b/accounting/withdraw.go index 0a8cf901..11c56081 100644 --- a/accounting/withdraw.go +++ b/accounting/withdraw.go @@ -11,12 +11,6 @@ type ( MessageID = refs.MessageID ) -// SetSignature sets signature to PutRequest to satisfy SignedRequest interface. -func (m *PutRequest) SetSignature(v []byte) { m.Signature = v } - -// SetSignature sets signature to DeleteRequest to satisfy SignedRequest interface. -func (m *DeleteRequest) SetSignature(v []byte) { m.Signature = v } - // PrepareData prepares bytes representation of PutRequest to satisfy SignedRequest interface. func (m *PutRequest) PrepareData() ([]byte, error) { var offset int diff --git a/accounting/withdraw.pb.go b/accounting/withdraw.pb.go index a2116c01..d80b01cf 100644 Binary files a/accounting/withdraw.pb.go and b/accounting/withdraw.pb.go differ diff --git a/accounting/withdraw.proto b/accounting/withdraw.proto index bb950ba4..a44e47a8 100644 --- a/accounting/withdraw.proto +++ b/accounting/withdraw.proto @@ -59,8 +59,6 @@ message PutRequest { uint64 Height = 3; // MessageID is a nonce for uniq request (UUIDv4) bytes MessageID = 4 [(gogoproto.customtype) = "MessageID", (gogoproto.nullable) = false]; - // Signature is a signature of the sent request - bytes Signature = 5; // RequestMetaHeader contains information about request meta headers (should be embedded into message) service.RequestMetaHeader Meta = 98 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; // RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) @@ -92,8 +90,6 @@ message DeleteRequest { bytes OwnerID = 2 [(gogoproto.customtype) = "OwnerID", (gogoproto.nullable) = false]; // MessageID is a nonce for uniq request (UUIDv4) bytes MessageID = 3 [(gogoproto.customtype) = "MessageID", (gogoproto.nullable) = false]; - // Signature is a signature of the sent request - bytes Signature = 4; // RequestMetaHeader contains information about request meta headers (should be embedded into message) service.RequestMetaHeader Meta = 98 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; // RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) diff --git a/container/service.go b/container/service.go index 4d3747e5..24727ee7 100644 --- a/container/service.go +++ b/container/service.go @@ -25,12 +25,6 @@ const ( ErrNotFound = internal.Error("could not find container") ) -// SetSignature sets signature to PutRequest to satisfy SignedRequest interface. -func (m *PutRequest) SetSignature(v []byte) { m.Signature = v } - -// SetSignature sets signature to DeleteRequest to satisfy SignedRequest interface. -func (m *DeleteRequest) SetSignature(v []byte) { m.Signature = v } - // PrepareData prepares bytes representation of PutRequest to satisfy SignedRequest interface. func (m *PutRequest) PrepareData() ([]byte, error) { var ( diff --git a/container/service.pb.go b/container/service.pb.go index 8b98cfa5..d9febc0e 100644 Binary files a/container/service.pb.go and b/container/service.pb.go differ diff --git a/container/service.proto b/container/service.proto index d4d50cae..8a3f56c0 100644 --- a/container/service.proto +++ b/container/service.proto @@ -41,9 +41,6 @@ message PutRequest { // Rules define storage policy for the object inside the container. netmap.PlacementRule rules = 4 [(gogoproto.nullable) = false]; - // Signature of the user (owner id) - bytes Signature = 5; - // RequestMetaHeader contains information about request meta headers (should be embedded into message) service.RequestMetaHeader Meta = 98 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; // RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) @@ -59,9 +56,6 @@ message DeleteRequest { // CID (container id) is a SHA256 hash of the container structure bytes CID = 1 [(gogoproto.customtype) = "CID", (gogoproto.nullable) = false]; - // Signature of the container owner - bytes Signature = 2; - // RequestMetaHeader contains information about request meta headers (should be embedded into message) service.RequestMetaHeader Meta = 98 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; // RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) diff --git a/docs/accounting.md b/docs/accounting.md index 268a1872..bcae1366 100644 --- a/docs/accounting.md +++ b/docs/accounting.md @@ -362,7 +362,6 @@ Delete allows user to remove unused cheque | ID | [bytes](#bytes) | | ID is cheque identifier | | OwnerID | [bytes](#bytes) | | OwnerID is a wallet address | | MessageID | [bytes](#bytes) | | MessageID is a nonce for uniq request (UUIDv4) | -| Signature | [bytes](#bytes) | | Signature is a signature of the sent request | | Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) | | Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) | @@ -450,7 +449,6 @@ DeleteResponse is empty | Amount | [decimal.Decimal](#decimal.Decimal) | | Amount of funds | | Height | [uint64](#uint64) | | Height is the neo blockchain height until the cheque is valid | | MessageID | [bytes](#bytes) | | MessageID is a nonce for uniq request (UUIDv4) | -| Signature | [bytes](#bytes) | | Signature is a signature of the sent request | | Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) | | Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) | diff --git a/docs/container.md b/docs/container.md index bc559ce2..ef2ba19a 100644 --- a/docs/container.md +++ b/docs/container.md @@ -92,7 +92,6 @@ List returns all user's containers | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | CID | [bytes](#bytes) | | CID (container id) is a SHA256 hash of the container structure | -| Signature | [bytes](#bytes) | | Signature of the container owner | | Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) | | Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) | @@ -165,7 +164,6 @@ via consensus in inner ring nodes | Capacity | [uint64](#uint64) | | Capacity defines amount of data that can be stored in the container (doesn't used for now). | | OwnerID | [bytes](#bytes) | | OwnerID is a wallet address | | rules | [netmap.PlacementRule](#netmap.PlacementRule) | | Rules define storage policy for the object inside the container. | -| Signature | [bytes](#bytes) | | Signature of the user (owner id) | | Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) | | Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) | diff --git a/go.mod b/go.mod index 06fb5c07..dc07a30b 100644 --- a/go.mod +++ b/go.mod @@ -3,16 +3,13 @@ module github.com/nspcc-dev/neofs-proto go 1.13 require ( - code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c github.com/gogo/protobuf v1.3.1 github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 - github.com/mr-tron/base58 v1.1.2 + github.com/mr-tron/base58 v1.1.3 github.com/nspcc-dev/neofs-crypto v0.2.2 github.com/nspcc-dev/netmap v1.6.1 github.com/nspcc-dev/tzhash v1.3.0 - github.com/onsi/ginkgo v1.10.2 // indirect - github.com/onsi/gomega v1.7.0 // indirect github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.2.1 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 diff --git a/go.sum b/go.sum index f06a4990..13842ce9 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,4 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c h1:2RuXx1+tSNWRjxhY0Bx52kjV2odJQ0a6MTbfTPhGAkg= -code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/abiosoft/ishell v2.0.0+incompatible/go.mod h1:HQR9AqF2R3P4XXpMpI0NAzgHf/aS6+zVXRj14cVk9qg= github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db/go.mod h1:rB3B4rKii8V21ydCbIzH5hZiCQE7f5E9SzUb/ZZx530= @@ -25,8 +23,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -49,8 +45,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -68,6 +62,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc= +github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nspcc-dev/hrw v1.0.8 h1:vwRuJXZXgkMvf473vFzeWGCfY1WBVeSHAEHvR4u3/Cg= github.com/nspcc-dev/hrw v1.0.8/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU= @@ -79,11 +75,6 @@ github.com/nspcc-dev/rfc6979 v0.1.0 h1:Lwg7esRRoyK1Up/IN1vAef1EmvrBeMHeeEkek2fAJ github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/nspcc-dev/tzhash v1.3.0 h1:n6FTHsfPYbMi5Jmo6SwGVVRQD8i2w1P2ScCaW6rz69Q= github.com/nspcc-dev/tzhash v1.3.0/go.mod h1:Lc4DersKS8MNIrunTmsAzANO56qnG+LZ4GOE/WYGVzU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.10.2 h1:uqH7bpe+ERSiDa34FDOF7RikN6RzXgduUF8yarlZp94= -github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= -github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -119,7 +110,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= @@ -127,12 +117,10 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -155,10 +143,6 @@ gopkg.in/abiosoft/ishell.v2 v2.0.0/go.mod h1:sFp+cGtH6o4s1FtpVPTMcHq2yue+c4DGOVo gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/object/utils.go b/object/utils.go index c0fb6248..fab7fcc8 100644 --- a/object/utils.go +++ b/object/utils.go @@ -2,12 +2,43 @@ package object import ( "io" + "strconv" - "code.cloudfoundry.org/bytefmt" "github.com/nspcc-dev/neofs-proto/session" "github.com/pkg/errors" ) +// ByteSize used to format bytes +type ByteSize uint64 + +// String represents ByteSize in string format +func (b ByteSize) String() string { + var ( + dec int64 + unit string + num = int64(b) + ) + + switch { + case num > UnitsTB: + unit = "TB" + dec = UnitsTB + case num > UnitsGB: + unit = "GB" + dec = UnitsGB + case num > UnitsMB: + unit = "MB" + dec = UnitsMB + case num > UnitsKB: + unit = "KB" + dec = UnitsKB + case num > UnitsB: + dec = 1 + } + + return strconv.FormatFloat(float64(num)/float64(dec), 'g', 6, 64) + unit +} + // MakePutRequestHeader combines object and session token value // into header of object put request. func MakePutRequestHeader(obj *Object, token *session.Token) *PutRequest { @@ -26,7 +57,7 @@ func MakePutRequestChunk(chunk []byte) *PutRequest { } func errMaxSizeExceeded(size uint64) error { - return errors.Errorf("object payload size exceed: %s", bytefmt.ByteSize(size)) + return errors.Errorf("object payload size exceed: %s", ByteSize(size).String()) } // ReceiveGetResponse receives object by chunks from the protobuf stream diff --git a/object/utils_test.go b/object/utils_test.go new file mode 100644 index 00000000..a3f0162b --- /dev/null +++ b/object/utils_test.go @@ -0,0 +1,48 @@ +package object + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestByteSize_String(t *testing.T) { + var cases = []struct { + name string + expect string + actual ByteSize + }{ + { + name: "101 bytes", + expect: "101", + actual: ByteSize(101), + }, + { + name: "112.84KB", + expect: "112.84KB", + actual: ByteSize(115548), + }, + { + name: "80.44MB", + expect: "80.44MB", + actual: ByteSize(84347453), + }, + { + name: "905.144GB", + expect: "905.144GB", + actual: ByteSize(971891061884), + }, + { + name: "1.857TB", + expect: "1.857TB", + actual: ByteSize(2041793092780), + }, + } + + for i := range cases { + tt := cases[i] + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.expect, tt.actual.String()) + }) + } +} diff --git a/service/epoch.go b/service/epoch.go deleted file mode 100644 index 2fd43817..00000000 --- a/service/epoch.go +++ /dev/null @@ -1,7 +0,0 @@ -package service - -// EpochRequest interface gives possibility to get or set epoch in RPC Requests. -type EpochRequest interface { - GetEpoch() uint64 - SetEpoch(v uint64) -} diff --git a/service/meta.go b/service/meta.go index abffdadd..8730386c 100644 --- a/service/meta.go +++ b/service/meta.go @@ -2,6 +2,7 @@ package service import ( "github.com/nspcc-dev/neofs-proto/internal" + "github.com/pkg/errors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -19,14 +20,19 @@ type ( GetTTL() uint32 SetTTL(uint32) - // EpochRequest gives possibility to get or set epoch in RPC Requests. - GetEpoch() uint64 - SetEpoch(uint64) + // EpochHeader gives possibility to get or set epoch in RPC Requests. + EpochHeader // VersionHeader allows get or set version of protocol request VersionHeader } + // EpochHeader interface gives possibility to get or set epoch in RPC Requests. + EpochHeader interface { + GetEpoch() uint64 + SetEpoch(v uint64) + } + // VersionHeader allows get or set version of protocol request VersionHeader interface { GetVersion() uint32 @@ -101,7 +107,7 @@ func ProcessRequestTTL(req MetaHeader, cond ...TTLCondition) error { // check specific condition: if err := cond[i](ttl); err != nil { - if st, ok := status.FromError(err); ok { + if st, ok := status.FromError(errors.Cause(err)); ok { return st.Err() } diff --git a/service/meta_test.go b/service/meta_test.go index 496ea519..e208dfe1 100644 --- a/service/meta_test.go +++ b/service/meta_test.go @@ -3,6 +3,7 @@ package service import ( "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -54,6 +55,18 @@ func TestMetaRequest(t *testing.T) { RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, handler: func(_ uint32) error { return status.Error(codes.NotFound, "not found") }, }, + { + msg: "not found", + code: codes.NotFound, + name: "custom wrapped status error", + RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, + handler: func(_ uint32) error { + err := status.Error(codes.NotFound, "not found") + err = errors.Wrap(err, "some error context") + err = errors.Wrap(err, "another error context") + return err + }, + }, } for i := range tests { diff --git a/service/sign.go b/service/sign.go deleted file mode 100644 index d8db94e8..00000000 --- a/service/sign.go +++ /dev/null @@ -1,47 +0,0 @@ -package service - -import ( - "crypto/ecdsa" - - crypto "github.com/nspcc-dev/neofs-crypto" - "github.com/nspcc-dev/neofs-proto/internal" - "github.com/pkg/errors" -) - -// ErrWrongSignature should be raised when wrong signature is passed into VerifyRequest. -const ErrWrongSignature = internal.Error("wrong signature") - -// SignedRequest interface allows sign and verify requests. -type SignedRequest interface { - PrepareData() ([]byte, error) - GetSignature() []byte - SetSignature([]byte) -} - -// SignRequest with passed private key. -func SignRequest(r SignedRequest, key *ecdsa.PrivateKey) error { - var signature []byte - if data, err := r.PrepareData(); err != nil { - return err - } else if signature, err = crypto.Sign(key, data); err != nil { - return errors.Wrap(err, "could not sign data") - } - - r.SetSignature(signature) - - return nil -} - -// VerifyRequest by passed public keys. -func VerifyRequest(r SignedRequest, keys ...*ecdsa.PublicKey) bool { - data, err := r.PrepareData() - if err != nil { - return false - } - for i := range keys { - if err := crypto.Verify(keys[i], data, r.GetSignature()); err == nil { - return true - } - } - return false -} diff --git a/service/verify.go b/service/verify.go index a6ac3a51..48e2871d 100644 --- a/service/verify.go +++ b/service/verify.go @@ -6,6 +6,7 @@ import ( "github.com/gogo/protobuf/proto" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-proto/internal" + "github.com/nspcc-dev/neofs-proto/refs" "github.com/pkg/errors" ) @@ -35,6 +36,9 @@ const ( // ErrCannotFindOwner is raised when signatures empty in GetOwner. ErrCannotFindOwner = internal.Error("cannot find owner public key") + + // ErrWrongOwner is raised when passed OwnerID not equal to present PublicKey + ErrWrongOwner = internal.Error("wrong owner") ) // SetSignatures replaces signatures stored in RequestVerificationHeader. @@ -62,6 +66,18 @@ func (m *RequestVerificationHeader) SetOwner(pub *ecdsa.PublicKey, sign []byte) } } +// CheckOwner validates, that passed OwnerID is equal to present PublicKey of owner. +func (m *RequestVerificationHeader) CheckOwner(owner refs.OwnerID) error { + if key, err := m.GetOwner(); err != nil { + return err + } else if user, err := refs.NewOwnerID(key); err != nil { + return err + } else if !user.Equal(owner) { + return ErrWrongOwner + } + return nil +} + // GetOwner tries to get owner (client) public key from signatures. // If signatures contains not empty Origin, we should try to validate, // that session key was signed by owner (client), otherwise return error. diff --git a/service/verify_test.go b/service/verify_test.go index 1403c678..237e3623 100644 --- a/service/verify_test.go +++ b/service/verify_test.go @@ -9,6 +9,7 @@ import ( "github.com/gogo/protobuf/proto" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-crypto/test" + "github.com/nspcc-dev/neofs-proto/refs" "github.com/pkg/errors" "github.com/stretchr/testify/require" ) @@ -78,6 +79,12 @@ func TestMaintainableRequest(t *testing.T) { } } + { // Validate owner + user, err := refs.NewOwnerID(&owner.PublicKey) + require.NoError(t, err) + require.NoError(t, req.CheckOwner(user)) + } + { // Good case: require.NoError(t, VerifyRequestHeader(req))