use of com.jcraft.jsch.HostKey in project spring-cloud-config by spring-cloud.
the class PropertyBasedSshSessionFactory method createSession.
@Override
protected Session createSession(Host hc, String user, String host, int port, FS fs) throws JSchException {
if (sshKeysByHostname.containsKey(host)) {
SshUri sshUriProperties = sshKeysByHostname.get(host);
jSch.addIdentity(host, sshUriProperties.getPrivateKey().getBytes(), null, null);
if (sshUriProperties.getKnownHostsFile() != null) {
jSch.setKnownHosts(sshUriProperties.getKnownHostsFile());
}
if (sshUriProperties.getHostKey() != null) {
HostKey hostkey = new HostKey(host, Base64.decode(sshUriProperties.getHostKey()));
jSch.getHostKeyRepository().add(hostkey, null);
}
return jSch.getSession(user, host, port);
}
throw new JSchException("no keys configured for hostname " + host);
}
use of com.jcraft.jsch.HostKey in project spring-cloud-config by spring-cloud.
the class PropertyBasedSshSessionFactoryTest method hostKeyIsUsed.
@Test
public void hostKeyIsUsed() throws Exception {
SshUri sshKey = new SshUriProperties.SshUriPropertiesBuilder().uri("git@gitlab.example.local:someorg/somerepo.git").hostKey(HOST_KEY).privateKey(PRIVATE_KEY).build();
setupSessionFactory(sshKey);
factory.createSession(hc, null, SshUriPropertyProcessor.getHostname(sshKey.getUri()), 22, null);
ArgumentCaptor<HostKey> captor = ArgumentCaptor.forClass(HostKey.class);
verify(hostKeyRepository).add(captor.capture(), isNull());
HostKey hostKey = captor.getValue();
Assert.assertEquals("gitlab.example.local", hostKey.getHost());
Assert.assertEquals(HOST_KEY, hostKey.getKey());
}
use of com.jcraft.jsch.HostKey in project sw360portal by sw360.
the class FossologyHostKeyRepositoryTest method testCheckAValidNewKeyIsSavedAsUntrusted.
@Test
public void testCheckAValidNewKeyIsSavedAsUntrusted() throws Exception {
when(connector.getAll()).thenReturn(Collections.<FossologyHostFingerPrint>emptyList());
String host = "host";
byte[] key = GOOD_KEY.getBytes();
final String expectedFingerPrint = new HostKey(host, key).getFingerPrint(jSch);
assertThat(expectedFingerPrint, not(isEmptyOrNullString()));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
FossologyHostFingerPrint fingerPrint = (FossologyHostFingerPrint) invocation.getArguments()[0];
assertThat(fingerPrint.getFingerPrint(), is(expectedFingerPrint));
assertFalse(fingerPrint.isTrusted());
return null;
}
}).when(connector).add(any(FossologyHostFingerPrint.class));
assertThat(repo.check(host, key), is(HostKeyRepository.NOT_INCLUDED));
verify(connector).getAll();
verify(connector).add(any(FossologyHostFingerPrint.class));
}
use of com.jcraft.jsch.HostKey in project sw360portal by sw360.
the class FossologyHostKeyRepositoryTest method testCheckAValidKnownUntrustedKeyIsNotTrusted.
@Test
public void testCheckAValidKnownUntrustedKeyIsNotTrusted() throws Exception {
String host = "host";
byte[] key = GOOD_KEY.getBytes();
final String expectedFingerPrint = new HostKey(host, key).getFingerPrint(jSch);
assertThat(expectedFingerPrint, not(isEmptyOrNullString()));
when(connector.getAll()).thenReturn(ImmutableList.of(new FossologyHostFingerPrint().setFingerPrint(expectedFingerPrint).setTrusted(false)));
assertThat(repo.check(host, key), is(HostKeyRepository.NOT_INCLUDED));
verify(connector).getAll();
verify(connector, never()).add(any(FossologyHostFingerPrint.class));
}
use of com.jcraft.jsch.HostKey in project sw360portal by sw360.
the class FossologyHostKeyRepositoryTest method testAdd.
@Test
public void testAdd() {
UserInfo ui = mock(UserInfo.class);
HostKey hk = mock(HostKey.class);
expectUnsupported();
repo.add(hk, ui);
}
Aggregations