From 9ceba98198d0fd5ea578900a6395a5d5a96c0b8b Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 17 Nov 2020 14:17:15 +0300 Subject: [PATCH] [#202] pkg/client: Fix signature check in object header getter According to API object.Head response contains signature of object ID rather than signature of object header itself. Signed-off-by: Alex Vanin --- pkg/client/object.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/client/object.go b/pkg/client/object.go index 87842c4c..f30ca0d5 100644 --- a/pkg/client/object.go +++ b/pkg/client/object.go @@ -543,7 +543,10 @@ func (c *Client) getObjectHeaderV2(ctx context.Context, p *ObjectHeaderParams, o return nil, errors.Wrapf(err, "could not verify %T", resp) } - var hdr *v2object.Header + var ( + hdr *v2object.Header + idSig *v2refs.Signature + ) switch v := resp.GetBody().GetHeaderPart().(type) { case nil: @@ -576,15 +579,14 @@ func (c *Client) getObjectHeaderV2(ctx context.Context, p *ObjectHeaderParams, o } hdr = hdrWithSig.GetHeader() + idSig = hdrWithSig.GetSignature() if err := signer.VerifyDataWithSource( signature.StableMarshalerWrapper{ - SM: hdrWithSig.GetHeader(), + SM: p.addr.ObjectID().ToV2(), }, func() (key, sig []byte) { - s := hdrWithSig.GetSignature() - - return s.GetKey(), s.GetSign() + return idSig.GetKey(), idSig.GetSign() }, ); err != nil { return nil, errors.Wrap(err, "incorrect object header signature") @@ -595,6 +597,7 @@ func (c *Client) getObjectHeaderV2(ctx context.Context, p *ObjectHeaderParams, o obj := new(v2object.Object) obj.SetHeader(hdr) + obj.SetSignature(idSig) raw := object.NewRawFromV2(obj) raw.SetID(p.addr.ObjectID())