This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit ccaec74addcb3109568907a78661a50c36a3ef2e
Author: Lyor Goldstein <lgoldst...@apache.org>
AuthorDate: Thu Apr 1 20:59:46 2021 +0300

    [SSHD-1116] Provide SessionContext argument to 
HostKeyIdentityProvider#loadHostKeys
---
 CHANGES.md                                          |  1 +
 .../auth/hostbased/HostKeyIdentityProvider.java     | 21 ++++++++++++++++-----
 .../client/auth/hostbased/UserAuthHostBased.java    |  2 +-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 4681c75..d2e0fcf 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -28,6 +28,7 @@
 * [SSHD-1109](https://issues.apache.org/jira/browse/SSHD-1109) Provide full 
slf4j logger capabilities to CliLogger + use it in all CLI classes
 * [SSHD-1110](https://issues.apache.org/jira/browse/SSHD-1110) Replace 
`Class#newInstance()` calls with `Class#getDefaultConstructor().newInstance()`
 * [SSHD-1111](https://issues.apache.org/jira/browse/SSHD-1111) Fixed 
SshClientCliSupport compression option detection
+* [SSHD-1116](https://issues.apache.org/jira/browse/SSHD-1116) Provide 
SessionContext argument to HostKeyIdentityProvider#loadHostKeys
 * [SSHD-1125](https://issues.apache.org/jira/browse/SSHD-1125) Added option to 
require immediate close of channel in command `ExitCallback` invocation
 * [SSHD-1127](https://issues.apache.org/jira/browse/SSHD-1127) Consolidated 
`SftpSubsystem` support implementations into `SftpSubsystemConfigurator`
 * [SSHD-1148](https://issues.apache.org/jira/browse/SSHD-1148) Generate a 
unique thread name for each `SftpSubsystem` instance
diff --git 
a/sshd-common/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java
 
b/sshd-common/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java
index 53b1aca..f08a7b7 100644
--- 
a/sshd-common/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java
+++ 
b/sshd-common/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java
@@ -19,6 +19,8 @@
 
 package org.apache.sshd.client.auth.hostbased;
 
+import java.io.IOException;
+import java.security.GeneralSecurityException;
 import java.security.KeyPair;
 import java.security.cert.X509Certificate;
 import java.util.AbstractMap.SimpleImmutableEntry;
@@ -27,6 +29,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.sshd.common.session.SessionContext;
 import org.apache.sshd.common.util.GenericUtils;
 
 /**
@@ -35,12 +38,20 @@ import org.apache.sshd.common.util.GenericUtils;
 @FunctionalInterface
 public interface HostKeyIdentityProvider {
     /**
-     * @return The host keys as a {@link java.util.Map.Entry} of key + 
certificates (which can be {@code null}/empty)
+     * @param  session                  The {@link SessionContext} for 
invoking this load command - may be {@code null}
+     *                                  if not invoked within a session 
context (e.g., offline tool).
+     * @return                          The host keys as a {@link 
java.util.Map.Entry} of key + certificates (which can
+     *                                  be {@code null}/empty)
+     * @throws IOException              If failed to load the keys
+     * @throws GeneralSecurityException If failed to parse the keys
      */
-    Iterable<? extends Map.Entry<KeyPair, List<X509Certificate>>> 
loadHostKeys();
+    Iterable<? extends Map.Entry<KeyPair, List<X509Certificate>>> 
loadHostKeys(SessionContext session)
+            throws IOException, GeneralSecurityException;
 
-    static Iterator<? extends Map.Entry<KeyPair, List<X509Certificate>>> 
iteratorOf(HostKeyIdentityProvider provider) {
-        return GenericUtils.iteratorOf((provider == null) ? null : 
provider.loadHostKeys());
+    static Iterator<? extends Map.Entry<KeyPair, List<X509Certificate>>> 
iteratorOf(
+            SessionContext session, HostKeyIdentityProvider provider)
+            throws IOException, GeneralSecurityException {
+        return GenericUtils.iteratorOf((provider == null) ? null : 
provider.loadHostKeys(session));
     }
 
     static HostKeyIdentityProvider wrap(KeyPair... pairs) {
@@ -48,7 +59,7 @@ public interface HostKeyIdentityProvider {
     }
 
     static HostKeyIdentityProvider wrap(Iterable<? extends KeyPair> pairs) {
-        return () -> GenericUtils.wrapIterable(pairs,
+        return session -> GenericUtils.wrapIterable(pairs,
                 kp -> new SimpleImmutableEntry<>(kp, 
Collections.<X509Certificate> emptyList()));
     }
 }
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java
 
b/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java
index 2e9ded2..4ec21ba 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java
@@ -63,7 +63,7 @@ public class UserAuthHostBased extends AbstractUserAuth 
implements SignatureFact
     @Override
     public void init(ClientSession session, String service) throws Exception {
         super.init(session, service);
-        keys = HostKeyIdentityProvider.iteratorOf(clientHostKeys); // in case 
multiple calls to the method
+        keys = HostKeyIdentityProvider.iteratorOf(session, clientHostKeys); // 
in case multiple calls to the method
     }
 
     @Override

Reply via email to