Skip to content

Commit 9cba9fe

Browse files
authored
Merge pull request #16955 from iterate-ch/bugfix/GH-16954
Make aware of none value for configuration directives in OpenSSH configuration
2 parents 3b569cc + 5dfde99 commit 9cba9fe

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

ssh/src/main/java/ch/cyberduck/core/sftp/openssh/OpenSSHCredentialsConfigurator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Credentials configure(final Host host) {
5353
if(!credentials.isPublicKeyAuthentication()) {
5454
if(null != entry.getIdentityFile()) {
5555
log.info("Using identity {} from {}", entry, configuration);
56-
credentials.setIdentity(entry.getIdentityFile());
56+
credentials.setIdentity(LocalFactory.get(entry.getIdentityFile()));
5757
}
5858
else {
5959
// No custom public key authentication configuration

ssh/src/main/java/ch/cyberduck/core/sftp/openssh/OpenSSHIdentityAgentConfigurator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
1919
*/
2020

21-
import ch.cyberduck.core.Local;
2221
import ch.cyberduck.core.LocalFactory;
2322
import ch.cyberduck.core.sftp.openssh.config.transport.OpenSshConfig;
2423

@@ -39,13 +38,13 @@ public OpenSSHIdentityAgentConfigurator(final OpenSshConfig configuration) {
3938
}
4039

4140
public String getIdentityAgent(final String alias) {
42-
final Local agent = configuration.lookup(alias).getIdentityAgent();
41+
final String agent = configuration.lookup(alias).getIdentityAgent();
4342
if(null == agent) {
4443
log.debug("No configuration for alias {}", alias);
4544
return null;
4645
}
4746
log.debug("Found configuration {} for alias {}", agent, alias);
48-
return agent.getAbsolute();
47+
return agent;
4948
}
5049

5150
@Override

ssh/src/main/java/ch/cyberduck/core/sftp/openssh/config/transport/OpenSshConfig.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,45 +147,35 @@ public Map<String, Host> refresh() {
147147
}
148148

149149
private Map<String, Host> parse(final InputStream in) throws IOException {
150-
final Map<String, Host> m = new LinkedHashMap<String, Host>();
150+
final Map<String, Host> m = new LinkedHashMap<>();
151151
final BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
152-
final List<Host> current = new ArrayList<Host>(4);
152+
final List<Host> current = new ArrayList<>(4);
153153
String line;
154154

155155
while((line = br.readLine()) != null) {
156156
line = line.trim();
157-
if(line.length() == 0 || line.startsWith("#")) {
157+
if(line.isEmpty() || line.startsWith("#")) {
158158
continue;
159159
}
160-
161160
final String[] parts = line.split("[ \t]*[= \t]", 2);
162161
if(parts.length != 2) {
163162
continue;
164163
}
165164
final String keyword = parts[0].trim();
166165
final String argValue = parts[1].trim();
167-
168166
if("Host".equalsIgnoreCase(keyword)) {
169167
current.clear();
170168
for(final String pattern : argValue.split("[ \t]")) {
171169
final String name = dequote(pattern);
172-
Host c = m.get(name);
173-
if(c == null) {
174-
c = new Host();
175-
m.put(name, c);
176-
}
170+
Host c = m.computeIfAbsent(name, k -> new Host());
177171
current.add(c);
178172
}
179173
continue;
180174
}
181-
182175
if(current.isEmpty()) {
183-
// We received an option outside of a Host block. We
184-
// don't know who this should match against, so skip.
185-
//
176+
// We received an option outside a Host block. We don't know who this should match against, so skip.
186177
continue;
187178
}
188-
189179
if("HostName".equalsIgnoreCase(keyword)) {
190180
for(final Host c : current) {
191181
if(c.hostName == null) {
@@ -196,7 +186,7 @@ private Map<String, Host> parse(final InputStream in) throws IOException {
196186
else if("ProxyJump".equalsIgnoreCase(keyword)) {
197187
for(final Host c : current) {
198188
if(c.proxyJump == null) {
199-
c.proxyJump = dequote(argValue);
189+
c.proxyJump = none(dequote(argValue));
200190
}
201191
}
202192
}
@@ -223,21 +213,21 @@ else if("Port".equalsIgnoreCase(keyword)) {
223213
else if("IdentityFile".equalsIgnoreCase(keyword)) {
224214
for(final Host c : current) {
225215
if(c.identityFile == null) {
226-
c.identityFile = LocalFactory.get(dequote(argValue));
216+
c.identityFile = none(dequote(argValue));
227217
}
228218
}
229219
}
230220
else if("IdentityAgent".equalsIgnoreCase(keyword)) {
231221
for(final Host c : current) {
232222
if(c.identityAgent == null) {
233-
c.identityAgent = LocalFactory.get(dequote(argValue));
223+
c.identityAgent = none(dequote(argValue));
234224
}
235225
}
236226
}
237227
else if("PreferredAuthentications".equalsIgnoreCase(keyword)) {
238228
for(final Host c : current) {
239229
if(c.preferredAuthentications == null) {
240-
c.preferredAuthentications = nows(dequote(argValue));
230+
c.preferredAuthentications = none(nows(dequote(argValue)));
241231
}
242232
}
243233
}
@@ -256,7 +246,6 @@ else if("BatchMode".equalsIgnoreCase(keyword)) {
256246
}
257247
}
258248
}
259-
260249
return m;
261250
}
262251

@@ -300,6 +289,13 @@ private static Boolean yesno(final String value) {
300289
return Boolean.FALSE;
301290
}
302291

292+
private static String none(final String value) {
293+
if("none".equalsIgnoreCase(value)) {
294+
return null;
295+
}
296+
return value;
297+
}
298+
303299
/**
304300
* Configuration of one "Host" block in the configuration file.
305301
* <p/>
@@ -315,8 +311,8 @@ public static class Host {
315311
String hostName;
316312
String proxyJump;
317313
int port;
318-
Local identityFile;
319-
Local identityAgent;
314+
String identityFile;
315+
String identityAgent;
320316
String user;
321317
String preferredAuthentications;
322318
Boolean identitiesOnly;
@@ -374,14 +370,14 @@ public int getPort() {
374370
* @return path of the private key file to use for authentication; null if the caller should use default
375371
* authentication strategies.
376372
*/
377-
public Local getIdentityFile() {
373+
public String getIdentityFile() {
378374
return identityFile;
379375
}
380376

381377
/**
382378
* @return Specifies the UNIX-domain socket used to communicate with the authentication agent.
383379
*/
384-
public Local getIdentityAgent() {
380+
public String getIdentityAgent() {
385381
return identityAgent;
386382
}
387383

0 commit comments

Comments
 (0)