Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Adjusted authorization type to a list for easy additions
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Osborn <osbornjd@ornl.gov>
  • Loading branch information
Joe Osborn committed Nov 25, 2019
1 parent d49df50 commit e491f4f
Showing 1 changed file with 23 additions and 8 deletions.
Expand Up @@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.ice.commands;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

Expand Down Expand Up @@ -49,6 +50,13 @@ public class ConnectionManager {
*/
private boolean requireStrictHostKeyChecking = true;

/**
* This is a list of authorization types for JSch to allow authentication via.
* The default types added automatically are ssh-rsa and ecdsa-sha2-nistp256.
* Clients can add additional types should they need to.
*/
private ArrayList<String> authTypes = new ArrayList<String>();

/**
* String containing the path to the known hosts directory. Can be set to
* something else if the user has a different default known_host
Expand All @@ -62,6 +70,10 @@ public ConnectionManager() {
// If the OS is windows, then change the known hosts to be windows style
if (System.getProperty("os.name").toLowerCase().contains("win"))
knownHosts = System.getProperty("user.home") + "\\.ssh\\known_hosts";

// Add the default authorization types
authTypes.add("ssh-rsa");
authTypes.add("ecdsa-sha2-nistp256");
}

/**
Expand Down Expand Up @@ -102,14 +114,9 @@ public Connection openConnection(ConnectionConfiguration config) throws JSchExce
authorizeSession(newConnection);

// JSch default requests ssh-rsa host checking, but some keys
// request ecdsa-sha2-nistp256. So loop through the available
// host keys that were grabbed from known_hosts and add all
// available ssh key check types to those that JSch can authenticate
HostKeyRepository hkr = jsch.getHostKeyRepository();
String type = null;
for (HostKey hk : hkr.getHostKey()) {
type = hk.getType();
// Set the session configuration key type to that hosts type
// request other types. Loop through the available authorization types
// and add them to the session.
for(String type : authTypes) {
newConnection.getSession().setConfig("server_host_key", type);
}

Expand Down Expand Up @@ -364,4 +371,12 @@ public void setKnownHosts(String knownHosts) {
this.knownHosts = knownHosts;
}

/**
* This function allows clients to add an authorization type for which JSch can
* authorize with. ssh-rsa and ecdsa-sha2-nistp256 are added by default.
* @param type
*/
public void addAuthorizationType(String type) {
authTypes.add(type);
}
}

0 comments on commit e491f4f

Please sign in to comment.