[#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 <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-09-02 14:58:28 +03:00 committed by Stanislav Bogatyrev
parent acbdbd410e
commit de505ddee9

View file

@ -13,6 +13,18 @@ import (
"github.com/pkg/errors" "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) { func (c Client) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*container.ID, error) {
switch c.remoteNode.Version.Major { switch c.remoteNode.Version.Major {
case 2: 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 { func (c Client) DeleteContainer(ctx context.Context, id *container.ID, opts ...CallOption) error {
switch c.remoteNode.Version.Major { switch c.remoteNode.Version.Major {
case 2: case 2:
panic("not implemented") return c.delContainerV2(ctx, id, opts...)
default: default:
return unsupportedProtocolErr return unsupportedProtocolErr
} }
@ -248,13 +260,17 @@ func (c Client) delContainerV2(ctx context.Context, id *container.ID, opts ...Ca
reqBody.SetContainerID(id.ToV2()) reqBody.SetContainerID(id.ToV2())
// sign container // sign container
signWrapper := v2signature.StableMarshalerWrapper{SM: reqBody.GetContainerID()} err := signature.SignDataWithHandler(c.key,
err := signature.SignDataWithHandler(c.key, signWrapper, func(key []byte, sig []byte) { delContainerSignWrapper{
containerSignature := new(refs.Signature) body: reqBody,
containerSignature.SetKey(key) },
containerSignature.SetSign(sig) func(key []byte, sig []byte) {
reqBody.SetSignature(containerSignature) containerSignature := new(refs.Signature)
}, signature.SignWithRFC6979()) containerSignature.SetKey(key)
containerSignature.SetSign(sig)
reqBody.SetSignature(containerSignature)
},
signature.SignWithRFC6979())
if err != nil { if err != nil {
return err return err
} }