From de505ddee93a64ef624914e0fba2d231d89ddf72 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 2 Sep 2020 14:58:28 +0300 Subject: [PATCH] [#133] sdk: Use cid wrapper to sign container delete request StableMarshalerWrapper is not suitable for container delete request, because it signs marshaled structure of container id. As for delete request, container id itself should be signed. Signed-off-by: Alex Vanin --- pkg/client/container.go | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/pkg/client/container.go b/pkg/client/container.go index ef72a83..67301c7 100644 --- a/pkg/client/container.go +++ b/pkg/client/container.go @@ -13,6 +13,18 @@ import ( "github.com/pkg/errors" ) +type delContainerSignWrapper struct { + body *v2container.DeleteRequestBody +} + +func (c delContainerSignWrapper) ReadSignedData(bytes []byte) ([]byte, error) { + return c.body.GetContainerID().GetValue(), nil +} + +func (c delContainerSignWrapper) SignedDataSize() int { + return len(c.body.GetContainerID().GetValue()) +} + func (c Client) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*container.ID, error) { switch c.remoteNode.Version.Major { case 2: @@ -55,7 +67,7 @@ func (c Client) ListSelfContainers(ctx context.Context, opts ...CallOption) ([]* func (c Client) DeleteContainer(ctx context.Context, id *container.ID, opts ...CallOption) error { switch c.remoteNode.Version.Major { case 2: - panic("not implemented") + return c.delContainerV2(ctx, id, opts...) default: return unsupportedProtocolErr } @@ -248,13 +260,17 @@ func (c Client) delContainerV2(ctx context.Context, id *container.ID, opts ...Ca reqBody.SetContainerID(id.ToV2()) // sign container - signWrapper := v2signature.StableMarshalerWrapper{SM: reqBody.GetContainerID()} - err := signature.SignDataWithHandler(c.key, signWrapper, func(key []byte, sig []byte) { - containerSignature := new(refs.Signature) - containerSignature.SetKey(key) - containerSignature.SetSign(sig) - reqBody.SetSignature(containerSignature) - }, signature.SignWithRFC6979()) + err := signature.SignDataWithHandler(c.key, + delContainerSignWrapper{ + body: reqBody, + }, + func(key []byte, sig []byte) { + containerSignature := new(refs.Signature) + containerSignature.SetKey(key) + containerSignature.SetSign(sig) + reqBody.SetSignature(containerSignature) + }, + signature.SignWithRFC6979()) if err != nil { return err }