2024-08-12 14:11:10 +00:00
|
|
|
package patchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/elliptic"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
|
2024-08-12 14:11:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newOwnerID(vh *session.RequestVerificationHeader) (*refs.OwnerID, error) {
|
|
|
|
for vh.GetOrigin() != nil {
|
|
|
|
vh = vh.GetOrigin()
|
|
|
|
}
|
|
|
|
sig := vh.GetBodySignature()
|
|
|
|
if sig == nil {
|
|
|
|
return nil, errors.New("empty body signature")
|
|
|
|
}
|
|
|
|
key, err := keys.NewPublicKeyFromBytes(sig.GetKey(), elliptic.P256())
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid signature key: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var userID user.ID
|
|
|
|
user.IDFromKey(&userID, (ecdsa.PublicKey)(*key))
|
|
|
|
ownID := new(refs.OwnerID)
|
|
|
|
userID.WriteToV2(ownID)
|
|
|
|
|
|
|
|
return ownID, nil
|
|
|
|
}
|