Files
threshold/internal/session/util.go
T

28 lines
738 B
Go
Raw Normal View History

2020-09-16 12:02:02 -04:00
package session
2020-09-03 13:24:34 -04:00
import (
"crypto/ed25519"
"github.com/hashicorp/boundary/internal/errors"
2021-04-08 20:54:32 -04:00
"github.com/hashicorp/boundary/internal/kms"
2020-09-03 13:24:34 -04:00
wrapping "github.com/hashicorp/go-kms-wrapping"
)
2020-09-16 12:02:02 -04:00
// DeriveED25519Key generates a key based on the scope's session DEK, the
2020-09-03 13:24:34 -04:00
// requesting user, and the generated job ID.
func DeriveED25519Key(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
}
2021-04-08 20:54:32 -04:00
reader, err := kms.NewDerivedReader(wrapper, 32, uId, jId)
if err != nil {
2021-04-08 20:54:32 -04:00
return nil, nil, errors.Wrap(err, op)
}
2021-04-08 20:54:32 -04:00
return ed25519.GenerateKey(reader)
2020-09-03 13:24:34 -04:00
}