|
61 | 61 | * @author Pat Turner
|
62 | 62 | * @author Artem Bilan
|
63 | 63 | * @author Krzysztof Debski
|
| 64 | + * @author Auke Zaaiman |
64 | 65 | *
|
65 | 66 | * @since 2.0
|
66 | 67 | */
|
@@ -335,36 +336,45 @@ private void doInitClient() throws IOException {
|
335 | 336 | if (this.port <= 0) {
|
336 | 337 | this.port = SshConstants.DEFAULT_PORT;
|
337 | 338 | }
|
338 |
| - ServerKeyVerifier serverKeyVerifier = |
339 |
| - this.allowUnknownKeys ? AcceptAllServerKeyVerifier.INSTANCE : RejectAllServerKeyVerifier.INSTANCE; |
340 |
| - if (this.knownHosts != null) { |
341 |
| - serverKeyVerifier = new ResourceKnownHostsServerKeyVerifier(this.knownHosts); |
342 |
| - } |
343 |
| - this.sshClient.setServerKeyVerifier(serverKeyVerifier); |
344 |
| - |
345 |
| - this.sshClient.setPasswordIdentityProvider(PasswordIdentityProvider.wrapPasswords(this.password)); |
346 |
| - if (this.privateKey != null) { |
347 |
| - IoResource<Resource> privateKeyResource = |
348 |
| - new AbstractIoResource<>(Resource.class, this.privateKey) { |
349 |
| - |
350 |
| - @Override |
351 |
| - public InputStream openInputStream() throws IOException { |
352 |
| - return getResourceValue().getInputStream(); |
353 |
| - } |
354 |
| - }; |
355 |
| - try { |
356 |
| - Collection<KeyPair> keys = |
357 |
| - SecurityUtils.getKeyPairResourceParser() |
358 |
| - .loadKeyPairs(null, privateKeyResource, |
359 |
| - FilePasswordProvider.of(this.privateKeyPassphrase)); |
360 |
| - this.sshClient.setKeyIdentityProvider(KeyIdentityProvider.wrapKeyPairs(keys)); |
| 339 | + |
| 340 | + doInitInnerClient(); |
| 341 | + |
| 342 | + this.sshClient.start(); |
| 343 | + } |
| 344 | + |
| 345 | + private void doInitInnerClient() throws IOException { |
| 346 | + if (this.isInnerClient) { |
| 347 | + ServerKeyVerifier serverKeyVerifier = |
| 348 | + this.allowUnknownKeys ? AcceptAllServerKeyVerifier.INSTANCE : RejectAllServerKeyVerifier.INSTANCE; |
| 349 | + if (this.knownHosts != null) { |
| 350 | + serverKeyVerifier = new ResourceKnownHostsServerKeyVerifier(this.knownHosts); |
361 | 351 | }
|
362 |
| - catch (GeneralSecurityException ex) { |
363 |
| - throw new IOException("Cannot load private key: " + this.privateKey.getFilename(), ex); |
| 352 | + this.sshClient.setServerKeyVerifier(serverKeyVerifier); |
| 353 | + |
| 354 | + this.sshClient.setPasswordIdentityProvider(PasswordIdentityProvider.wrapPasswords(this.password)); |
| 355 | + if (this.privateKey != null) { |
| 356 | + IoResource<Resource> privateKeyResource = |
| 357 | + new AbstractIoResource<>(Resource.class, this.privateKey) { |
| 358 | + |
| 359 | + @Override |
| 360 | + public InputStream openInputStream() throws IOException { |
| 361 | + return getResourceValue().getInputStream(); |
| 362 | + } |
| 363 | + |
| 364 | + }; |
| 365 | + try { |
| 366 | + Collection<KeyPair> keys = |
| 367 | + SecurityUtils.getKeyPairResourceParser() |
| 368 | + .loadKeyPairs(null, privateKeyResource, |
| 369 | + FilePasswordProvider.of(this.privateKeyPassphrase)); |
| 370 | + this.sshClient.setKeyIdentityProvider(KeyIdentityProvider.wrapKeyPairs(keys)); |
| 371 | + } |
| 372 | + catch (GeneralSecurityException ex) { |
| 373 | + throw new IOException("Cannot load private key: " + this.privateKey.getFilename(), ex); |
| 374 | + } |
364 | 375 | }
|
| 376 | + this.sshClient.setUserInteraction(this.userInteraction); |
365 | 377 | }
|
366 |
| - this.sshClient.setUserInteraction(this.userInteraction); |
367 |
| - this.sshClient.start(); |
368 | 378 | }
|
369 | 379 |
|
370 | 380 | @Override
|
|
0 commit comments