473,418 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Trying to SSH to a trusted server

112 100+
I am trying to SSH to a trusted server, without using a password but I am getting this error:

null
[Ljava.lang.StackTraceElement;@3b1d04



This is the code that I am using:

Expand|Select|Wrap|Line Numbers
  1. SshClient ssh = new SshClient();
  2.  
  3.  
  4. ssh.connect("prdgc103b", new ConsoleKnownHostsKeyVerification());
  5.  
  6.  
The known_hosts file is located at
$HOME/.ssh/known_hosts which is the default for the ConsoleKnownHostsKeyVerification() method.

Can someone please tell me what I am doing wrong.

Thanks
Sep 20 '10 #1
10 6338
ndedhia1
112 100+
I have fixed the above error by putting in the correct path name for the known_hosts file, but now, how do i authenticate?
There is no password that is needed to get onto these servers because it is trusted.
Sep 20 '10 #2
Oralloy
988 Expert 512MB
@ndedhia1,

You should get back a SSL certificate as part of the authentication process. You'll have to verify that it is derived from a trusted certificate.

With SSL, there are several standard authentication providers, and they let you root your certificate to theirs. These providers are self proclaimed, and only accepted because the community accepts them.

If you want, you can provide your own root authentication server. I've done it in the past to keep managers from crying too much while the real certificates are acquired.

Hopefully that helps some.

Cheers!
Sep 20 '10 #3
ndedhia1
112 100+
hi Oralloy,
thanks for the help!!
Do you have any code examples of the SSL certificates you were talking about?

Right now, I am doing the authenticating like this:

Expand|Select|Wrap|Line Numbers
  1. pwd.setUsername(user);
  2. pwd.setPassword(password);
  3. // Authenticate the user
  4. int result = ssh.authenticate(pwd);
  5. if(result==AuthenticationProtocolState.COMPLETED) {
  6. System.out.println("Authentication Completed");
  7. }
  8.  
But the only problem with this is that there is no password. When i dont try to authenticate the password, I get an error saying that password or user cannot be null.

Thanks again!!
Sep 21 '10 #4
Oralloy
988 Expert 512MB
ndedhia1,

For some reason I thought you were using SSL, not SSH. I gave you a bum post, and I apologize for that.

Still, I'll look around and see what we can do.

As I recall for SSH (not SSL), hosts and clients have optional mutual recognition. Most hosts I've worked with are permissive, though, and don't complain when they don't recognize the client computer. Clients often complain (look at the implementation of PUTTy) about host recognition, because the user is too lazy to update the known_hosts and keys files. But, you likely know this.

BTW, if you don't have a password, try sending a zero length string (""), instead of null, or none at all.

Again, my apologies for the brain fart yesterday.

Luck!
Oralloy
Sep 21 '10 #5
ndedhia1
112 100+
hi Oralloy.
No problem with the mistake. It happens to everyone:)

Here is the output I get from my connect and authentication code:
Also, I tried it with an empty password and that failed also.

