diff --git a/Makefile b/Makefile index b99682b..6b1ab7a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PROTO_VERSION=v0.7.4 +PROTO_VERSION=v0.7.5 PROTO_URL=https://github.com/nspcc-dev/neofs-api/archive/$(PROTO_VERSION).tar.gz B=\033[0;1m diff --git a/docs/service.md b/docs/service.md index 9ed548e..0765f04 100644 --- a/docs/service.md +++ b/docs/service.md @@ -132,6 +132,7 @@ User token granting rights for object manipulation | Address | [refs.Address](#refs.Address) | | Address is an object address for which token is issued | | Lifetime | [TokenLifetime](#service.TokenLifetime) | | Lifetime is a lifetime of the session | | SessionKey | [bytes](#bytes) | | SessionKey is a public key of session key | +| OwnerKey | [bytes](#bytes) | | OwnerKey is a public key of the token owner | diff --git a/service/token.go b/service/token.go index cce1059..a5dd5da 100644 --- a/service/token.go +++ b/service/token.go @@ -103,6 +103,11 @@ func (m *Token_Info) SetSessionKey(key []byte) { m.SessionKey = key } +// SetOwnerKey is an OwnerKey field setter. +func (m *Token_Info) SetOwnerKey(key []byte) { + m.OwnerKey = key +} + // SetSignature is a Signature field setter. func (m *Token) SetSignature(sig []byte) { m.Signature = sig @@ -169,11 +174,11 @@ func NewVerifiedSessionToken(token SessionToken) DataWithSignature { } } -func tokenInfoSize(v SessionKeySource) int { +func tokenInfoSize(v SessionTokenInfo) int { if v == nil { return 0 } - return fixedTokenDataSize + len(v.GetSessionKey()) + return fixedTokenDataSize + len(v.GetSessionKey()) + len(v.GetOwnerKey()) } // Fills passed buffer with signing token information bytes. @@ -203,7 +208,9 @@ func copyTokenSignedData(buf []byte, token SessionTokenInfo) { tokenEndianness.PutUint64(buf[off:], token.ExpirationEpoch()) off += 8 - copy(buf[off:], token.GetSessionKey()) + off += copy(buf[off:], token.GetSessionKey()) + + copy(buf[off:], token.GetOwnerKey()) } // SignedData concatenates signed data with session token information. Returns concatenation result. diff --git a/service/token_test.go b/service/token_test.go index e8599e7..43e380d 100644 --- a/service/token_test.go +++ b/service/token_test.go @@ -77,6 +77,16 @@ func TestTokenGettersSetters(t *testing.T) { require.Equal(t, key, tok.GetSessionKey()) } + { + key := make([]byte, 10) + _, err := rand.Read(key) + require.NoError(t, err) + + tok.SetOwnerKey(key) + + require.Equal(t, key, tok.GetOwnerKey()) + } + { // Signature sig := make([]byte, 10) _, err := rand.Read(sig) @@ -126,6 +136,11 @@ func TestSignToken(t *testing.T) { require.NoError(t, err) token.SetSessionKey(sessionKey) + ownerKey := make([]byte, 10) + _, err = rand.Read(ownerKey[:]) + require.NoError(t, err) + token.SetOwnerKey(ownerKey) + signedToken := NewSignedSessionToken(token) verifiedToken := NewVerifiedSessionToken(token) @@ -211,6 +226,18 @@ func TestSignToken(t *testing.T) { token.SetSessionKey(sessionKey) }, }, + { // Owner key + corrupt: func() { + ownerKey := token.GetOwnerKey() + ownerKey[0]++ + token.SetOwnerKey(ownerKey) + }, + restore: func() { + ownerKey := token.GetOwnerKey() + ownerKey[0]-- + token.SetOwnerKey(ownerKey) + }, + }, } for _, v := range items { diff --git a/service/types.go b/service/types.go index 31f4507..66582f5 100644 --- a/service/types.go +++ b/service/types.go @@ -158,6 +158,17 @@ type SignatureContainer interface { SetSignature([]byte) } +// OwnerKeySource is an interface of the container of owner key bytes with read access. +type OwnerKeySource interface { + GetOwnerKey() []byte +} + +// OwnerKeyContainer is an interface of the container of owner key bytes. +type OwnerKeyContainer interface { + OwnerKeySource + SetOwnerKey([]byte) +} + // SessionTokenSource is an interface of the container of a SessionToken with read access. type SessionTokenSource interface { GetSessionToken() SessionToken @@ -170,7 +181,8 @@ type SessionTokenSource interface { // - verb of the session; // - address of the session object; // - token lifetime; -// - public session key bytes. +// - public session key bytes; +// - owner's public key bytes. type SessionTokenInfo interface { TokenIDContainer OwnerIDContainer @@ -178,6 +190,7 @@ type SessionTokenInfo interface { AddressContainer LifetimeContainer SessionKeyContainer + OwnerKeyContainer } // SessionToken is an interface of token information and signature pair. diff --git a/service/verify.pb.go b/service/verify.pb.go index 3dadf0b..d198302 100644 --- a/service/verify.pb.go +++ b/service/verify.pb.go @@ -239,7 +239,9 @@ type Token_Info struct { // Lifetime is a lifetime of the session TokenLifetime `protobuf:"bytes,5,opt,name=Lifetime,proto3,embedded=Lifetime" json:"Lifetime"` // SessionKey is a public key of session key - SessionKey []byte `protobuf:"bytes,6,opt,name=SessionKey,proto3" json:"SessionKey,omitempty"` + SessionKey []byte `protobuf:"bytes,6,opt,name=SessionKey,proto3" json:"SessionKey,omitempty"` + // OwnerKey is a public key of the token owner + OwnerKey []byte `protobuf:"bytes,7,opt,name=OwnerKey,proto3" json:"OwnerKey,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -288,6 +290,13 @@ func (m *Token_Info) GetSessionKey() []byte { return nil } +func (m *Token_Info) GetOwnerKey() []byte { + if m != nil { + return m.OwnerKey + } + return nil +} + // TokenLifetime carries a group of lifetime parameters of the token type TokenLifetime struct { // Created carries an initial epoch of token lifetime @@ -354,43 +363,44 @@ func init() { func init() { proto.RegisterFile("service/verify.proto", fileDescriptor_4bdd5bc50ec96238) } var fileDescriptor_4bdd5bc50ec96238 = []byte{ - // 567 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x53, 0x4d, 0x6f, 0xd3, 0x40, - 0x10, 0xed, 0x26, 0xce, 0xd7, 0xf4, 0x03, 0xb3, 0x20, 0x64, 0x22, 0x94, 0x44, 0x11, 0x87, 0x54, - 0x22, 0x8e, 0x94, 0x4a, 0x08, 0x09, 0x2e, 0x0d, 0x11, 0x34, 0xa2, 0x82, 0x6a, 0x53, 0x7a, 0xe0, - 0xe6, 0xd8, 0x63, 0x77, 0x45, 0xeb, 0x0d, 0xbb, 0x9b, 0xa0, 0xfe, 0x13, 0x7e, 0x03, 0xbf, 0x83, - 0x43, 0x8f, 0x3d, 0x22, 0x24, 0x22, 0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 0x3c, 0xc4, 0x0b, 0xd4, 0x68, 0x5b, 0xb4, 0x06, 0x25, 0xe6, 0xc5, 0x11, 0xda, 0x25, - 0xba, 0x0b, 0x35, 0x03, 0x8f, 0x3c, 0x75, 0x6e, 0x97, 0xdb, 0x23, 0xd8, 0xbd, 0x15, 0x8d, 0x3a, - 0x50, 0x79, 0x29, 0xd1, 0xd3, 0x18, 0x98, 0xff, 0xc1, 0x62, 0xab, 0x32, 0x09, 0x78, 0xe6, 0x5d, - 0xf0, 0xe0, 0x7d, 0xac, 0xf9, 0x85, 0x39, 0xbf, 0xc5, 0x72, 0xcc, 0x60, 0x7c, 0xbd, 0x6c, 0x90, - 0x9b, 0x65, 0x83, 0x7c, 0x5f, 0x36, 0xc8, 0xaf, 0x65, 0x83, 0x7c, 0xf9, 0xdd, 0xd8, 0xfa, 0xb0, - 0x9f, 0x7b, 0x36, 0xb1, 0x9a, 0xfa, 0x7e, 0x37, 0xc0, 0x79, 0x2f, 0x46, 0x11, 0xaa, 0xae, 0x37, - 0xe5, 0xdd, 0x48, 0xf4, 0xb2, 0x1b, 0x7d, 0x2d, 0xdc, 0x7d, 0x8b, 0xe2, 0xd5, 0xd8, 0x3d, 0x3c, - 0x19, 0xb9, 0xe3, 0x94, 0x9b, 0x94, 0xcd, 0x6b, 0x3a, 0xf8, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x13, - 0xf0, 0xba, 0xcc, 0xaf, 0x03, 0x00, 0x00, + // 579 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x53, 0x4f, 0x6f, 0x12, 0x41, + 0x14, 0xef, 0xc0, 0xc2, 0xc2, 0xeb, 0x1f, 0xd7, 0xd1, 0x98, 0x95, 0x18, 0x20, 0xc4, 0x03, 0x4d, + 0x64, 0x49, 0x68, 0x62, 0x4c, 0xf4, 0x52, 0x24, 0x5a, 0x62, 0xa3, 0xcd, 0x50, 0x7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9, 0xba, 0x36, 0xbb, 0x8e, 0x1b, 0xa7, 0x60, + 0x4f, 0x40, 0x5d, 0xc8, 0x9f, 0xcc, 0xb4, 0xb7, 0x65, 0xc0, 0x6b, 0xd4, 0x1e, 0xa1, 0x25, 0x70, + 0xcc, 0xd3, 0xf1, 0x72, 0x14, 0xa0, 0x38, 0xc0, 0x50, 0x8e, 0xce, 0xbd, 0xbc, 0xc1, 0x3d, 0xbc, + 0x40, 0x8d, 0x9e, 0x43, 0xcb, 0x50, 0x60, 0x61, 0x1c, 0xa1, 0x57, 0xa0, 0xbb, 0x50, 0xb6, 0xf0, + 0x28, 0x54, 0xe7, 0x5e, 0xb1, 0xd1, 0x87, 0xdd, 0x5b, 0x63, 0x53, 0x1f, 0xdc, 0x97, 0x12, 0x43, + 0x8d, 0x63, 0x7b, 0x47, 0x0e, 0x5b, 0x85, 0x66, 0xf8, 0xb3, 0xf0, 0x82, 0x8f, 0xdf, 0xc7, 0x9a, + 0x5f, 0xd8, 0xab, 0x71, 0x58, 0x86, 0xe9, 0x0e, 0xae, 0x97, 0x55, 0x72, 0xb3, 0xac, 0x92, 0x1f, + 0xcb, 0x2a, 0xf9, 0xb5, 0xac, 0x92, 0xaf, 0xbf, 0xab, 0x5b, 0x1f, 0xf6, 0x33, 0x5f, 0x2a, 0x56, + 0xd3, 0xd1, 0xa8, 0x35, 0xc6, 0x79, 0x3b, 0x46, 0x31, 0x51, 0xad, 0x70, 0xca, 0x5b, 0x91, 0x68, + 0xa7, 0xfb, 0xfb, 0x96, 0xbb, 0xfb, 0x16, 0xc5, 0xab, 0x41, 0x70, 0x78, 0xd2, 0x0f, 0x06, 0x09, + 0x37, 0x2c, 0xda, 0x9f, 0x76, 0xf0, 0x37, 0x00, 0x00, 0xff, 0xff, 0xcb, 0xab, 0x17, 0xd9, 0xcb, + 0x03, 0x00, 0x00, } func (m *RequestVerificationHeader) Marshal() (dAtA []byte, err error) { @@ -555,6 +565,13 @@ func (m *Token_Info) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= len(m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized) } + if len(m.OwnerKey) > 0 { + i -= len(m.OwnerKey) + copy(dAtA[i:], m.OwnerKey) + i = encodeVarintVerify(dAtA, i, uint64(len(m.OwnerKey))) + i-- + dAtA[i] = 0x3a + } if len(m.SessionKey) > 0 { i -= len(m.SessionKey) copy(dAtA[i:], m.SessionKey) @@ -739,6 +756,10 @@ func (m *Token_Info) Size() (n int) { if l > 0 { n += 1 + l + sovVerify(uint64(l)) } + l = len(m.OwnerKey) + if l > 0 { + n += 1 + l + sovVerify(uint64(l)) + } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -1350,6 +1371,40 @@ func (m *Token_Info) Unmarshal(dAtA []byte) error { m.SessionKey = []byte{} } iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OwnerKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVerify + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthVerify + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthVerify + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OwnerKey = append(m.OwnerKey[:0], dAtA[iNdEx:postIndex]...) + if m.OwnerKey == nil { + m.OwnerKey = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipVerify(dAtA[iNdEx:]) diff --git a/service/verify.proto b/service/verify.proto index ed360be..a6619a6 100644 --- a/service/verify.proto +++ b/service/verify.proto @@ -63,6 +63,9 @@ message Token { // SessionKey is a public key of session key bytes SessionKey = 6; + + // OwnerKey is a public key of the token owner + bytes OwnerKey = 7; } // TokenInfo is a grouped information about token