git: Add git.HostKeyAlgos

Enables the setting of HostKey algorithms to be used from
a client perspective. This implementation supports go-git
and libgit2 when in ManagedTransport.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
This commit is contained in:
Paulo Gomes 2022-05-06 17:58:09 +01:00
parent d425923a54
commit 4e3e62923b
No known key found for this signature in database
GPG Key ID: 9995233870E99BEE
3 changed files with 13 additions and 1 deletions

View File

@ -103,5 +103,9 @@ func (a *CustomPublicKeys) ClientConfig() (*gossh.ClientConfig, error) {
if len(git.KexAlgos) > 0 { if len(git.KexAlgos) > 0 {
config.Config.KeyExchanges = git.KexAlgos config.Config.KeyExchanges = git.KexAlgos
} }
if len(git.HostKeyAlgos) > 0 {
config.HostKeyAlgorithms = git.HostKeyAlgos
}
return config, nil return config, nil
} }

View File

@ -421,6 +421,9 @@ func cacheKeyAndConfig(remoteAddress string, cred *git2go.Credential) (string, *
if len(git.KexAlgos) > 0 { if len(git.KexAlgos) > 0 {
cfg.Config.KeyExchanges = git.KexAlgos cfg.Config.KeyExchanges = git.KexAlgos
} }
if len(git.HostKeyAlgos) > 0 {
cfg.HostKeyAlgorithms = git.HostKeyAlgos
}
return ck, cfg, nil return ck, cfg, nil
} }

View File

@ -70,9 +70,14 @@ type AuthOptions struct {
CAFile []byte CAFile []byte
} }
// List of custom key exchange algorithms to be used for ssh connections. // KexAlgos hosts the key exchange algorithms to be used for ssh connections.
// If empty, golang's default is used instead.
var KexAlgos []string var KexAlgos []string
// HostKeyAlgos holds the HostKey algorithms that the ssh client will advertise
// to the server. If empty, golang's default is used instead.
var HostKeyAlgos []string
// Validate the AuthOptions against the defined Transport. // Validate the AuthOptions against the defined Transport.
func (o AuthOptions) Validate() error { func (o AuthOptions) Validate() error {
switch o.Transport { switch o.Transport {