Thanks Borislav:
Independently after instrumenting the code (It would definitely help if
something were logged by default) I discovered the JAAS Authentication was not
setup and adding a .java.login.config made authentication possible. However, I
do see one oddity - if I have agent forwarding setup and log back onto the same
machine that is running everything hangs when an ssh-add occurs. Granted this
is a degenerate case but it also doesn't seem to be an issue in native ssh or
when using a keyfile. Also after reading up on JAAS I don't quite get the
usage model. Does everyone require the users to do this configuration step
which seems quite cumbersome? I've been playing around with setting the
java.security.auth.login.config property but that still doesn't get me all the
way to the end experience I want.
Thanks again,
Ben
From: Borislav Stoichkov [mailto:[email protected]]
Sent: Thursday, February 10, 2011 7:55 PM
To: Leis, Benjamin
Cc: [email protected]
Subject: Re: [JSch-users] Getting kerberos working
Hello Benjamin
You need to verify that that you have the GSSContextKrb5 class in the jar file
or the classpath you are using. If you are using the jar file, the class is
available in versions 36-40,42 but missing in 41,43,44. If you want to use a
jar of one of the versions that does not have the class, you will need to
compile it.
You will also need to create a JAAS login configuration file. It needs to be
passed as a property along with a configuration file for Kerberos. The
parameters you will need are
-Djava.security.auth.config=/path/to/jaas/login.conf
-Djavax.security.auth.useSubjectCredsOnly=false
-Djava.security.krb5.conf=/path/to/krb5.conf. You will also need an existing
valid credentials cache or a keytab file. For more information on the login
file as well as other useful information take a look at these links
http://download.oracle.com/javase/1,5.0/docs/guide/security/jgss/tutorials/index.html
http://download.oracle.com/javase/1,5.0/docs/guide/security/jgss/tutorials/BasicClientServer.html
http://download.oracle.com/javase/1,5.0/docs/guide/security/jaas/spec/com/sun/security/auth/module/Krb5LoginModule.html
An example login file that uses an existing cache might look something like this
com.sun.security.jgss.initiate {
com.sun.security.auth.module.Krb5LoginModule required
debug="false"
doNotPrompt="true"
useTicketCache="true"
ticketCache="/path/to/krb5cc_username"
;
};
Good luck!
Borislav
On Thu, Feb 10, 2011 at 6:52 PM, Leis, Benjamin
<[email protected]<mailto:[email protected]>> wrote:
Hi
I'm experimenting with Jsch and got private key ssh connections to work without
a hitch. I'm now trying to do Kerberos authentication and am getting
authentication failures:
My code:
jsch = new JSch();
jsch.setLogger( SIMPLE_LOGGER );
if ( sshKeyPath != null )
{
jsch.addIdentity( sshKeyPath );
}
jsch.setKnownHosts( "/dev/null" );
session= jsch.getSession( targetUser, targetNode, SSH_PORT );
config = new java.util.Properties();
config.put( "StrictHostKeyChecking", "no" );
config.put("PreferredAuthentications",
"gssapi-with-mic,publickey" );
session.setConfig( config );
session.connect( SSH_CONNECT_TIMEOUT );
channel = (ChannelExec)session.openChannel( "exec" );
channel.setCommand( targetCommand );
channel.setAgentForwarding( true );
inStream = channel.getInputStream();
channel.connect( SSH_CHANNEL_TIMEOUT );
With logging on I'm seeing:
junit] SSH_MSG_KEXINIT sent
[junit] SSH_MSG_KEXINIT received
[junit] kex: server->client aes128-ctr hmac-md5 none
[junit] kex: client->server aes128-ctr hmac-md5 none
[junit] SSH_MSG_KEXDH_INIT sent
[junit] expecting SSH_MSG_KEXDH_REPLY
[junit] ssh_rsa_verify: signature true
[junit] Permanently added 'benleis.desktop' (RSA) to the list of known
hosts.
[junit] SSH_MSG_NEWKEYS sent
[junit] SSH_MSG_NEWKEYS received
[junit] SSH_MSG_SERVICE_REQUEST sent
[junit] SSH_MSG_SERVICE_ACCEPT received
[junit] Authentications that can continue: gssapi-with-mic,publickey
[junit] Next authentication method: gssapi-with-mic
[junit] Authentications that can continue: publickey
[junit] Next authentication method: publickey
[junit] Disconnecting from benleis.desktop port 22
[junit] line: Failed to open the SSH channel to benleis.desktop: Auth fail
com.jcraft.jsch.JSchException
Compared to a verbose cmd-line ssh login which succeeds:
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'benleis.desktop' is known and matches the RSA host key.
debug1: Found key in /home/benleis/.ssh/known_hosts:30
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Authentication succeeded (gssapi-with-mic).
I've not done much with Kerberos before. Does anyone have advice on diagnosing
the failure or some option I need to configure to get this working?
Thanks
Ben
__o __o __o __o
_`\<,_ _`\<,_ _`\<,_ _`\<,_
(*)/ (*) (*)/ (*) (*)/ (*) (*)/ (*)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
JSch-users mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/jsch-users
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users