MCPcopy Create free account
hub / github.com/appleboy/easyssh-proxy / getSSHConfig

Function getSSHConfig

easyssh.go:142–213  ·  view source on GitHub ↗

returns *ssh.ClientConfig and io.Closer. if io.Closer is not nil, io.Closer.Close() should be called when *ssh.ClientConfig is no longer used.

(config DefaultConfig)

Source from the content-addressed store, hash-verified

140// if io.Closer is not nil, io.Closer.Close() should be called when
141// *ssh.ClientConfig is no longer used.
142func getSSHConfig(config DefaultConfig) (*ssh.ClientConfig, io.Closer) {
143 var sshAgent io.Closer
144
145 // auths holds the detected ssh auth methods
146 auths := []ssh.AuthMethod{}
147
148 // figure out what auths are requested, what is supported
149 if config.Password != "" {
150 auths = append(auths, ssh.Password(config.Password))
151 }
152 if config.KeyPath != "" {
153 if pubkey, err := getKeyFile(config.KeyPath, config.Passphrase); err != nil {
154 log.Printf("getKeyFile error: %v\n", err)
155 } else {
156 auths = append(auths, ssh.PublicKeys(pubkey))
157 }
158 }
159
160 if config.Key != "" {
161 var signer ssh.Signer
162 var err error
163 if config.Passphrase != "" {
164 signer, err = sshkeys.ParseEncryptedPrivateKey([]byte(config.Key), []byte(config.Passphrase))
165 } else {
166 signer, err = ssh.ParsePrivateKey([]byte(config.Key))
167 }
168
169 if err != nil {
170 log.Printf("ssh.ParsePrivateKey: %v\n", err)
171 } else {
172 auths = append(auths, ssh.PublicKeys(signer))
173 }
174 }
175
176 if sock, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil {
177 sshAgent = sock
178 auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(sock).Signers))
179 }
180
181 c := ssh.Config{}
182 if config.UseInsecureCipher {
183 c.SetDefaults()
184 c.Ciphers = append(c.Ciphers, "aes128-cbc", "aes192-cbc", "aes256-cbc", "3des-cbc")
185 c.KeyExchanges = append(c.KeyExchanges, "diffie-hellman-group-exchange-sha1", "diffie-hellman-group-exchange-sha256")
186 }
187
188 if len(config.Ciphers) > 0 {
189 c.Ciphers = append(c.Ciphers, config.Ciphers...)
190 }
191
192 if len(config.KeyExchanges) > 0 {
193 c.KeyExchanges = append(c.KeyExchanges, config.KeyExchanges...)
194 }
195
196 hostKeyCallback := ssh.InsecureIgnoreHostKey()
197 if config.Fingerprint != "" {
198 hostKeyCallback = func(hostname string, remote net.Addr, publicKey ssh.PublicKey) error {
199 if ssh.FingerprintSHA256(publicKey) != config.Fingerprint {

Callers 1

ConnectMethod · 0.85

Calls 1

getKeyFileFunction · 0.85

Tested by

no test coverage detected