-
Notifications
You must be signed in to change notification settings - Fork 51
/
psksecrets.go
86 lines (70 loc) · 2.11 KB
/
psksecrets.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package secrets
// PSKSecrets holds the shared key.
type PSKSecrets struct {
SharedKey []byte
}
// NewPSKSecrets creates new PSK Secrets.
func NewPSKSecrets(psk []byte) *PSKSecrets {
return &PSKSecrets{SharedKey: psk}
}
// Type implements the Secrets interface.
func (p *PSKSecrets) Type() PrivateSecretsType {
return PSKType
}
// EncodingKey returns the pre-shared key.
func (p *PSKSecrets) EncodingKey() interface{} {
return p.SharedKey
}
// PublicKey returns the public key
func (p *PSKSecrets) PublicKey() interface{} {
return p.SharedKey
}
// DecodingKey returns the preshared key.
func (p *PSKSecrets) DecodingKey(server string, ackCert, prevCert interface{}) (interface{}, error) {
return p.SharedKey, nil
}
// TransmittedKey returns nil in the case of pre-shared key.
func (p *PSKSecrets) TransmittedKey() []byte {
return nil
}
// VerifyPublicKey always returns nil for pre-shared secrets.
func (p *PSKSecrets) VerifyPublicKey(pkey []byte) (interface{}, error) {
return nil, nil
}
// AckSize returns the expected size of ack packets.
func (p *PSKSecrets) AckSize() uint32 {
return uint32(237)
}
// AuthPEM returns the Certificate Authority PEM.
func (p *PSKSecrets) AuthPEM() []byte {
return p.SharedKey
}
// TransmittedPEM returns the PEM certificate that is transmitted.
func (p *PSKSecrets) TransmittedPEM() []byte {
return p.SharedKey
}
// EncodingPEM returns the certificate PEM that is used for encoding.
func (p *PSKSecrets) EncodingPEM() []byte {
return p.SharedKey
}
// PublicSecrets returns the secrets that are marshallable over the RPC interface.
func (p *PSKSecrets) PublicSecrets() PublicSecrets {
return &PSKPublicSecrets{
Type: PSKType,
SharedKey: p.SharedKey,
}
}
// PSKPublicSecrets includes all the secrets that can be transmitted over
// the RPC interface.
type PSKPublicSecrets struct {
Type PrivateSecretsType
SharedKey []byte
}
// SecretsType returns the type of secrets.
func (p *PSKPublicSecrets) SecretsType() PrivateSecretsType {
return p.Type
}
// CertAuthority returns the cert authority - N/A to PSK
func (p *PSKPublicSecrets) CertAuthority() []byte {
return []byte{}
}