Skip to content

Commit

Permalink
Merge pull request #422 from moul/dev/moul/maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Apr 24, 2021
2 parents 3f0c85a + e2fa2bb commit 74c203f
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 227 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: lint
uses: golangci/[email protected]
with:
version: v1.28
version: v1.38
github-token: ${{ secrets.GITHUB_TOKEN }}
tests-on-windows:
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
Expand Down
2 changes: 1 addition & 1 deletion contrib/webapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func server(c *cli.Context) error {
})
} else {
c.JSON(200, gin.H{
//"assh_config": json.AsshConfig,
// "assh_config": json.AsshConfig,
"ssh_config": buffer.String(),
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func runInfoCommand(cmd *cobra.Command, args []string) error {
fmt.Printf("RC files:\n")
homeDir := utils.GetHomeDir()
for _, filename := range conf.IncludedFiles() {
relativeFilename := strings.Replace(filename, homeDir, "~", -1)
relativeFilename := strings.ReplaceAll(filename, homeDir, "~")
fmt.Printf("- %s\n", relativeFilename)
}
fmt.Println("")
Expand Down
24 changes: 12 additions & 12 deletions pkg/commands/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,27 +187,27 @@ func expandSSHTokens(tokenized string, host *config.Host) string {
if result[0] == '~' {
result = strings.Replace(result, "~", homedir, 1)
}
result = strings.Replace(result, "%d", homedir, -1)
result = strings.ReplaceAll(result, "%d", homedir)

result = strings.Replace(result, "%%", "%", -1)
result = strings.Replace(result, "%C", "%l%h%p%r", -1)
result = strings.Replace(result, "%h", host.Name(), -1)
result = strings.Replace(result, "%i", strconv.Itoa(os.Geteuid()), -1)
result = strings.Replace(result, "%p", host.Port, -1)
result = strings.ReplaceAll(result, "%%", "%")
result = strings.ReplaceAll(result, "%C", "%l%h%p%r")
result = strings.ReplaceAll(result, "%h", host.Name())
result = strings.ReplaceAll(result, "%i", strconv.Itoa(os.Geteuid()))
result = strings.ReplaceAll(result, "%p", host.Port)

if hostname, err := os.Hostname(); err == nil {
result = strings.Replace(result, "%L", hostname, -1)
result = strings.ReplaceAll(result, "%L", hostname)
} else {
result = strings.Replace(result, "%L", "hostname", -1)
result = strings.ReplaceAll(result, "%L", "hostname")
}

if host.User != "" {
result = strings.Replace(result, "%r", host.User, -1)
result = strings.ReplaceAll(result, "%r", host.User)
} else {
if userdata, err := user.Current(); err == nil {
result = strings.Replace(result, "%r", userdata.Username, -1)
result = strings.ReplaceAll(result, "%r", userdata.Username)
} else {
result = strings.Replace(result, "%r", "username", -1)
result = strings.ReplaceAll(result, "%r", "username")
}
}

Expand Down Expand Up @@ -542,7 +542,7 @@ func proxyGo(host *config.Host, dryRun bool) error {
// human
stats.WrittenBytesHuman = humanize.Bytes(stats.WrittenBytes)
connectionDurationHuman := humanize.RelTime(stats.DisconnectedAt, stats.ConnectedAt, "", "")
stats.ConnectionDurationHuman = strings.Replace(connectionDurationHuman, "now", "0 sec", -1)
stats.ConnectionDurationHuman = strings.ReplaceAll(connectionDurationHuman, "now", "0 sec")
stats.AverageSpeedHuman = humanize.Bytes(uint64(stats.AverageSpeed)) + "/s"

// OnDisconnect hook
Expand Down
12 changes: 6 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ func computeHost(host *Host, config *Config, name string, fullCompute bool) (*Ho
}
// expands variables in host
// i.e: %h.some.zone -> {name}.some.zone
hostname := strings.Replace(computedHost.HostName, "%h", "%n", -1)
hostname := strings.ReplaceAll(computedHost.HostName, "%h", "%n")

// ssh resolve '%h' in hostnames
// -> we bypass the string expansion if the input matches
// an already resolved hostname
// See https://github.com/moul/assh/issues/103
pattern := strings.Replace(hostname, "%n", "*", -1)
pattern := strings.ReplaceAll(hostname, "%n", "*")
if match, _ := path.Match(pattern, computedHost.inputName); match {
computedHost.HostName = computedHost.inputName
} else {
Expand Down Expand Up @@ -412,7 +412,7 @@ func (c *Config) mergeWildCardEntries() {
}
}
} else {
tempKey := strings.Replace(key, "*", "", -1)
tempKey := strings.ReplaceAll(key, "*", "")
// if the wildcard matches
if strings.Contains(k, tempKey) {
if err := mergo.Merge(host, subHost); err != nil {
Expand Down Expand Up @@ -623,9 +623,9 @@ func (c *Config) WriteSSHConfigTo(w io.Writer) error {
#
# more info: https://github.com/moul/assh
`)
header = strings.Replace(header, "%VERSION", version.Version, -1)
header = strings.Replace(header, "%VCS_REF", version.VcsRef, -1)
header = strings.Replace(header, "%BUILD_DATE", time.Now().Format("2006-01-02 15:04:05 -0700 MST"), -1)
header = strings.ReplaceAll(header, "%VERSION", version.Version)
header = strings.ReplaceAll(header, "%VCS_REF", version.VcsRef)
header = strings.ReplaceAll(header, "%BUILD_DATE", time.Now().Format("2006-01-02 15:04:05 -0700 MST"))
_, _ = fmt.Fprintln(w, header)
// FIXME: add version
_, _ = fmt.Fprintln(w)
Expand Down
168 changes: 84 additions & 84 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,96 +195,96 @@ func dummyConfig() *Config {
}
config.Hosts["zzz"] = &Host{
// ssh-config fields
AddressFamily: "any",
AskPassGUI: "yes",
BatchMode: "no",
BindAddress: "",
CanonicalDomains: "42.am",
CanonicalizeFallbackLocal: "no",
CanonicalizeHostname: "yes",
CanonicalizeMaxDots: "1",
CanonicalizePermittedCNAMEs: "*.a.example.com:*.b.example.com:*.c.example.com",
ChallengeResponseAuthentication: "yes",
CheckHostIP: "yes",
Cipher: "blowfish",
Ciphers: []string{"aes128-ctr,aes192-ctr", "aes256-ctr"},
ClearAllForwardings: "yes",
Compression: "yes",
CompressionLevel: 6,
ConnectionAttempts: "1",
ConnectTimeout: 10,
ControlMaster: "yes",
ControlPath: "/tmp/%L-%l-%n-%p-%u-%r-%C-%h",
ControlPersist: "yes",
DynamicForward: []string{"0.0.0.0:4242", "0.0.0.0:4343"},
EnableSSHKeysign: "yes",
EscapeChar: "~",
ExitOnForwardFailure: "yes",
FingerprintHash: "sha256",
ForwardAgent: "yes",
ForwardX11: "yes",
ForwardX11Timeout: 42,
ForwardX11Trusted: "yes",
GatewayPorts: "yes",
GlobalKnownHostsFile: []string{"/etc/ssh/ssh_known_hosts", "/tmp/ssh_known_hosts"},
GSSAPIAuthentication: "no",
GSSAPIKeyExchange: "no",
GSSAPIClientIdentity: "moul",
GSSAPIServerIdentity: "gssapi.example.com",
GSSAPIDelegateCredentials: "no",
GSSAPIRenewalForcesRekey: "no",
GSSAPITrustDNS: "no",
HashKnownHosts: "no",
HostbasedAuthentication: "no",
HostbasedKeyTypes: "*",
HostKeyAlgorithms: "[email protected]",
HostKeyAlias: "z",
IdentitiesOnly: "yes",
IdentityFile: []string{"~/.ssh/identity", "~/.ssh/identity2"},
IgnoreUnknown: "testtest", // FIXME: looks very interesting to generate .ssh/config without comments !
IPQoS: []string{"lowdelay", "highdelay"},
KbdInteractiveAuthentication: "yes",
KbdInteractiveDevices: []string{"bsdauth", "test"},
KeychainIntegration: "yes",
KexAlgorithms: []string{"[email protected]", "test"}, // for all algorithms/ciphers, we could have an "assh diagnose" that warns about unsafe connections
LocalCommand: "echo %h > /tmp/logs",
LocalForward: []string{"0.0.0.0:1234", "0.0.0.0:1235"},
LogLevel: "DEBUG3",
MACs: []string{"[email protected],[email protected]", "test"},
Match: "all",
AddressFamily: "any",
AskPassGUI: "yes",
BatchMode: "no",
BindAddress: "",
CanonicalDomains: "42.am",
CanonicalizeFallbackLocal: "no",
CanonicalizeHostname: "yes",
CanonicalizeMaxDots: "1",
CanonicalizePermittedCNAMEs: "*.a.example.com:*.b.example.com:*.c.example.com",
ChallengeResponseAuthentication: "yes",
CheckHostIP: "yes",
Cipher: "blowfish",
Ciphers: []string{"aes128-ctr,aes192-ctr", "aes256-ctr"},
ClearAllForwardings: "yes",
Compression: "yes",
CompressionLevel: 6,
ConnectionAttempts: "1",
ConnectTimeout: 10,
ControlMaster: "yes",
ControlPath: "/tmp/%L-%l-%n-%p-%u-%r-%C-%h",
ControlPersist: "yes",
DynamicForward: []string{"0.0.0.0:4242", "0.0.0.0:4343"},
EnableSSHKeysign: "yes",
EscapeChar: "~",
ExitOnForwardFailure: "yes",
FingerprintHash: "sha256",
ForwardAgent: "yes",
ForwardX11: "yes",
ForwardX11Timeout: 42,
ForwardX11Trusted: "yes",
GatewayPorts: "yes",
GlobalKnownHostsFile: []string{"/etc/ssh/ssh_known_hosts", "/tmp/ssh_known_hosts"},
GSSAPIAuthentication: "no",
GSSAPIKeyExchange: "no",
GSSAPIClientIdentity: "moul",
GSSAPIServerIdentity: "gssapi.example.com",
GSSAPIDelegateCredentials: "no",
GSSAPIRenewalForcesRekey: "no",
GSSAPITrustDNS: "no",
HashKnownHosts: "no",
HostbasedAuthentication: "no",
HostbasedKeyTypes: "*",
HostKeyAlgorithms: "[email protected]",
HostKeyAlias: "z",
IdentitiesOnly: "yes",
IdentityFile: []string{"~/.ssh/identity", "~/.ssh/identity2"},
IgnoreUnknown: "testtest", // FIXME: looks very interesting to generate .ssh/config without comments !
IPQoS: []string{"lowdelay", "highdelay"},
KbdInteractiveAuthentication: "yes",
KbdInteractiveDevices: []string{"bsdauth", "test"},
KeychainIntegration: "yes",
KexAlgorithms: []string{"[email protected]", "test"}, // for all algorithms/ciphers, we could have an "assh diagnose" that warns about unsafe connections
LocalCommand: "echo %h > /tmp/logs",
LocalForward: []string{"0.0.0.0:1234", "0.0.0.0:1235"},
LogLevel: "DEBUG3",
MACs: []string{"[email protected],[email protected]", "test"},
Match: "all",
NoHostAuthenticationForLocalhost: "yes",
NumberOfPasswordPrompts: "3",
PasswordAuthentication: "yes",
PermitLocalCommand: "yes",
PKCS11Provider: "/a/b/c/pkcs11.so",
Port: "22",
PreferredAuthentications: "gssapi-with-mic,hostbased,publickey",
Protocol: []string{"2", "3"},
ProxyUseFdpass: "no",
PubkeyAuthentication: "yes",
RekeyLimit: "default none",
RemoteForward: []string{"0.0.0.0:1234", "0.0.0.0:1255"},
RequestTTY: "yes",
RevokedHostKeys: "/a/revoked-keys",
RhostsRSAAuthentication: "no",
RSAAuthentication: "yes",
SendEnv: []string{"CUSTOM_*,TEST", "TEST2"},
ServerAliveCountMax: 3,
ServerAliveInterval: 0,
StreamLocalBindMask: "0177",
StreamLocalBindUnlink: "no",
StrictHostKeyChecking: "ask",
TCPKeepAlive: "yes",
Tunnel: "yes",
TunnelDevice: "any:any",
UpdateHostKeys: "ask",
UseKeychain: "no",
UsePrivilegedPort: "no",
User: "moul",
UserKnownHostsFile: []string{"~/.ssh/known_hosts ~/.ssh/known_hosts2", "/tmp/known_hosts"},
VerifyHostKeyDNS: "no",
VisualHostKey: "yes",
XAuthLocation: "xauth",
PreferredAuthentications: "gssapi-with-mic,hostbased,publickey",
Protocol: []string{"2", "3"},
ProxyUseFdpass: "no",
PubkeyAuthentication: "yes",
RekeyLimit: "default none",
RemoteForward: []string{"0.0.0.0:1234", "0.0.0.0:1255"},
RequestTTY: "yes",
RevokedHostKeys: "/a/revoked-keys",
RhostsRSAAuthentication: "no",
RSAAuthentication: "yes",
SendEnv: []string{"CUSTOM_*,TEST", "TEST2"},
ServerAliveCountMax: 3,
ServerAliveInterval: 0,
StreamLocalBindMask: "0177",
StreamLocalBindUnlink: "no",
StrictHostKeyChecking: "ask",
TCPKeepAlive: "yes",
Tunnel: "yes",
TunnelDevice: "any:any",
UpdateHostKeys: "ask",
UseKeychain: "no",
UsePrivilegedPort: "no",
User: "moul",
UserKnownHostsFile: []string{"~/.ssh/known_hosts ~/.ssh/known_hosts2", "/tmp/known_hosts"},
VerifyHostKeyDNS: "no",
VisualHostKey: "yes",
XAuthLocation: "xauth",

// ssh-config fields with a different behavior
ProxyCommand: "nc %h %p",
Expand Down
44 changes: 22 additions & 22 deletions pkg/config/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,27 +521,27 @@ func (h *Host) Options() OptionsList {
}

// ssh-config fields with a different behavior
//HostName
//ProxyCommand
// HostName
// ProxyCommand

// exposed assh fields
//Inherits
//Gateways
//ResolveNameservers
//ResolveCommand
//ControlMasterMkdir
//Aliases
//Comment
//Hooks
// Inherits
// Gateways
// ResolveNameservers
// ResolveCommand
// ControlMasterMkdir
// Aliases
// Comment
// Hooks

// private assh fields
//knownHosts
//pattern
//name
//inputName
//isDefault
//isTemplate
//inherited
// knownHosts
// pattern
// name
// inputName
// isDefault
// isTemplate
// inherited

return options
}
Expand Down Expand Up @@ -1489,19 +1489,19 @@ func (h *Host) ExpandString(input string, gateway string) string {
output := input

// name of the host in config
output = strings.Replace(output, "%name", h.Name(), -1)
output = strings.ReplaceAll(output, "%name", h.Name())

// original target host name specified on the command line
output = strings.Replace(output, "%n", h.inputName, -1)
output = strings.ReplaceAll(output, "%n", h.inputName)

// target host name
output = strings.Replace(output, "%h", h.HostName, -1)
output = strings.ReplaceAll(output, "%h", h.HostName)

// port
output = strings.Replace(output, "%p", h.Port, -1)
output = strings.ReplaceAll(output, "%p", h.Port)

// gateway
output = strings.Replace(output, "%g", gateway, -1)
output = strings.ReplaceAll(output, "%g", gateway)

// FIXME: add
// %L -> first component of the local host name
Expand Down
Loading

0 comments on commit 74c203f

Please sign in to comment.