Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package session
|
|
|
|
import (
|
|
"context"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
|
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
|
|
"github.com/hashicorp/go-kms-wrapping/v2/extras/structwrapping"
|
|
)
|
|
|
|
// Credential represents the credential data which is sent to the worker.
|
|
type Credential []byte
|
|
|
|
type credential struct {
|
|
SessionId string `gorm:"index:,unique,composite:session_credential_session_id_credential_sha256_uq"`
|
|
KeyId string
|
|
Credential []byte `gorm:"-" wrapping:"pt,credential_data"`
|
|
CtCredential []byte `gorm:"column:credential" wrapping:"ct,credential_data"`
|
|
CredentialSha256 []byte `gorm:"index:,unique,composite:session_credential_session_id_credential_sha256_uq"`
|
|
}
|
|
|
|
// TableName returns the table name.
|
|
func (c *credential) TableName() string {
|
|
return "session_credential"
|
|
}
|
|
|
|
func (c *credential) encrypt(ctx context.Context, cipher wrapping.Wrapper) error {
|
|
const op = "session.(credential).encrypt"
|
|
if err := structwrapping.WrapStruct(ctx, cipher, c, nil); err != nil {
|
|
return errors.Wrap(ctx, err, op, errors.WithCode(errors.Encrypt))
|
|
}
|
|
var err error
|
|
c.KeyId, err = cipher.KeyId(ctx)
|
|
if err != nil {
|
|
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to discover wrapper key id"))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *credential) decrypt(ctx context.Context, cipher wrapping.Wrapper) error {
|
|
const op = "session.(credential).decrypt"
|
|
if err := structwrapping.UnwrapStruct(ctx, cipher, c, nil); err != nil {
|
|
return errors.Wrap(ctx, err, op, errors.WithCode(errors.Decrypt))
|
|
}
|
|
return nil
|
|
}
|