Skip to content

Commit

Permalink
session: Add getter of binary-encoded public key from signature
Browse files Browse the repository at this point in the history
Signature is used for user authentication so access to public key is
required. Digital signature bytes may still be unexported because they
are only useful for `VerifySignature` method.

Add `IssuerPublicKeyBytes` method returning binary-encoded public key of
the session issuer.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Aug 3, 2023
1 parent 75dfaef commit 3ba061e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions session/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,14 @@ func (x commonData) Issuer() user.ID {

return user.ID{}
}

// IssuerPublicKeyBytes returns binary-encoded public key of the session issuer.
//
// IssuerPublicKeyBytes MUST NOT be called before ReadFromV2 or Sign methods.
func (x *commonData) IssuerPublicKeyBytes() []byte {
if x.sigSet {
return x.sig.GetKey()
}

return nil
}
9 changes: 9 additions & 0 deletions session/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,15 @@ func TestContainer_Issuer(t *testing.T) {
token.SetIssuer(issuer)
require.True(t, token.Issuer().Equals(issuer))
})

t.Run("public key", func(t *testing.T) {
signer := test.RandomSignerRFC6979(t)

require.Nil(t, token.IssuerPublicKeyBytes())
require.NoError(t, token.Sign(signer))

require.Equal(t, neofscrypto.PublicKeyBytes(signer.Public()), token.IssuerPublicKeyBytes())
})
}

func TestContainer_Sign(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions session/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,14 @@ func TestObject_Issuer(t *testing.T) {
signer := test.RandomSignerRFC6979(t)

require.Zero(t, token.Issuer())
require.Nil(t, token.IssuerPublicKeyBytes())

require.NoError(t, token.Sign(signer))

issuer := signer.UserID()

require.True(t, token.Issuer().Equals(issuer))
require.Equal(t, neofscrypto.PublicKeyBytes(signer.Public()), token.IssuerPublicKeyBytes())
}

func TestObject_Sign(t *testing.T) {
Expand Down

0 comments on commit 3ba061e

Please sign in to comment.