Files
threshold/internal/session/credential.go
T
Louis Ruch 5fe23ab14d feat(session): Store session credentials
Creates a new session_credential table and repository functions
to add and list credentials attached to a session. All credentials
are encrypted using the session scope id.
2021-12-17 11:26:52 -08:00

42 lines
1.2 KiB
Go

package session
import (
"context"
"github.com/hashicorp/boundary/internal/errors"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/hashicorp/go-kms-wrapping/structwrapping"
)
// Credential represents the credential data which is sent to the worker.
type Credential []byte
type credential struct {
SessionId string
KeyId string
Credential []byte `gorm:"-" wrapping:"pt,credential_data"`
CtCredential []byte `gorm:"column:credential" wrapping:"ct,credential_data"`
}
// 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))
}
c.KeyId = cipher.KeyID()
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
}