Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

how to use bouncycastle ciphers ?

nephylim
2010-08-24
2013-05-20
  • nephylim
    nephylim
    2010-08-24

    does anyone know how to use the bouncycastle ciphers ? I have added the provider in the lib directory, and added the provider in java.security but I still don't see the ciphers enabled when checking the network packets.
    Is enabling this provider enough, or is it necessary to add some java code ?

     
  • Pat
    Pat
    2010-08-24

    Assuming you can already specify the ciphers elsewhere in your code, com.sshtools.j2ssh.transport.cipher.SshCipherFactory needs to add these as well -

    import com.sshtools.ext.bouncycastle.cipher.*;

          addCipher("aes128-cbc", AES128Cbc.class);
          addCipher("aes192-cbc", AES192Cbc.class);
          addCipher("aes256-cbc", AES256Cbc.class);
          addCipher("cast-128-cbc", CAST128Cbc.class);
          addCipher("twofish128-cbc", Twofish128Cbc.class);
          addCipher("twofish192-cbc", Twofish192Cbc.class);
          addCipher("twofish256-cbc", Twofish256Cbc.class);

    Instead of changing java.security you can add the bc provider jar to your classpath and load it dynamically (if not already done - see Bouncy Castle for how to do this).

    If you do not have the com.sshtools.ext.bouncycastle.cipher package get it from CVS  at http://sshtools.cvs.sourceforge.net/viewvc/sshtools/code/src/com/sshtools/ext/

     
  • nephylim
    nephylim
    2010-08-27

    I added as you said with ciphers.put("…" and not addCipher
    I downloaded the bouncycastle ciphers and built a jar with them.
    Now I have another exception :

    27 ao¹t 2010 12:02:53 com.sshtools.j2ssh.transport.cipher.SshCipherFactory <clinit>
    INFO: Loading supported cipher algorithms
    27 ao¹t 2010 12:02:54 com.sshtools.j2ssh.transport.kex.SshKeyExchangeFactory <clinit>
    INFO: Loading key exchange methods
    27 ao¹t 2010 12:02:54 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize

    INFO: Loading public key algorithms
    27 ao¹t 2010 12:02:54 com.sshtools.j2ssh.transport.compression.SshCompressionFactory <clinit>
    INFO: Loading compression methods
    27 ao¹t 2010 12:02:54 com.sshtools.j2ssh.transport.hmac.SshHmacFactory <clinit>
    INFO: Loading message authentication methods
    java.net.BindException: Cannot assign requested address: bind

     
  • Pat
    Pat
    2010-08-27

    java.net.BindException: Cannot assign requested address: bind  - usually indicates the desired port is in use - but just guessing without a stack trace.

     
  • nephylim
    nephylim
    2010-09-07

    thanks for helpin, here is the stack :

    7 sept. 2010 11:20:03 com.sshtools.j2ssh.transport.cipher.SshCipherFactory <clinit>
    INFO: Loading supported cipher algorithms
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.transport.kex.SshKeyExchangeFactory <clinit>
    INFO: Loading key exchange methods
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\user\Java\jre6u18\lib\ext\bcprov136.jar being added to classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\user\Java\jre6u18\lib\ext\bcprov136.jar to the extension classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\user\Java\jre6u18\lib\ext\dnsns.jar being added to classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\user\Java\jre6u18\lib\ext\dnsns.jar to the extension classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\user\Java\jre6u18\lib\ext\gnu-crypto.jar being added to classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\user\Java\jre6u18\lib\ext\gnu-crypto.jar to the extension classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\user\Java\jre6u18\lib\ext\ibmjsseprovider.jar being added to classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\user\Java\jre6u18\lib\ext\ibmjsseprovider.jar to the extension classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\user\Java\jre6u18\lib\ext\localedata.jar being added to classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\user\Java\jre6u18\lib\ext\localedata.jar to the extension classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\user\Java\jre6u18\lib\ext\sunjce_provider.jar being added to classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\user\Java\jre6u18\lib\ext\sunjce_provider.jar to the extension classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\user\Java\jre6u18\lib\ext\sunmscapi.jar being added to classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\user\Java\jre6u18\lib\ext\sunmscapi.jar to the extension classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\user\Java\jre6u18\lib\ext\sunpkcs11.jar being added to classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\user\Java\jre6u18\lib\ext\sunpkcs11.jar to the extension classpath
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory <clinit>
    INFO: Loading public key algorithms
    7 sept. 2010 11:20:03 com.sshtools.j2ssh.transport.compression.SshCompressionFactory <clinit>
    INFO: Loading compression methods
    7 sept. 2010 11:20:04 com.sshtools.j2ssh.transport.hmac.SshHmacFactory <clinit>
    INFO: Loading message authentication methods
    java.net.BindException: Cannot assign requested address: bind

     
  • Pat
    Pat
    2010-09-08

    A stack trace of the exception should look something like -
    java.net.BindException: Cannot assign requested address: bind
    at sun.nio.ch.Net.bind(Native Method)
    at sun.nio.ch.SocketChannelImpl.bind(Unknown Source)
    at sun.nio.ch.SocketAdaptor.bind(Unknown Source)
    at
    com.sshtools.j2ssh.net.TransportProviderFactory.connectTransportProvider
    (TransportProviderFactory.java:67)
    at com.sshtools.j2ssh.SshClient.connect(SshClient.java:773)

    You will need to build the j2ssh jar with debug on - if you're using the build.xml it would be
      <property name="build.debugInformation" value="on" />

    A simple example to recreate the issue would also be helpful like -

    Code to duplicate the error:

    SshClient ssh = new SshClient();
    ssh.connect("remote-host.mydomain.com", 22, new AlwaysAllowingConsoleKnownHostsKeyVerification());

     
  • nephylim
    nephylim
    2010-09-08

    code is simple :

    import com.sshtools.j2ssh.SshClient;
    import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient;
    import com.sshtools.j2ssh.session.SessionChannelClient;
    import com.sshtools.j2ssh.configuration.SshConnectionProperties;
    import com.sshtools.j2ssh.transport.IgnoreHostKeyVerification;

    public class Test {
      public static void main(String args) {
        try {
          SshConnectionProperties sshcp  = new SshConnectionProperties();
          sshcp.setHost("esedevweb01.fr.world.socgen");
          SshClient ssh = new SshClient();
          ssh.connect(sshcp, new IgnoreHostKeyVerification());
         }
        catch(java.io.IOException ioe) {
          ioe.printStackTrace();
        }
      }
    }

    stack is similar to yours :

    INFO: Loading message authentication methods
    java.net.BindException: Cannot assign requested address: bind
            at sun.nio.ch.Net.bind(Native Method)
            at sun.nio.ch.SocketChannelImpl.bind(Unknown Source)
            at sun.nio.ch.SocketAdaptor.bind(Unknown Source)
            at com.sshtools.j2ssh.net.TransportProviderFactory.connectTransportProvider(TransportProviderFactory.java:67)
            at com.sshtools.j2ssh.SshClient.connect(SshClient.java:773)
            at Test.main(Test.java:36)

     
  • Pat
    Pat
    2010-09-08

    You are going to have to add debug around at com.sshtools.j2ssh.net.TransportProviderFactory.connectTransportProvider(TransportProviderFactory.java:67)  to pinpoint the problem.

    A few suggestions - try an ip address rather than a host name, attempt a normal socket connection rather than a SOCKS5 proxy connection, and try to telnet the host/port with a system command in your code before attempting the SSH connection.

     
  • nephylim
    nephylim
    2010-09-09

    "My" mistake, sorry…
    I was using the source code coming from j2ssh-fork which is supposed to be compliant on this part, but even trying with their compiled libs I can't run anything.
    I agree with the above (message n°2), this works as expected.
    thanks for helping