Files
threshold/internal/session/util.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
974 B
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
2023-02-02 17:15:17 -08:00
// SPDX-License-Identifier: BUSL-1.1
2020-09-16 12:02:02 -04:00
package session
2020-09-03 13:24:34 -04:00
import (
"context"
2020-09-03 13:24:34 -04:00
"crypto/ed25519"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/libs/crypto"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
2020-09-03 13:24:34 -04:00
)
2022-07-20 16:24:46 -07:00
// DeriveED25519Key generates a key based on the project's session DEK, the
2020-09-03 13:24:34 -04:00
// requesting user, and the generated job ID.
func DeriveED25519Key(ctx context.Context, wrapper wrapping.Wrapper, userId, jobId string) (ed25519.PublicKey, ed25519.PrivateKey, error) {
const op = "session.DeriveED25519Key"
2021-04-08 20:54:32 -04:00
var uId, jId []byte
if userId != "" {
uId = []byte(userId)
2020-09-03 13:24:34 -04:00
}
2021-04-08 20:54:32 -04:00
if jobId != "" {
jId = []byte(jobId)
2020-09-03 13:24:34 -04:00
}
if wrapper == nil {
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "missing wrapper")
}
2021-04-08 20:54:32 -04:00
reader, err := crypto.NewDerivedReader(ctx, wrapper, 32, uId, jId)
if err != nil {
return nil, nil, errors.Wrap(ctx, err, op)
}
2021-04-08 20:54:32 -04:00
return ed25519.GenerateKey(reader)
2020-09-03 13:24:34 -04:00
}