-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypair.go
52 lines (43 loc) · 1.18 KB
/
keypair.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
package tls
import (
"fmt"
"github.com/openshift/installer/pkg/asset"
)
// KeyPair implements the Asset interface and
// generates an RSA public/private key pair.
type KeyPair struct {
PrivKeyFileName string
PubKeyFileName string
}
var _ asset.Asset = (*KeyPair)(nil)
// Dependencies returns the dependency of an rsa private / public key pair.
func (k *KeyPair) Dependencies() []asset.Asset {
return []asset.Asset{}
}
// Generate generates the rsa private / public key pair.
func (k *KeyPair) Generate(map[asset.Asset]*asset.State) (*asset.State, error) {
key, err := PrivateKey()
if err != nil {
return nil, fmt.Errorf("failed to generate private key: %v", err)
}
pubkeyData, err := PublicKeyToPem(&key.PublicKey)
if err != nil {
return nil, fmt.Errorf("failed to get public key data: %v", err)
}
return &asset.State{
Contents: []asset.Content{
{
Name: assetFilePath(k.PrivKeyFileName),
Data: []byte(PrivateKeyToPem(key)),
},
{
Name: assetFilePath(k.PubKeyFileName),
Data: []byte(pubkeyData),
},
},
}, nil
}
// Name returns the human-friendly name of the asset.
func (k *KeyPair) Name() string {
return fmt.Sprintf("Key Pair (%s)", k.PubKeyFileName)
}