if (authTimeout == null) {
authTimeout = SSH_SERVER_AUTH_DEFAULT_TIMEOUT;
}
//
Resource serverKey = null;
KeyPairProvider keyPairProvider = null;
// Get embedded default key
URL serverKeyURL = SSHPlugin.class.getResource("/crash/hostkey.pem");
if (serverKeyURL != null) {
try {
log.log(Level.FINE, "Found embedded key url " + serverKeyURL);
serverKey = new Resource("hostkey.pem", serverKeyURL);
}
catch (IOException e) {
log.log(Level.FINE, "Could not load ssh key from url " + serverKeyURL, e);
}
}
// Override from config if any
Resource serverKeyRes = getContext().loadResource("hostkey.pem", ResourceKind.CONFIG);
if (serverKeyRes != null) {
serverKey = serverKeyRes;
log.log(Level.FINE, "Found server ssh key url");
}
// If we have a key path, we convert is as an URL
String serverKeyPath = getContext().getProperty(SSH_SERVER_KEYPATH);
if (serverKeyPath != null) {
log.log(Level.FINE, "Found server key path " + serverKeyPath);
File f = new File(serverKeyPath);
String keyGen = getContext().getProperty(SSH_SERVER_KEYGEN);
if (keyGen != null && keyGen.equals("true")) {
keyPairProvider = new PEMGeneratorHostKeyProvider(serverKeyPath, "RSA");
} else if (f.exists() && f.isFile()) {
try {
serverKeyURL = f.toURI().toURL();
serverKey = new Resource("hostkey.pem", serverKeyURL);
} catch (MalformedURLException e) {
log.log(Level.FINE, "Ignoring invalid server key " + serverKeyPath, e);
} catch (IOException e) {
log.log(Level.FINE, "Could not load SSH key from " + serverKeyPath, e);
}