Skip to content

Commit

Permalink
[#380] Support changes in signature schemes
Browse files Browse the repository at this point in the history
Support new `SignatureRFC6979` message. Make `refs.ECDSA_SHA512` to be
default scheme.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
  • Loading branch information
Leonard Lyubich committed Mar 2, 2022
1 parent f4fd28e commit 51dcec9
Show file tree
Hide file tree
Showing 9 changed files with 517 additions and 362 deletions.
37 changes: 27 additions & 10 deletions container/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,26 @@ func (c *Container) FromGRPCMessage(m grpc.Message) error {
return nil
}

func toSignatureRFC6979(s *refs.Signature) *refsGRPC.SignatureRFC6979 {
var res *refsGRPC.SignatureRFC6979

if s != nil {
res = new(refsGRPC.SignatureRFC6979)
res.SetKey(s.GetKey())
res.SetSign(s.GetSign())
}

return res
}

func (r *PutRequestBody) ToGRPCMessage() grpc.Message {
var m *container.PutRequest_Body

if r != nil {
m = new(container.PutRequest_Body)

m.SetContainer(r.cnr.ToGRPCMessage().(*container.Container))
m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature))
m.SetSignatureRFC6979(toSignatureRFC6979(r.sig))
}

return m
Expand Down Expand Up @@ -195,7 +207,8 @@ func (r *PutRequestBody) FromGRPCMessage(m grpc.Message) error {
r.sig = new(refs.Signature)
}

err = r.sig.FromGRPCMessage(sig)
r.sig.SetKey(sig.GetKey())
r.sig.SetSign(sig.GetSign())
}

return err
Expand Down Expand Up @@ -391,7 +404,7 @@ func (r *GetResponseBody) ToGRPCMessage() grpc.Message {

m.SetContainer(r.cnr.ToGRPCMessage().(*container.Container))
m.SetSessionToken(r.token.ToGRPCMessage().(*sessionGRPC.SessionToken))
m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature))
m.SetSignatureRFC6979(toSignatureRFC6979(r.sig))
}

return m
Expand Down Expand Up @@ -424,7 +437,8 @@ func (r *GetResponseBody) FromGRPCMessage(m grpc.Message) error {
r.sig = new(refs.Signature)
}

err = r.sig.FromGRPCMessage(sig)
r.sig.SetKey(sig.GetKey())
r.sig.SetSign(sig.GetSign())
}

token := v.GetSessionToken()
Expand Down Expand Up @@ -486,7 +500,7 @@ func (r *DeleteRequestBody) ToGRPCMessage() grpc.Message {
m = new(container.DeleteRequest_Body)

m.SetContainerId(r.cid.ToGRPCMessage().(*refsGRPC.ContainerID))
m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature))
m.SetSignatureRFC6979(toSignatureRFC6979(r.sig))
}

return m
Expand Down Expand Up @@ -522,7 +536,8 @@ func (r *DeleteRequestBody) FromGRPCMessage(m grpc.Message) error {
r.sig = new(refs.Signature)
}

err = r.sig.FromGRPCMessage(sig)
r.sig.SetKey(sig.GetKey())
r.sig.SetSign(sig.GetSign())
}

return err
Expand Down Expand Up @@ -765,7 +780,7 @@ func (r *SetExtendedACLRequestBody) ToGRPCMessage() grpc.Message {
m = new(container.SetExtendedACLRequest_Body)

m.SetEacl(r.eacl.ToGRPCMessage().(*aclGRPC.EACLTable))
m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature))
m.SetSignatureRFC6979(toSignatureRFC6979(r.sig))
}

return m
Expand Down Expand Up @@ -801,7 +816,8 @@ func (r *SetExtendedACLRequestBody) FromGRPCMessage(m grpc.Message) error {
r.sig = new(refs.Signature)
}

err = r.sig.FromGRPCMessage(sig)
r.sig.SetKey(sig.GetKey())
r.sig.SetSign(sig.GetSign())
}

return err
Expand Down Expand Up @@ -981,7 +997,7 @@ func (r *GetExtendedACLResponseBody) ToGRPCMessage() grpc.Message {
m = new(container.GetExtendedACLResponse_Body)

m.SetEacl(r.eacl.ToGRPCMessage().(*aclGRPC.EACLTable))
m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature))
m.SetSignatureRFC6979(toSignatureRFC6979(r.sig))
m.SetSessionToken(r.token.ToGRPCMessage().(*sessionGRPC.SessionToken))
}

