forked from TrueCloudLab/frostfs-node
[#1255] node/session: Rename constant
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
90a8c52bdb
commit
6ec104d686
2 changed files with 6 additions and 17 deletions
|
@ -3,7 +3,6 @@ package persistent
|
||||||
import (
|
import (
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/x509"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
@ -62,20 +61,10 @@ func NewTokenStore(path string, opts ...Option) (*TokenStore, error) {
|
||||||
// enable encryption if it
|
// enable encryption if it
|
||||||
// was configured so
|
// was configured so
|
||||||
if cfg.privateKey != nil {
|
if cfg.privateKey != nil {
|
||||||
rawKey, err := x509.MarshalECPrivateKey(cfg.privateKey)
|
rawKey := make([]byte, (cfg.privateKey.Curve.Params().N.BitLen()+7)/8)
|
||||||
if err != nil {
|
cfg.privateKey.D.FillBytes(rawKey)
|
||||||
return nil, fmt.Errorf("could not marshal provided private key: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// tagOffset is a constant offset for
|
c, err := aes.NewCipher(rawKey)
|
||||||
// tags when marshalling ECDSA key in
|
|
||||||
// ASN.1 DER form
|
|
||||||
const tagOffset = 7
|
|
||||||
|
|
||||||
// using first 32 bytes from
|
|
||||||
// the marshalled private key
|
|
||||||
// as a secret
|
|
||||||
c, err := aes.NewCipher(rawKey[tagOffset : tagOffset+32])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not create cipher block: %w", err)
|
return nil, fmt.Errorf("could not create cipher block: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const expOffset = 8
|
const keyOffset = 8
|
||||||
|
|
||||||
func (s *TokenStore) packToken(exp uint64, key *ecdsa.PrivateKey) ([]byte, error) {
|
func (s *TokenStore) packToken(exp uint64, key *ecdsa.PrivateKey) ([]byte, error) {
|
||||||
rawKey, err := x509.MarshalECPrivateKey(key)
|
rawKey, err := x509.MarshalECPrivateKey(key)
|
||||||
|
@ -25,7 +25,7 @@ func (s *TokenStore) packToken(exp uint64, key *ecdsa.PrivateKey) ([]byte, error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res := make([]byte, expOffset, expOffset+len(rawKey))
|
res := make([]byte, keyOffset, keyOffset+len(rawKey))
|
||||||
binary.LittleEndian.PutUint64(res, exp)
|
binary.LittleEndian.PutUint64(res, exp)
|
||||||
|
|
||||||
res = append(res, rawKey...)
|
res = append(res, rawKey...)
|
||||||
|
@ -37,7 +37,7 @@ func (s *TokenStore) unpackToken(raw []byte) (*storage.PrivateToken, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
epoch := epochFromToken(raw)
|
epoch := epochFromToken(raw)
|
||||||
rawKey := raw[expOffset:]
|
rawKey := raw[keyOffset:]
|
||||||
|
|
||||||
if s.gcm != nil {
|
if s.gcm != nil {
|
||||||
rawKey, err = s.decrypt(rawKey)
|
rawKey, err = s.decrypt(rawKey)
|
||||||
|
|
Loading…
Reference in a new issue