Skip to content

Commit

Permalink
api: Replace the private key with slicer completely
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Aug 9, 2023
1 parent 141497b commit a443041
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 0 additions & 2 deletions handlers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
type API struct {
log *zap.Logger
pool *pool.Pool
key *keys.PrivateKey
owner *user.ID
signer user.Signer
defaultTimestamp bool
Expand Down Expand Up @@ -82,7 +81,6 @@ func New(prm *PrmAPI) *API {
return &API{
log: prm.Logger,
pool: prm.Pool,
key: prm.Key,
signer: signer,

Check warning on line 84 in handlers/api.go

View check run for this annotation

Codecov / codecov/patch

handlers/api.go#L84

Added line #L84 was not covered by tests
owner: &owner,
defaultTimestamp: prm.DefaultTimestamp,
Expand Down
10 changes: 4 additions & 6 deletions handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import (

"github.com/go-openapi/runtime/middleware"
"github.com/google/uuid"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-api-go/v2/acl"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
sessionv2 "github.com/nspcc-dev/neofs-api-go/v2/session"
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
"github.com/nspcc-dev/neofs-rest-gw/internal/util"
"github.com/nspcc-dev/neofs-sdk-go/client"
neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa"
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
"github.com/nspcc-dev/neofs-sdk-go/pool"
"github.com/nspcc-dev/neofs-sdk-go/user"
)
Expand Down Expand Up @@ -93,7 +92,7 @@ func (a *API) PostAuth(params operations.AuthParams) middleware.Responder {
response[i], err = prepareObjectToken(ctx, prm, a.pool, *a.owner)
} else {
prm := newContainerParams(commonPrm, token)
response[i], err = prepareContainerTokens(ctx, prm, a.pool, a.key.PublicKey())
response[i], err = prepareContainerTokens(ctx, prm, a.pool, a.signer.Public())

Check warning on line 95 in handlers/auth.go

View check run for this annotation

Codecov / codecov/patch

handlers/auth.go#L95

Added line #L95 was not covered by tests
}
if err != nil {
return operations.NewAuthBadRequest().WithPayload(util.NewErrorResponse(err))
Expand Down Expand Up @@ -148,7 +147,7 @@ func prepareObjectToken(ctx context.Context, params objectTokenParams, pool *poo
}, nil
}

func prepareContainerTokens(ctx context.Context, params containerTokenParams, pool *pool.Pool, key *keys.PublicKey) (*models.TokenResponse, error) {
func prepareContainerTokens(ctx context.Context, params containerTokenParams, pool *pool.Pool, pubKey neofscrypto.PublicKey) (*models.TokenResponse, error) {

Check warning on line 150 in handlers/auth.go

View check run for this annotation

Codecov / codecov/patch

handlers/auth.go#L150

Added line #L150 was not covered by tests
iat, exp, err := getTokenLifetime(ctx, pool, params.XBearerLifetime)
if err != nil {
return nil, fmt.Errorf("couldn't get lifetime: %w", err)
Expand All @@ -168,8 +167,7 @@ func prepareContainerTokens(ctx context.Context, params containerTokenParams, po
stoken.SetIat(iat)
stoken.SetExp(exp)

authKey := neofsecdsa.PublicKey(*key)
stoken.SetAuthKey(&authKey)
stoken.SetAuthKey(pubKey)

Check warning on line 170 in handlers/auth.go

View check run for this annotation

Codecov / codecov/patch

handlers/auth.go#L170

Added line #L170 was not covered by tests

var v2token sessionv2.Token
stoken.WriteToV2(&v2token)
Expand Down

0 comments on commit a443041

Please sign in to comment.