-
Notifications
You must be signed in to change notification settings - Fork 2
/
profile.go
62 lines (49 loc) · 1.34 KB
/
profile.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
package profile
import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
)
type Profile struct {
baseConfig string
privateKey *rsa.PrivateKey
certificate []byte
}
func NewProfile(baseConfig string, privateKey *rsa.PrivateKey, certificate []byte) Profile {
return Profile{
baseConfig: baseConfig,
privateKey: privateKey,
certificate: certificate,
}
}
func (p Profile) CertificatePEM() []byte {
return p.certificate
}
func (p Profile) BaseConfig() string {
return p.baseConfig
}
func (p Profile) StaticConfig() string {
config := p.baseConfig
// inline key-pair
config = fmt.Sprintf("%s\n<key>\n%s\n</key>\n", config, p.privateKeyPEM())
config = fmt.Sprintf("%s\n<cert>\n%s\n</cert>\n", config, p.certificate)
return config
}
func (p Profile) ManagementConfig(managementAddress string) string {
config := p.baseConfig
// management configuration
config = fmt.Sprintf("%s\nmanagement %s\nmanagement-client\n", config, managementAddress)
config = fmt.Sprintf("%s\nmanagement-external-cert ssoca\nmanagement-external-key\n", config)
// force connection resets to flush credentials
config = fmt.Sprintf("%s\nremap-usr1 SIGHUP\n", config)
return config
}
func (p Profile) privateKeyPEM() []byte {
return pem.EncodeToMemory(
&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(p.privateKey),
},
)
}