Expand|Select|Wrap|Line Numbers
  1.           ssh.connect(host, new ConsoleKnownHostsKeyVerification("$HOME/.ssh/known_hosts"));
  2.  
  3.  
  4.            System.out.println("BEFORE AUTHENTICATION");
  5.          //Authenticate
  6.  
  7.            PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
  8.            passwordAuthenticationClient.setUsername(user);
  9. //          passwordAuthenticationClient.setPassword(password);
  10.  

Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.publickey.SshKeyPairF actory <clinit>
INFO: Loading public key algorithms
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.configuration.ConfigurationLoad er initialize
INFO: JAVA version is 1.6.0_11-rev
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.configuration.ConfigurationLoad er initialize
INFO: Extension /usr/local/jdk1.6.0_11/jre/lib/ext/sunjce_provider.jar being added to classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.util.ExtensionClassLoader add
INFO: Adding /usr/local/jdk1.6.0_11/jre/lib/ext/sunjce_provider.jar to the extension classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.configuration.ConfigurationLoad er initialize
INFO: Extension /usr/local/jdk1.6.0_11/jre/lib/ext/sunpkcs11.jar being added to classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.util.ExtensionClassLoader add
INFO: Adding /usr/local/jdk1.6.0_11/jre/lib/ext/sunpkcs11.jar to the extension classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.configuration.ConfigurationLoad er initialize
INFO: Extension /usr/local/jdk1.6.0_11/jre/lib/ext/dnsns.jar being added to classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.util.ExtensionClassLoader add
INFO: Adding /usr/local/jdk1.6.0_11/jre/lib/ext/dnsns.jar to the extension classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.configuration.ConfigurationLoad er initialize
INFO: Extension /usr/local/jdk1.6.0_11/jre/lib/ext/tools.jar being added to classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.util.ExtensionClassLoader add
INFO: Adding /usr/local/jdk1.6.0_11/jre/lib/ext/tools.jar to the extension classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.configuration.ConfigurationLoad er initialize
INFO: Extension /usr/local/jdk1.6.0_11/jre/lib/ext/localedata.jar being added to classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.util.ExtensionClassLoader add
INFO: Adding /usr/local/jdk1.6.0_11/jre/lib/ext/localedata.jar to the extension classpath
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.cipher.SshCipherFacto ry <clinit>
INFO: Loading supported cipher algorithms
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.kex.SshKeyExchangeFac tory <clinit>
INFO: Loading key exchange methods
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.compression.SshCompre ssionFactory <clinit>
INFO: Loading compression methods
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.hmac.SshHmacFactory <clinit>
INFO: Loading message authentication methods
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.TransportProtocolComm on startTransportProtocol
INFO: Starting transport protocol
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.TransportProtocolComm on run
INFO: Registering transport protocol messages with inputstream
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.TransportProtocolComm on negotiateVersion
INFO: Negotiating protocol version
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.TransportProtocolComm on negotiateVersion
INFO: Protocol negotiation complete
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.TransportProtocolComm on beginKeyExchange
INFO: Starting key exchange
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.kex.DhGroup1Sha1 performClientExchange
INFO: Starting client side key exchange.
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.AbstractKnownHostsKey Verification verifyHost
INFO: Verifying prdgc103b,10.170.114.4 host key
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.TransportProtocolClie nt verifyHostKey
INFO: The host key signature is valid
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.TransportProtocolComm on completeKeyExchange
INFO: Completing key exchange
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.cipher.SshCipherFacto ry newInstance
INFO: Creating new blowfish-cbc cipher instance
Sep 21, 2010 10:11:38 AM com.sshtools.j2ssh.transport.cipher.SshCipherFacto ry newInstance
INFO: Creating new blowfish-cbc cipher instance
BEFORE AUTHENTICATION
YOU FAILED IN THE CONNECT
Error: com.sshtools.j2ssh.authentication.AuthenticationPr otocolException: Username and password cannot be null!
Sep 21 '10 #6
Oralloy
988 Expert 512MB
Hey, have you tried looking at:

http://www.sshtools.com/en/kb/idx.ph...-Maverick.html
Sep 21 '10 #7
ndedhia1
112 100+
Hey Oralloy,
Before I try you suggested way, I found a way to authenticate using key, which is the way that I am connecting to the server. Now the problem that i am getting is that I am getting this error when running the below program:

ISCONNECTED: true
I got past the authenticate the public key
Sep 21, 2010 12:31:43 PM com.sshtools.j2ssh.transport.publickey.SshPrivateK eyFile parse
INFO: Parsing private key file
Sep 21, 2010 12:31:43 PM com.sshtools.j2ssh.transport.publickey.SshPrivateK eyFile parse
INFO: Private key is not in the default format, attempting parse with other supported formats
YOU FAILED IN THE CONNECT
Error: com.sshtools.j2ssh.transport.publickey.InvalidSshK eyException: The key format is not a supported format


I found an example of this code that I thought would help but the parse method did allow 2 arguments:

do you have any thoughts on how i can format the key to the supported format.

I found this information in the Java SSH API User's Guide.

Thanks for all the help so far!!

THIS IS THE EXAMPLE I FOUND ON HOW TO FORMAT THE KEY BUT THE PARSE DIDNT ALLOW IT:
Expand|Select|Wrap|Line Numbers
  1. // Open up the private key file
  2. SshPrivateKeyFile file =
  3.   SshPrivateKeyFile.parse(new File(filename),
  4.               new SshtoolsPrivateKeyFormat());
  5.  
  6.  

