-
Notifications
You must be signed in to change notification settings - Fork 53
/
keys.go
59 lines (48 loc) · 1.21 KB
/
keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package keyring
import (
"crypto/x509"
"slices"
"github.com/rancher/opni/pkg/keyring/ephemeral"
"github.com/rancher/opni/pkg/pkp"
)
// Key types are used indirectly via an interface, as most key values would
// benefit from extra accessor logic (e.g. copying raw byte arrays).
type SharedKeys struct {
ClientKey []byte `json:"clientKey"`
ServerKey []byte `json:"serverKey"`
}
type PKPKey struct {
PinnedKeys []*pkp.PublicKeyPin `json:"pinnedKeys"`
}
type CACertsKey struct {
// DER-encoded certificates
CACerts [][]byte `json:"caCerts"`
}
type EphemeralKey = ephemeral.Key
func NewSharedKeys(secret []byte) *SharedKeys {
if len(secret) != 64 {
panic("shared secret must be 64 bytes")
}
return &SharedKeys{
ClientKey: secret[:32],
ServerKey: secret[32:],
}
}
func NewPKPKey(pinnedKeys []*pkp.PublicKeyPin) *PKPKey {
key := &PKPKey{
PinnedKeys: make([]*pkp.PublicKeyPin, len(pinnedKeys)),
}
for i, pinnedKey := range pinnedKeys {
key.PinnedKeys[i] = pinnedKey.DeepCopy()
}
return key
}
func NewCACertsKey(certs []*x509.Certificate) *CACertsKey {
key := &CACertsKey{
CACerts: make([][]byte, len(certs)),
}
for i, cert := range certs {
key.CACerts[i] = slices.Clone(cert.Raw)
}
return key
}