Skip to content

Commit 15c378b

Browse files
committed
feat(ssh): add support for deprecated SSH config aliases
- Add HostbasedAcceptedAlgorithms field to domain model - Support deprecated aliases: HostbasedKeyTypes, HostbasedAcceptedKeyTypes - Add clear comments documenting which options are deprecated since OpenSSH 8.5 - Update mapper, CRUD operations, and SSH command builder accordingly This ensures backward compatibility with older SSH configurations while supporting the newer, more accurate naming conventions introduced in OpenSSH 8.5.
1 parent 7bab9a6 commit 15c378b

File tree

4 files changed

+106
-91
lines changed

4 files changed

+106
-91
lines changed

internal/adapters/data/ssh_config_file/crud.go

Lines changed: 91 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func (r *Repository) createHostFromServer(server domain.Server) *ssh_config.Host
134134
// Authentication and key management
135135
r.addKVNodeIfNotEmpty(host, "PubkeyAuthentication", server.PubkeyAuthentication)
136136
r.addKVNodeIfNotEmpty(host, "PubkeyAcceptedAlgorithms", server.PubkeyAcceptedAlgorithms)
137+
r.addKVNodeIfNotEmpty(host, "HostbasedAcceptedAlgorithms", server.HostbasedAcceptedAlgorithms)
137138
r.addKVNodeIfNotEmpty(host, "PasswordAuthentication", server.PasswordAuthentication)
138139
r.addKVNodeIfNotEmpty(host, "PreferredAuthentications", server.PreferredAuthentications)
139140
r.addKVNodeIfNotEmpty(host, "IdentitiesOnly", server.IdentitiesOnly)
@@ -197,45 +198,48 @@ func (r *Repository) addKVNodeIfNotEmpty(host *ssh_config.Host, key, value strin
197198
// updateHostNodes updates the nodes of an existing host with new server details.
198199
func (r *Repository) updateHostNodes(host *ssh_config.Host, newServer domain.Server) {
199200
updates := map[string]string{
200-
"hostname": newServer.Host,
201-
"user": newServer.User,
202-
"port": fmt.Sprintf("%d", newServer.Port),
203-
"proxycommand": newServer.ProxyCommand,
204-
"proxyjump": newServer.ProxyJump,
205-
"remotecommand": newServer.RemoteCommand,
206-
"requesttty": newServer.RequestTTY,
207-
"connecttimeout": newServer.ConnectTimeout,
208-
"connectionattempts": newServer.ConnectionAttempts,
209-
"bindaddress": newServer.BindAddress,
210-
"bindinterface": newServer.BindInterface,
211-
"pubkeyauthentication": newServer.PubkeyAuthentication,
212-
"passwordauthentication": newServer.PasswordAuthentication,
213-
"preferredauthentications": newServer.PreferredAuthentications,
214-
"pubkeyacceptedalgorithms": newServer.PubkeyAcceptedAlgorithms,
215-
"pubkeyacceptedkeytypes": newServer.PubkeyAcceptedAlgorithms, // Deprecated alias
216-
"identitiesonly": newServer.IdentitiesOnly,
217-
"addkeystoagent": newServer.AddKeysToAgent,
218-
"identityagent": newServer.IdentityAgent,
219-
"forwardagent": newServer.ForwardAgent,
220-
"forwardx11": newServer.ForwardX11,
221-
"forwardx11trusted": newServer.ForwardX11Trusted,
222-
"controlmaster": newServer.ControlMaster,
223-
"controlpath": newServer.ControlPath,
224-
"controlpersist": newServer.ControlPersist,
225-
"serveraliveinterval": newServer.ServerAliveInterval,
226-
"serveralivecountmax": newServer.ServerAliveCountMax,
227-
"compression": newServer.Compression,
228-
"tcpkeepalive": newServer.TCPKeepAlive,
229-
"stricthostkeychecking": newServer.StrictHostKeyChecking,
230-
"userknownhostsfile": newServer.UserKnownHostsFile,
231-
"hostkeyalgorithms": newServer.HostKeyAlgorithms,
232-
"macs": newServer.MACs,
233-
"ciphers": newServer.Ciphers,
234-
"kexalgorithms": newServer.KexAlgorithms,
235-
"localcommand": newServer.LocalCommand,
236-
"permitlocalcommand": newServer.PermitLocalCommand,
237-
"loglevel": newServer.LogLevel,
238-
"batchmode": newServer.BatchMode,
201+
"hostname": newServer.Host,
202+
"user": newServer.User,
203+
"port": fmt.Sprintf("%d", newServer.Port),
204+
"proxycommand": newServer.ProxyCommand,
205+
"proxyjump": newServer.ProxyJump,
206+
"remotecommand": newServer.RemoteCommand,
207+
"requesttty": newServer.RequestTTY,
208+
"connecttimeout": newServer.ConnectTimeout,
209+
"connectionattempts": newServer.ConnectionAttempts,
210+
"bindaddress": newServer.BindAddress,
211+
"bindinterface": newServer.BindInterface,
212+
"pubkeyauthentication": newServer.PubkeyAuthentication,
213+
"passwordauthentication": newServer.PasswordAuthentication,
214+
"preferredauthentications": newServer.PreferredAuthentications,
215+
"pubkeyacceptedalgorithms": newServer.PubkeyAcceptedAlgorithms,
216+
"pubkeyacceptedkeytypes": newServer.PubkeyAcceptedAlgorithms, // Deprecated alias (since OpenSSH 8.5)
217+
"hostbasedacceptedalgorithms": newServer.HostbasedAcceptedAlgorithms,
218+
"hostbasedkeytypes": newServer.HostbasedAcceptedAlgorithms, // Deprecated alias (since OpenSSH 8.5)
219+
"hostbasedacceptedkeytypes": newServer.HostbasedAcceptedAlgorithms, // Deprecated alias (since OpenSSH 8.5)
220+
"identitiesonly": newServer.IdentitiesOnly,
221+
"addkeystoagent": newServer.AddKeysToAgent,
222+
"identityagent": newServer.IdentityAgent,
223+
"forwardagent": newServer.ForwardAgent,
224+
"forwardx11": newServer.ForwardX11,
225+
"forwardx11trusted": newServer.ForwardX11Trusted,
226+
"controlmaster": newServer.ControlMaster,
227+
"controlpath": newServer.ControlPath,
228+
"controlpersist": newServer.ControlPersist,
229+
"serveraliveinterval": newServer.ServerAliveInterval,
230+
"serveralivecountmax": newServer.ServerAliveCountMax,
231+
"compression": newServer.Compression,
232+
"tcpkeepalive": newServer.TCPKeepAlive,
233+
"stricthostkeychecking": newServer.StrictHostKeyChecking,
234+
"userknownhostsfile": newServer.UserKnownHostsFile,
235+
"hostkeyalgorithms": newServer.HostKeyAlgorithms,
236+
"macs": newServer.MACs,
237+
"ciphers": newServer.Ciphers,
238+
"kexalgorithms": newServer.KexAlgorithms,
239+
"localcommand": newServer.LocalCommand,
240+
"permitlocalcommand": newServer.PermitLocalCommand,
241+
"loglevel": newServer.LogLevel,
242+
"batchmode": newServer.BatchMode,
239243
}
240244
for key, value := range updates {
241245
if value != "" {
@@ -315,51 +319,54 @@ func (r *Repository) updateOrAddKVNode(host *ssh_config.Host, key, newValue stri
315319
// Reference: https://www.ssh.com/academy/ssh/config
316320
func (r *Repository) getProperKeyCase(key string) string {
317321
keyMap := map[string]string{
318-
"hostname": "HostName",
319-
"user": "User",
320-
"port": "Port",
321-
"identityfile": "IdentityFile",
322-
"proxycommand": "ProxyCommand",
323-
"proxyjump": "ProxyJump",
324-
"remotecommand": "RemoteCommand",
325-
"requesttty": "RequestTTY",
326-
"connecttimeout": "ConnectTimeout",
327-
"connectionattempts": "ConnectionAttempts",
328-
"bindaddress": "BindAddress",
329-
"bindinterface": "BindInterface",
330-
"localforward": "LocalForward",
331-
"remoteforward": "RemoteForward",
332-
"dynamicforward": "DynamicForward",
333-
"pubkeyauthentication": "PubkeyAuthentication",
334-
"passwordauthentication": "PasswordAuthentication",
335-
"preferredauthentications": "PreferredAuthentications",
336-
"pubkeyacceptedalgorithms": "PubkeyAcceptedAlgorithms",
337-
"pubkeyacceptedkeytypes": "PubkeyAcceptedAlgorithms", // Deprecated alias
338-
"identitiesonly": "IdentitiesOnly",
339-
"addkeystoagent": "AddKeysToAgent",
340-
"identityagent": "IdentityAgent",
341-
"forwardagent": "ForwardAgent",
342-
"forwardx11": "ForwardX11",
343-
"forwardx11trusted": "ForwardX11Trusted",
344-
"controlmaster": "ControlMaster",
345-
"controlpath": "ControlPath",
346-
"controlpersist": "ControlPersist",
347-
"serveraliveinterval": "ServerAliveInterval",
348-
"serveralivecountmax": "ServerAliveCountMax",
349-
"compression": "Compression",
350-
"tcpkeepalive": "TCPKeepAlive",
351-
"stricthostkeychecking": "StrictHostKeyChecking",
352-
"userknownhostsfile": "UserKnownHostsFile",
353-
"hostkeyalgorithms": "HostKeyAlgorithms",
354-
"macs": "MACs",
355-
"ciphers": "Ciphers",
356-
"kexalgorithms": "KexAlgorithms",
357-
"localcommand": "LocalCommand",
358-
"permitlocalcommand": "PermitLocalCommand",
359-
"sendenv": "SendEnv",
360-
"setenv": "SetEnv",
361-
"loglevel": "LogLevel",
362-
"batchmode": "BatchMode",
322+
"hostname": "HostName",
323+
"user": "User",
324+
"port": "Port",
325+
"identityfile": "IdentityFile",
326+
"proxycommand": "ProxyCommand",
327+
"proxyjump": "ProxyJump",
328+
"remotecommand": "RemoteCommand",
329+
"requesttty": "RequestTTY",
330+
"connecttimeout": "ConnectTimeout",
331+
"connectionattempts": "ConnectionAttempts",
332+
"bindaddress": "BindAddress",
333+
"bindinterface": "BindInterface",
334+
"localforward": "LocalForward",
335+
"remoteforward": "RemoteForward",
336+
"dynamicforward": "DynamicForward",
337+
"pubkeyauthentication": "PubkeyAuthentication",
338+
"passwordauthentication": "PasswordAuthentication",
339+
"preferredauthentications": "PreferredAuthentications",
340+
"pubkeyacceptedalgorithms": "PubkeyAcceptedAlgorithms",
341+
"pubkeyacceptedkeytypes": "PubkeyAcceptedAlgorithms", // Deprecated alias (since OpenSSH 8.5)
342+
"hostbasedacceptedalgorithms": "HostbasedAcceptedAlgorithms",
343+
"hostbasedkeytypes": "HostbasedAcceptedAlgorithms", // Deprecated alias (since OpenSSH 8.5)
344+
"hostbasedacceptedkeytypes": "HostbasedAcceptedAlgorithms", // Deprecated alias (since OpenSSH 8.5)
345+
"identitiesonly": "IdentitiesOnly",
346+
"addkeystoagent": "AddKeysToAgent",
347+
"identityagent": "IdentityAgent",
348+
"forwardagent": "ForwardAgent",
349+
"forwardx11": "ForwardX11",
350+
"forwardx11trusted": "ForwardX11Trusted",
351+
"controlmaster": "ControlMaster",
352+
"controlpath": "ControlPath",
353+
"controlpersist": "ControlPersist",
354+
"serveraliveinterval": "ServerAliveInterval",
355+
"serveralivecountmax": "ServerAliveCountMax",
356+
"compression": "Compression",
357+
"tcpkeepalive": "TCPKeepAlive",
358+
"stricthostkeychecking": "StrictHostKeyChecking",
359+
"userknownhostsfile": "UserKnownHostsFile",
360+
"hostkeyalgorithms": "HostKeyAlgorithms",
361+
"macs": "MACs",
362+
"ciphers": "Ciphers",
363+
"kexalgorithms": "KexAlgorithms",
364+
"localcommand": "LocalCommand",
365+
"permitlocalcommand": "PermitLocalCommand",
366+
"sendenv": "SendEnv",
367+
"setenv": "SetEnv",
368+
"loglevel": "LogLevel",
369+
"batchmode": "BatchMode",
363370
}
364371

365372
if properCase, exists := keyMap[strings.ToLower(key)]; exists {

internal/adapters/data/ssh_config_file/mapper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ func (r *Repository) mapAuthenticationConfig(server *domain.Server, key, value s
173173
case "pubkeyauthentication":
174174
server.PubkeyAuthentication = value
175175
case "pubkeyacceptedalgorithms", "pubkeyacceptedkeytypes":
176+
// PubkeyAcceptedKeyTypes is deprecated alias for PubkeyAcceptedAlgorithms (since OpenSSH 8.5)
176177
server.PubkeyAcceptedAlgorithms = value
178+
case "hostbasedacceptedalgorithms", "hostbasedkeytypes", "hostbasedacceptedkeytypes":
179+
// HostbasedKeyTypes and HostbasedAcceptedKeyTypes are deprecated aliases (since OpenSSH 8.5)
180+
server.HostbasedAcceptedAlgorithms = value
177181
case "passwordauthentication":
178182
server.PasswordAuthentication = value
179183
case "preferredauthentications":

internal/adapters/ui/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ func addAuthOptions(parts *[]string, s domain.Server) {
229229
if s.PubkeyAcceptedAlgorithms != "" {
230230
*parts = append(*parts, "-o", fmt.Sprintf("PubkeyAcceptedAlgorithms=%s", s.PubkeyAcceptedAlgorithms))
231231
}
232+
if s.HostbasedAcceptedAlgorithms != "" {
233+
*parts = append(*parts, "-o", fmt.Sprintf("HostbasedAcceptedAlgorithms=%s", s.HostbasedAcceptedAlgorithms))
234+
}
232235
if s.PasswordAuthentication != "" {
233236
*parts = append(*parts, "-o", fmt.Sprintf("PasswordAuthentication=%s", s.PasswordAuthentication))
234237
}

internal/core/domain/server.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ type Server struct {
4545
DynamicForward []string
4646

4747
// Authentication and key management
48-
PubkeyAuthentication string
49-
PubkeyAcceptedAlgorithms string
50-
PasswordAuthentication string
51-
PreferredAuthentications string
52-
IdentitiesOnly string
53-
AddKeysToAgent string
54-
IdentityAgent string
48+
PubkeyAuthentication string
49+
PubkeyAcceptedAlgorithms string
50+
HostbasedAcceptedAlgorithms string
51+
PasswordAuthentication string
52+
PreferredAuthentications string
53+
IdentitiesOnly string
54+
AddKeysToAgent string
55+
IdentityAgent string
5556

5657
// Agent and X11 forwarding
5758
ForwardAgent string

0 commit comments

Comments
 (0)