From 359a020a3ddd87cabe9a11b49786ad7d72339110 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Mon, 23 Oct 2023 21:23:18 +0200 Subject: [PATCH] Refactor for static access. --- .../sftp/auth/SFTPAgentAuthentication.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ssh/src/main/java/ch/cyberduck/core/sftp/auth/SFTPAgentAuthentication.java b/ssh/src/main/java/ch/cyberduck/core/sftp/auth/SFTPAgentAuthentication.java index f7dd92c4a3e..941f2881a0d 100644 --- a/ssh/src/main/java/ch/cyberduck/core/sftp/auth/SFTPAgentAuthentication.java +++ b/ssh/src/main/java/ch/cyberduck/core/sftp/auth/SFTPAgentAuthentication.java @@ -84,9 +84,9 @@ public Boolean authenticate(final Host bookmark, final LoginCallback prompt, fin if(log.isWarnEnabled()) { log.warn(String.format("Only read specific key %s from SSH agent with IdentitiesOnly configuration", identity)); } - identities = this.isPrivateKey(identity) ? - this.identityFromPrivateKey(identity) : - this.identityFromPublicKey(identity); + identities = Collections.singleton(isPrivateKey(identity) ? + identityFromPrivateKey(identity) : + identityFromPublicKey(identity)); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); @@ -143,29 +143,29 @@ protected Collection filter(final Credentials credentials, final Colle return identities; } - private boolean isPrivateKey(final Local identity) throws AccessDeniedException, IOException { + private static boolean isPrivateKey(final Local identity) throws AccessDeniedException, IOException { final KeyFormat format = KeyProviderUtil.detectKeyFileFormat( new InputStreamReader(identity.getInputStream()), true); return format != KeyFormat.Unknown; } - private Collection identityFromPrivateKey(final Local identity) throws IOException, AccessDeniedException { + private static Identity identityFromPrivateKey(final Local identity) throws IOException, AccessDeniedException { final File pubKey = OpenSSHKeyFileUtil.getPublicKeyFile(new File(identity.getAbsolute())); if(pubKey != null) { - return this.identityFromPublicKey(LocalFactory.get(pubKey.getAbsolutePath())); + return identityFromPublicKey(LocalFactory.get(pubKey.getAbsolutePath())); } log.warn(String.format("Unable to find public key file for identity %s", identity)); - return Collections.emptyList(); + return null; } - private Collection identityFromPublicKey(final Local identity) throws IOException, AccessDeniedException { + private static Identity identityFromPublicKey(final Local identity) throws IOException, AccessDeniedException { final List lines = IOUtils.readLines(identity.getInputStream(), Charset.defaultCharset()); for(String line : lines) { final String keydata = line.trim(); if(StringUtils.isNotBlank(keydata)) { String[] parts = keydata.split("\\s+"); if(parts.length >= 2) { - return Collections.singletonList(new CustomIdentity(Base64.decodeBase64(parts[1]))); + return new CustomIdentity(Base64.decodeBase64(parts[1])); } } }