@@ -25,8 +25,10 @@ import (
2525 "time"
2626
2727 "github.com/spf13/cobra"
28+ "golang.org/x/crypto/ssh"
2829 gossh "golang.org/x/crypto/ssh"
2930 "golang.org/x/term"
31+ "gopkg.in/yaml.v3"
3032)
3133
3234var (
5052 }
5153)
5254
55+ // old ssh ciphers issue
56+ // https://github.com/golang/go/issues/64779
57+
58+ type SSHConfig struct {
59+ Ciphers []string `yaml:"Ciphers"`
60+ KexAlgos []string `yaml:"KexAlgos"`
61+ MACs []string `yaml:"MACs"`
62+ HostKeyAlgos []string `yaml:"HostKeyAlgos"`
63+ }
64+
5365// sshCmd represents the ssh command
5466var sshCmd = & cobra.Command {
5567 Use : "ssh" ,
93105 password = flagPassword
94106 auths = append (auths , gossh .Password (password ))
95107 }
108+ var sshConfig SSHConfig
109+
110+ defaultConfig := ssh.Config {}
111+ defaultConfig .SetDefaults ()
112+
113+ if flagConfig , err := cmd .PersistentFlags ().GetString ("config" ); err == nil {
114+ raw , err := os .ReadFile (flagConfig )
115+ if err != nil {
116+ log .Fatal (err )
117+ }
118+ if err := yaml .Unmarshal (raw , & sshConfig ); err != nil {
119+ log .Fatal (err )
120+ }
121+ if len (sshConfig .Ciphers ) == 0 {
122+ sshConfig .Ciphers = defaultConfig .Ciphers
123+ }
124+ if len (sshConfig .KexAlgos ) == 0 {
125+ sshConfig .KexAlgos = defaultConfig .KeyExchanges
126+ }
127+ if len (sshConfig .HostKeyAlgos ) == 0 {
128+ sshConfig .HostKeyAlgos = nil
129+ }
130+ if len (sshConfig .MACs ) == 0 {
131+ sshConfig .MACs = defaultConfig .MACs
132+ }
133+
134+ }
96135
97136 if password == "" && privateFile == "" {
98137 if _ , err := fmt .Fprintf (os .Stdout , "%s@%s password: " , username , host ); err != nil {
122161 User : username ,
123162 Auth : auths ,
124163 HostKeyCallback : gossh .InsecureIgnoreHostKey (),
125- Config : gossh.Config {Ciphers : supportedCiphers , KeyExchanges : supportedKexAlgos },
164+ Config : gossh.Config {Ciphers : sshConfig . Ciphers , KeyExchanges : sshConfig . KexAlgos , MACs : sshConfig . MACs },
126165 Timeout : 30 * time .Second ,
127166 HostKeyAlgorithms : supportedHostKeyAlgos ,
128167 }
@@ -208,7 +247,7 @@ func init() {
208247 sshCmd .PersistentFlags ().StringP ("port" , "p" , "22" , "ssh port" )
209248 sshCmd .PersistentFlags ().StringP ("password" , "P" , "" , "ssh password" )
210249 sshCmd .PersistentFlags ().StringP ("identity" , "i" , "" , "identity_file" )
211- sshCmd .PersistentFlags ().StringP ("config" , "c" , "" , "config file for cipher, kex, hostkey" )
250+ sshCmd .PersistentFlags ().StringP ("config" , "c" , "" , "config file for cipher, kex, hostkey, macs " )
212251 // Here you will define your flags and configuration settings.
213252
214253 // Cobra supports Persistent Flags which will work for this command
0 commit comments