Merge pull request #81 from nspcc-dev/service-token-owner-key

Update to neofs-api v0.7.5
This commit is contained in:
Alex Vanin 2020-05-15 16:48:08 +03:00 committed by GitHub
commit a82a2e1f57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 5 deletions

View file

@ -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 PROTO_URL=https://github.com/nspcc-dev/neofs-api/archive/$(PROTO_VERSION).tar.gz
B=\033[0;1m B=\033[0;1m

View file

@ -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 | | 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 | | Lifetime | [TokenLifetime](#service.TokenLifetime) | | Lifetime is a lifetime of the session |
| SessionKey | [bytes](#bytes) | | SessionKey is a public key of session key | | SessionKey | [bytes](#bytes) | | SessionKey is a public key of session key |
| OwnerKey | [bytes](#bytes) | | OwnerKey is a public key of the token owner |
<a name="service.TokenLifetime"></a> <a name="service.TokenLifetime"></a>

View file

@ -103,6 +103,11 @@ func (m *Token_Info) SetSessionKey(key []byte) {
m.SessionKey = key 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. // SetSignature is a Signature field setter.
func (m *Token) SetSignature(sig []byte) { func (m *Token) SetSignature(sig []byte) {
m.Signature = sig 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 { if v == nil {
return 0 return 0
} }
return fixedTokenDataSize + len(v.GetSessionKey()) return fixedTokenDataSize + len(v.GetSessionKey()) + len(v.GetOwnerKey())
} }
// Fills passed buffer with signing token information bytes. // Fills passed buffer with signing token information bytes.
@ -203,7 +208,9 @@ func copyTokenSignedData(buf []byte, token SessionTokenInfo) {
tokenEndianness.PutUint64(buf[off:], token.ExpirationEpoch()) tokenEndianness.PutUint64(buf[off:], token.ExpirationEpoch())
off += 8 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. // SignedData concatenates signed data with session token information. Returns concatenation result.

View file

@ -77,6 +77,16 @@ func TestTokenGettersSetters(t *testing.T) {
require.Equal(t, key, tok.GetSessionKey()) 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 { // Signature
sig := make([]byte, 10) sig := make([]byte, 10)
_, err := rand.Read(sig) _, err := rand.Read(sig)
@ -126,6 +136,11 @@ func TestSignToken(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
token.SetSessionKey(sessionKey) token.SetSessionKey(sessionKey)
ownerKey := make([]byte, 10)
_, err = rand.Read(ownerKey[:])
require.NoError(t, err)
token.SetOwnerKey(ownerKey)
signedToken := NewSignedSessionToken(token) signedToken := NewSignedSessionToken(token)
verifiedToken := NewVerifiedSessionToken(token) verifiedToken := NewVerifiedSessionToken(token)
@ -211,6 +226,18 @@ func TestSignToken(t *testing.T) {
token.SetSessionKey(sessionKey) 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 { for _, v := range items {

View file

@ -158,6 +158,17 @@ type SignatureContainer interface {
SetSignature([]byte) 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. // SessionTokenSource is an interface of the container of a SessionToken with read access.
type SessionTokenSource interface { type SessionTokenSource interface {
GetSessionToken() SessionToken GetSessionToken() SessionToken
@ -170,7 +181,8 @@ type SessionTokenSource interface {
// - verb of the session; // - verb of the session;
// - address of the session object; // - address of the session object;
// - token lifetime; // - token lifetime;
// - public session key bytes. // - public session key bytes;
// - owner's public key bytes.
type SessionTokenInfo interface { type SessionTokenInfo interface {
TokenIDContainer TokenIDContainer
OwnerIDContainer OwnerIDContainer
@ -178,6 +190,7 @@ type SessionTokenInfo interface {
AddressContainer AddressContainer
LifetimeContainer LifetimeContainer
SessionKeyContainer SessionKeyContainer
OwnerKeyContainer
} }
// SessionToken is an interface of token information and signature pair. // SessionToken is an interface of token information and signature pair.

Binary file not shown.

View file

@ -63,6 +63,9 @@ message Token {
// SessionKey is a public key of session key // SessionKey is a public key of session key
bytes SessionKey = 6; bytes SessionKey = 6;
// OwnerKey is a public key of the token owner
bytes OwnerKey = 7;
} }
// TokenInfo is a grouped information about token // TokenInfo is a grouped information about token