The answer to this question depends on what you want to use for the ssh session: is it something software or do you want to show the user a terminal session or console where they can enter arbitrary commands? This second option is for the most part fairly easy to maintain, as you can see from studying the ConnectBot manifest - the application has an intent filter registered for ConsoleActivity that matches this pattern:
- action :
android.intent.action.VIEW - uri :
ssh:// user@host :port/#nickname
... he will not close the session afterwards, but in addition he will do whatever you specify, using your own ConnectBot infrastructure to connect and using any SSH keys that the user has registered in the ConnectBot application.
Alternatively , you can talk about the previous option: for your application to execute a specific command on the SSH server programmatically .
This is currently not supported by the official version of ConnectBot. Depending on your requirements, you can imagine that you simply missed ConnectBot’s intention with the server address and the command you want to execute; which will not be too difficult for ConnectBot to implement, and it will save you from the headache of too much to learn the ssh protocol. However, this intention does not exist, and if it were done, it would be very dangerous, any application on the phone could use it to execute arbitrary code with user credentials on remote servers.
What exists is the intention that I created in the fixed version of ConnectBot several months ago to support Agit , the Git client for Android:
org.openintents.ssh.BIND_SSH_AGENT_SERVICE
This patched version of ConnectBot allows ConnectBot to act as an ssh-agent - your application is responsible for managing the ssh connection, but you can call ConnectBot to obtain the necessary credentials - ConnectBot will tell you which public keys it has to connect and will sign digital problems required for authentication. The protocol information is on OpenIntents.org , but basically you use the intention of contacting ConnectBot, getting the AIDL interface that provides the agent ssh functionality:
org.openintents.ssh.BIND_SSH_AGENT_SERVICE
As a precaution, your application will need to declare that it is using this permission, or it will not be able to bind to the service:
org.openintents.ssh.permission.ACCESS_SSH_AGENT
The patchbot version of ConnectBot can be downloaded from the Android Market here:
https://market.android.com/details?id=com.madgag.ssh.agent
The source code for the patch is here:
http://code.google.com/r/robertotyley-connectbot-ssh-agent/source/list?name=ssh-agent
Although this will take care of managing the public / private key, it still leaves you the opportunity to implement an ssh connection in your application. I would recommend the sshj library to support the ssh protocol, see an example of a simple command connection:
https://github.com/shikhar/sshj/blob/v0.6.1/src/main/java/examples/Exec.java
Crypto libs Bouncy Castle are commonly used in Java to provide encryption algorithms, however, the Android version is crippled and not easily overridden - therefore, you should use Spongy Castle libraries for Android-friendly repackaging of BC libraries:
https://github.com/rtyley/spongycastle