Expand Down Expand Up @@ -1018,7 +1034,8 @@ func (r *GetExtendedACLResponseBody) FromGRPCMessage(m grpc.Message) error {
r.sig = new(refs.Signature)
}

err = r.sig.FromGRPCMessage(sig)
r.sig.SetKey(sig.GetKey())
r.sig.SetSign(sig.GetSign())
}

token := v.GetSessionToken()
Expand Down
63 changes: 59 additions & 4 deletions container/grpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ func (m *PutRequest_Body) SetContainer(v *Container) {
}

// SetSignature sets signature of the container structure.
//
// Deprecated: (v2.12.0) use SetSignatureRFC6979 instead.
func (m *PutRequest_Body) SetSignature(v *refs.Signature) {
s := new(refs.SignatureRFC6979)
s.SetKey(v.GetKey())
s.SetSign(v.GetSign())

m.SetSignatureRFC6979(s)
}

// SetSignatureRFC6979 sets signature of the container structure.
func (m *PutRequest_Body) SetSignatureRFC6979(v *refs.SignatureRFC6979) {
if m != nil {
m.Signature = v
}
Expand Down Expand Up @@ -76,8 +87,19 @@ func (m *DeleteRequest_Body) SetContainerId(v *refs.ContainerID) {
}
}

// SetSignature sets signature of the container identifier.
// SetSignature sets signature of the container structure.
//
// Deprecated: (v2.12.0) use SetSignatureRFC6979 instead.
func (m *DeleteRequest_Body) SetSignature(v *refs.Signature) {
s := new(refs.SignatureRFC6979)
s.SetKey(v.GetKey())
s.SetSign(v.GetSign())

m.SetSignatureRFC6979(s)
}

// SetSignatureRFC6979 sets signature of the container structure.
func (m *DeleteRequest_Body) SetSignatureRFC6979(v *refs.SignatureRFC6979) {
if m != nil {
m.Signature = v
}
Expand Down Expand Up @@ -166,8 +188,19 @@ func (m *GetResponse_Body) SetSessionToken(v *session.SessionToken) {
}
}

// SetSignature sets signature of the requested container.
// SetSignature sets signature of the container structure.
//
// Deprecated: (v2.12.0) use SetSignatureRFC6979 instead.
func (m *GetResponse_Body) SetSignature(v *refs.Signature) {
s := new(refs.SignatureRFC6979)
s.SetKey(v.GetKey())
s.SetSign(v.GetSign())

m.SetSignatureRFC6979(s)
}

// SetSignatureRFC6979 sets signature of the container structure.
func (m *GetResponse_Body) SetSignatureRFC6979(v *refs.SignatureRFC6979) {
if m != nil {
m.Signature = v
}
Expand Down Expand Up @@ -257,8 +290,19 @@ func (m *SetExtendedACLRequest_Body) SetEacl(v *acl.EACLTable) {
}
}

// SetSignature sets signature of the eACL table.
// SetSignature sets signature of the container structure.
//
// Deprecated: (v2.12.0) use SetSignatureRFC6979 instead.
func (m *SetExtendedACLRequest_Body) SetSignature(v *refs.Signature) {
s := new(refs.SignatureRFC6979)
s.SetKey(v.GetKey())
s.SetSign(v.GetSign())

m.SetSignatureRFC6979(s)
}

// SetSignatureRFC6979 sets signature of the container structure.
func (m *SetExtendedACLRequest_Body) SetSignatureRFC6979(v *refs.SignatureRFC6979) {
if m != nil {
m.Signature = v
}
Expand Down Expand Up @@ -341,8 +385,19 @@ func (m *GetExtendedACLResponse_Body) SetEacl(v *acl.EACLTable) {
}
}

// SetSignature sets signature of the eACL table.
// SetSignature sets signature of the container structure.
//
// Deprecated: (v2.12.0) use SetSignatureRFC6979 instead.
func (m *GetExtendedACLResponse_Body) SetSignature(v *refs.Signature) {
s := new(refs.SignatureRFC6979)
s.SetKey(v.GetKey())
s.SetSign(v.GetSign())

m.SetSignatureRFC6979(s)
}

// SetSignatureRFC6979 sets signature of the container structure.
func (m *GetExtendedACLResponse_Body) SetSignatureRFC6979(v *refs.SignatureRFC6979) {
if m != nil {
m.Signature = v
}
Expand Down
Loading

0 comments on commit 51dcec9

Please sign in to comment.