/** Default constructor. Initializes this object using {@link DefaultConfig}. */ public SSHClient() { this(new DefaultConfig()); }
public DefaultConfig() { setLoggerFactory(LoggerFactory.DEFAULT); setVersion(readVersionFromProperties()); final boolean bouncyCastleRegistered = SecurityUtils.isBouncyCastleRegistered(); initKeyExchangeFactories(bouncyCastleRegistered); initRandomFactory(bouncyCastleRegistered); initFileKeyProviderFactories(bouncyCastleRegistered); initCipherFactories(); initCompressionFactories(); initMACFactories(); initSignatureFactories(); setKeepAliveProvider(KeepAliveProvider.HEARTBEAT); }
protected void initCompressionFactories() { setCompressionFactories(new NoneCompression.Factory()); } }
public DefaultConfig() { setVersion(VERSION); final boolean bouncyCastleRegistered = SecurityUtils.isBouncyCastleRegistered(); initKeyExchangeFactories(bouncyCastleRegistered); initRandomFactory(bouncyCastleRegistered); initFileKeyProviderFactories(bouncyCastleRegistered); initCipherFactories(); initCompressionFactories(); initMACFactories(); initSignatureFactories(); }
@Override public SSHClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException { try { final DefaultConfig configuration = new DefaultConfig(); if("zlib".equals(preferences.getProperty("ssh.compression"))) { configuration.setCompressionFactories(Arrays.asList( new DelayedZlibCompression.Factory(), new ZlibCompression.Factory(), new NoneCompression.Factory())); } else { configuration.setCompressionFactories(Collections.singletonList(new NoneCompression.Factory())); } configuration.setVersion(new PreferencesUseragentProvider().get()); final KeepAliveProvider heartbeat; if(preferences.getProperty("ssh.heartbeat.provider").equals("keep-alive")) { heartbeat = KeepAliveProvider.KEEP_ALIVE; } else { heartbeat = KeepAliveProvider.HEARTBEAT; } configuration.setKeepAliveProvider(heartbeat); return this.connect(key, configuration); } catch(IOException e) { throw new SFTPExceptionMappingService().map(e); } }
@Test @Category({SlowTests.class, KnownFailingTests.class}) public void shouldCorrectlyTerminateThreadOnDisconnect() throws IOException, InterruptedException { DefaultConfig defaultConfig = new DefaultConfig(); defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE); for (int i = 0; i < 10; i++) { SSHClient sshClient = fixture.setupClient(defaultConfig); fixture.connectClient(sshClient); sshClient.getConnection().getKeepAlive().setKeepAliveInterval(1); try { sshClient.authPassword("bad", "credentials"); fail("Should not auth."); } catch (UserAuthException e) { // OK } fixture.stopClient(); Thread.sleep(2000); } ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); for (long l : threadMXBean.getAllThreadIds()) { ThreadInfo threadInfo = threadMXBean.getThreadInfo(l); if (threadInfo.getThreadName().equals("keep-alive") && threadInfo.getThreadState() != Thread.State.TERMINATED) { fail("Found alive keep-alive thread in state " + threadInfo.getThreadState()); } } } }
protected void initRandomFactory(boolean bouncyCastleRegistered) { setRandomFactory(new SingletonRandomFactory(bouncyCastleRegistered ? new BouncyCastleRandom.Factory() : new JCERandom.Factory())); }
@Override protected Config getClientConfig(DefaultConfig config) { config.setKeyExchangeFactories(Collections.singletonList(clientFactory)); return config; }
private void doEstablishConnection() { DefaultConfig defaultConfig = new DefaultConfig(); switch (this.keepAliveProvider) { case HEARTBEAT_PROVIDER: defaultConfig.setKeepAliveProvider(KeepAliveProvider.HEARTBEAT); break; default: defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE); break;
@Test public void shouldVerifyAlgorithm() throws IOException { for (int i = 0; i < 10; i++) { logger.info("--> Attempt {}", i); configureServer(fixture.getServer()); fixture.start(); config.setRandomFactory(randomFactory); Config config = getClientConfig(this.config); SSHClient sshClient = fixture.connectClient(fixture.setupClient(config)); assertThat("should be connected", sshClient.isConnected()); sshClient.disconnect(); // fixture.stopServer(); fixture.stopClient(); } }
protected void initKeyExchangeFactories(boolean bouncyCastleRegistered) { if (bouncyCastleRegistered) { setKeyExchangeFactories( new Curve25519SHA256.Factory(), new Curve25519SHA256.FactoryLibSsh(), new DHGexSHA256.Factory(), new ECDHNistP.Factory521(), new ECDHNistP.Factory384(), new ECDHNistP.Factory256(), new DHGexSHA1.Factory(), DHGroups.Group1SHA1(), DHGroups.Group14SHA1(), DHGroups.Group14SHA256(), DHGroups.Group15SHA512(), DHGroups.Group16SHA512(), DHGroups.Group17SHA512(), DHGroups.Group18SHA512(), ExtendedDHGroups.Group14SHA256AtSSH(), ExtendedDHGroups.Group15SHA256(), ExtendedDHGroups.Group15SHA256AtSSH(), ExtendedDHGroups.Group15SHA384AtSSH(), ExtendedDHGroups.Group16SHA256(), ExtendedDHGroups.Group16SHA384AtSSH(), ExtendedDHGroups.Group16SHA512AtSSH(), ExtendedDHGroups.Group18SHA512AtSSH()); } else { setKeyExchangeFactories(DHGroups.Group1SHA1(), new DHGexSHA1.Factory()); } }
public DefaultConfig() { setLoggerFactory(LoggerFactory.DEFAULT); setVersion(readVersionFromProperties()); final boolean bouncyCastleRegistered = SecurityUtils.isBouncyCastleRegistered(); initKeyExchangeFactories(bouncyCastleRegistered); initRandomFactory(bouncyCastleRegistered); initFileKeyProviderFactories(bouncyCastleRegistered); initCipherFactories(); initCompressionFactories(); initMACFactories(); initSignatureFactories(); setKeepAliveProvider(KeepAliveProvider.HEARTBEAT); }
public SSHClient setupDefaultClient() { return setupClient(new DefaultConfig()); }
protected void initRandomFactory(boolean bouncyCastleRegistered) { setRandomFactory(new SingletonRandomFactory(bouncyCastleRegistered ? new BouncyCastleRandom.Factory() : new JCERandom.Factory())); }
protected void initKeyExchangeFactories(boolean bouncyCastleRegistered) { if (bouncyCastleRegistered) setKeyExchangeFactories(new DHG14.Factory(), new DHG1.Factory()); else setKeyExchangeFactories(new DHG1.Factory()); }
protected void initCompressionFactories() { setCompressionFactories(new NoneCompression.Factory()); } }
/** Default constructor. Initializes this object using {@link DefaultConfig}. */ public SSHClient() { this(new DefaultConfig()); }
protected void initRandomFactory(boolean bouncyCastleRegistered) { setRandomFactory(new SingletonRandomFactory(bouncyCastleRegistered ? new BouncyCastleRandom.Factory() : new JCERandom.Factory())); }
protected void initKeyExchangeFactories(boolean bouncyCastleRegistered) { if (bouncyCastleRegistered) { setKeyExchangeFactories( new Curve25519SHA256.Factory(), new Curve25519SHA256.FactoryLibSsh(), new DHGexSHA256.Factory(), new ECDHNistP.Factory521(), new ECDHNistP.Factory384(), new ECDHNistP.Factory256(), new DHGexSHA1.Factory(), DHGroups.Group1SHA1(), DHGroups.Group14SHA1(), DHGroups.Group14SHA256(), DHGroups.Group15SHA512(), DHGroups.Group16SHA512(), DHGroups.Group17SHA512(), DHGroups.Group18SHA512(), ExtendedDHGroups.Group14SHA256AtSSH(), ExtendedDHGroups.Group15SHA256(), ExtendedDHGroups.Group15SHA256AtSSH(), ExtendedDHGroups.Group15SHA384AtSSH(), ExtendedDHGroups.Group16SHA256(), ExtendedDHGroups.Group16SHA384AtSSH(), ExtendedDHGroups.Group16SHA512AtSSH(), ExtendedDHGroups.Group18SHA512AtSSH()); } else { setKeyExchangeFactories(DHGroups.Group1SHA1(), new DHGexSHA1.Factory()); } }
protected void initCompressionFactories() { setCompressionFactories(new NoneCompression.Factory()); }