Expand|Select|Wrap|Line Numbers
  1. Once your server is configured you can connect using your newly generated key with the following code: 
  2.  
  3.  
  4. import com.sshtools.j2ssh.transport.publickey.SshPrivateKey;
  5. import com.sshtools.j2ssh.transport.publickey.SshPrivateKeyFile;
  6. import com.sshtools.j2ssh.transport.publickey.SshtoolsPrivateKeyFormat;
  7. import com.sshtools.j2ssh.transport.publickey.SshPrivateKey;
  8.  
  9. /**
  10. * Authenticate using a public key
  11. */
  12. PublicKeyAuthenticationClient pk = new PublicKeyAuthenticationClient();
  13. pk.setUsername(user);         
  14.  
  15. // Open up the private key file
  16. SshPrivateKeyFile file =
  17.   SshPrivateKeyFile.parse(new File("$HOME/.ssh/known_hosts"));
  18.  
  19. // Get the key
  20. SshPrivateKey key = file.toPrivateKey(password);
  21.  
  22. // Set the key and authenticate
  23. pk.setKey(key);
  24. int result = session.authenticate(pk);
  25.  
Sep 21 '10 #8
ndedhia1
112 100+
Hey Oralloy,
I got it to work. The reason that it was giving me this error:

INFO: Private key is not in the default format, attempting parse with other supported formats
YOU FAILED IN THE CONNECT
Error: com.sshtools.j2ssh.transport.publickey.InvalidSshK eyException: The key format is not a supported format

was because I had it pointing to the know_hosts file and not to the private key file.

THANKS FOR ALL YOUR HELP!!
Sep 21 '10 #9
Oralloy
988 Expert 512MB
ndedhia1,

I can't say I did much besides cheer you on.

Still, I'm glad you've got it working.

Cheers!
Oralloy
Sep 21 '10 #10
ndedhia1
112 100+
Hey Oralloy,
I have another question regarding blowfish-cbc cipher instance.
Before I give you the code, I was wondering if you have come across this issue.
My program will be running fine for hours or even days without this occurring, but every once in a while, it will get stuck on this part:

Expand|Select|Wrap|Line Numbers
  1. INFO: Creating new blowfish-cbc cipher instance.
  2. Jan 31, 2014 3:11:09 PM com.sshtools.j2ssh.transport.cipher.SshCipherFactory new Instance
  3. INFO: Creating new blowfish-cbc cipher instance
  4.  
My application will just sit there doing nothing till I shut it down and restart it.

Do you by any chance know the reason for this?

THanks!!
Jan 31 '14 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: bigDWK | last post by:
Hi- Is it possible to do a trusted connection for a web server not on the same physical machine. By this I mean can I make a remote connection from a web server to a sql server using a trusted...
1
by: charliewest | last post by:
I am trying use server controls or web controls to simulate the following behavior. I've an image wrapped w/in a link to create a rollover effect as if both elements we're one graphic: <a...
2
by: Jay | last post by:
Hi, Twice this has happened..... WinXP Pro SP2. SQL server 2000 When I have used a third party app (.net tool) to select my sql box from the "available list" it pauses for a while and the drop...
2
by: Blake Versiga | last post by:
I am pulling my hair out..... I am trying to put a bound data grid on a webform... I have 4 data connections in my server explorer, all of which connect successfully. But when I run the web...
4
by: Brian Henry | last post by:
I an trying to connect to a sql server in asp.net with the sql connection object, and every time i try to open the connection i get this Server Error in '/' Application. Login failed for user...
2
by: Gmansky | last post by:
I am just trying the server and wrote a simple test page accessing an access db. This same page works on the workstation with webmatrix. However, I am getting this error when I run it on the...
3
by: Mad Scientist Jr | last post by:
I am getting the following error when trying to access a database with a trusted connection: "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection." My...
1
by: dhan72 | last post by:
I got the trusted server connection error in MSSQL.How can I overcome from this error.
3
by: Kevinp | last post by:
I'm trying to get my program to connect to a SQL Server 2005 database over the internet. The remote computer is on another network and it's connected to our network through Windows VPN. I'm running...
9
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
I want to download pfx from my asp.net server, add the pfx to client's X509Store as a trusted publisher, Is it possible? my func in aspx is like this: void InstallCertification() { try{...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.