1+ // SSH Manager module for generating secure SSH key pairs and configurations.
12package main
23
34import (
@@ -15,89 +16,22 @@ import (
1516 "golang.org/x/crypto/ssh"
1617)
1718
18- type SshManager struct {}
19+ // SshManager provides services to generate and manage SSH identities.
20+ type SshManager struct {} //revive:disable-line
1921
22+ // KeyResult represents the collection of generated SSH components.
2023type KeyResult struct {
21- PublicKey * dagger.File `json:"publicKey"`
22- PrivateKey * dagger.Secret `json:"privateKey"`
23- Config * dagger.File `json:"config"`
24- Files * dagger.Directory `json:"files"`
24+ // The OpenSSH formatted public key file.
25+ PublicKey * dagger.File `json:"publicKey"`
26+ // The OpenSSH formatted private key, stored as a secret.
27+ PrivateKey * dagger.Secret `json:"privateKey"`
28+ // The SSH configuration file containing host and proxy settings.
29+ Config * dagger.File `json:"config"`
30+ // A directory containing the private key, public key, and config for easy export.
31+ Files * dagger.Directory `json:"files"`
2532}
2633
27- // func (m *SshManager) GenerateRsa(
28- // ctx context.Context,
29- // remoteHost string,
30- // remoteUser string,
31- // // +optional
32- // // +default="dagger"
33- // localHostname string,
34- // // +optional
35- // // +default=4096
36- // bits int,
37- // // +optional
38- // autoPassphrase bool,
39- // // +optional
40- // existingConfig *dagger.File,
41- // ) (*KeyResult, error) {
42- // priv, err := rsa.GenerateKey(rand.Reader, bits)
43- // if err != nil {
44- // return nil, err
45- // }
46- // return m.finalize(ctx, priv, priv.Public(), "rsa", remoteHost, remoteUser, localHostname, autoPassphrase, existingConfig)
47- // }
48-
49- /* func (m *SshManager) GenerateEd25519(
50- ctx context.Context,
51- remoteHost string,
52- remoteUser string,
53- // +optional
54- // +default="dagger"
55- localHostname string,
56- // +optional
57- autoPassphrase bool,
58- // +optional
59- existingConfig *dagger.File,
60- ) (*KeyResult, error) {
61- pub, priv, err := ed25519.GenerateKey(rand.Reader)
62- if err != nil {
63- return nil, err
64- }
65- return m.finalize(ctx, priv, pub, "ed25519", remoteHost, remoteUser, localHostname, autoPassphrase, existingConfig)
66- } */
67-
68- // func (m *SshManager) GenerateEcdsa(
69- // ctx context.Context,
70- // remoteHost string,
71- // remoteUser string,
72- // // +optional
73- // // +default="dagger"
74- // localHostname string,
75- // // +optional
76- // // +default=521
77- // bits int,
78- // // +optional
79- // autoPassphrase bool,
80- // // +optional
81- // existingConfig *dagger.File,
82- // ) (*KeyResult, error) {
83- // var curve elliptic.Curve
84- // switch bits {
85- // case 256:
86- // curve = elliptic.P256()
87- // case 384:
88- // curve = elliptic.P384()
89- // case 521:
90- // curve = elliptic.P521()
91- // default:
92- // return nil, fmt.Errorf("invalid bits for ecdsa")
93- // }
94- // priv, err := ecdsa.GenerateKey(curve, rand.Reader)
95- // if err != nil {
96- // return nil, err
97- // }
98- // return m.finalize(ctx, priv, priv.Public(), "ecdsa", remoteHost, remoteUser, localHostname, autoPassphrase, existingConfig)
99- // }
100-
34+ // finalize is an internal helper to process raw keys into formatted files and secrets.
10135func (m * SshManager ) finalize (
10236 ctx context.Context ,
10337 priv any ,
@@ -169,6 +103,7 @@ func (m *SshManager) finalize(
169103 }, nil
170104}
171105
106+ // randomString generates a cryptographically secure random string for passphrases.
172107func (m * SshManager ) randomString (n int ) string {
173108 const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()"
174109 ret := make ([]byte , n )
0 commit comments