use of org.apache.sshd.common.keyprovider.FileKeyPairProvider in project camel by apache.
the class SshComponentTestSupport method setUp.
@Override
public void setUp() throws Exception {
port = AvailablePortFinder.getNextAvailable(22000);
sshd = SshServer.setUpDefaultServer();
sshd.setPort(port);
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
sshd.setCommandFactory(new TestEchoCommandFactory());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
sshd.setPublickeyAuthenticator(new BogusPublickeyAuthenticator());
sshd.start();
super.setUp();
}
use of org.apache.sshd.common.keyprovider.FileKeyPairProvider in project camel by apache.
the class ScpServerTestSupport method startSshd.
protected boolean startSshd() {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getPort());
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
// dummy authentication: allow any user whose password is the same as the username
return username != null && username.equals(password);
}
});
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return true;
}
});
try {
sshd.start();
return true;
} catch (IOException e) {
LOG.info("Failed to start ssh server.", e);
}
return false;
}
use of org.apache.sshd.common.keyprovider.FileKeyPairProvider in project gerrit by GerritCodeReview.
the class HostKeyProvider method get.
@Override
public KeyPairProvider get() {
Path objKey = site.ssh_key;
Path rsaKey = site.ssh_rsa;
Path dsaKey = site.ssh_dsa;
Path ecdsaKey_256 = site.ssh_ecdsa_256;
Path ecdsaKey_384 = site.ssh_ecdsa_384;
Path ecdsaKey_521 = site.ssh_ecdsa_521;
Path ed25519Key = site.ssh_ed25519;
final List<File> stdKeys = new ArrayList<>(6);
if (Files.exists(rsaKey)) {
stdKeys.add(rsaKey.toAbsolutePath().toFile());
}
if (Files.exists(dsaKey)) {
stdKeys.add(dsaKey.toAbsolutePath().toFile());
}
if (Files.exists(ecdsaKey_256)) {
stdKeys.add(ecdsaKey_256.toAbsolutePath().toFile());
}
if (Files.exists(ecdsaKey_384)) {
stdKeys.add(ecdsaKey_384.toAbsolutePath().toFile());
}
if (Files.exists(ecdsaKey_521)) {
stdKeys.add(ecdsaKey_521.toAbsolutePath().toFile());
}
if (Files.exists(ed25519Key)) {
stdKeys.add(ed25519Key.toAbsolutePath().toFile());
}
if (Files.exists(objKey)) {
if (stdKeys.isEmpty()) {
SimpleGeneratorHostKeyProvider p = new SimpleGeneratorHostKeyProvider();
p.setPath(objKey.toAbsolutePath());
return p;
}
// Both formats of host key exist, we don't know which format
// should be authoritative. Complain and abort.
//
stdKeys.add(objKey.toAbsolutePath().toFile());
throw new ProvisionException("Multiple host keys exist: " + stdKeys);
}
if (stdKeys.isEmpty()) {
throw new ProvisionException("No SSH keys under " + site.etc_dir);
}
FileKeyPairProvider kp = new FileKeyPairProvider();
kp.setFiles(stdKeys);
return kp;
}
use of org.apache.sshd.common.keyprovider.FileKeyPairProvider in project karaf by apache.
the class ClientMojo method startAgent.
private SshAgent startAgent(String user, URL privateKeyUrl, File keyFile) {
try (InputStream is = privateKeyUrl.openStream()) {
SshAgent agent = new AgentImpl();
ObjectInputStream r = new ObjectInputStream(is);
KeyPair keyPair = (KeyPair) r.readObject();
is.close();
agent.addIdentity(keyPair, user);
if (keyFile != null) {
FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(keyFile.getAbsoluteFile().toPath());
for (KeyPair key : fileKeyPairProvider.loadKeys()) {
agent.addIdentity(key, user);
}
}
return agent;
} catch (Throwable e) {
getLog().error("Error starting ssh agent for: " + e.getMessage(), e);
return null;
}
}
use of org.apache.sshd.common.keyprovider.FileKeyPairProvider in project karaf by apache.
the class DeployMojo method startAgent.
private SshAgent startAgent(String user, URL privateKeyUrl, File keyFile) {
try (InputStream is = privateKeyUrl.openStream()) {
SshAgent agent = new AgentImpl();
ObjectInputStream r = new ObjectInputStream(is);
KeyPair keyPair = (KeyPair) r.readObject();
is.close();
agent.addIdentity(keyPair, user);
if (keyFile != null) {
FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(keyFile.getAbsoluteFile().toPath());
for (KeyPair key : fileKeyPairProvider.loadKeys()) {
agent.addIdentity(key, user);
}
}
return agent;
} catch (Throwable e) {
getLog().error("Error starting ssh agent for: " + e.getMessage(), e);
return null;
}
}
Aggregations