SFTP using both ssh key and password

Yes

not sure if it’s because I’m on 9.8 but can’t import either com.jcraft.jsch.*; or pub.CommonUtils;

To import pub.CommonUtils, you need set the package which hold this service to be depended on WmPublic.

I checked my 9.8, it has jsch.jar under <SAG_DIR>/common/lib/ext. Maybe you see a warning in Designer, but it won’t affect the compile, just ignore it and save the service.

Authentication Type
The type of authentication that Integration Server uses to authenticate itself to the SFTP server.
Client authentication can be either by password or by public and private keys.

Hi Shabaz,

this is the standard behaviour that you can choose between the two types.

But the requirement in this thread is that the SFTP-Server requires both types in sequence which is currently not possible with the built-in implementation.

Regards,
Holger

Unfortunately I’m not proficient enough in JAVA and can not get this code to run on v9.8. I’ve used the jcraft in other Java services, but not the pub.CommonUtils. Running the copied code just errors out on me :frowning: I believe I built the java service correct, but it doesn’t seem to work. Thanks for all your hard work. I’ll keep hacking at it, maybe I have code missed up.
Thanks,
Mark

Hi Mark,

did you add the package dependency to WmPublic package to your package as was requested earlier in this thread?

Can you provide the error message so we can have a look at it.

Please check for the SCG_TPS and/or SCG_TPL Fixes for 9.8 to see if there is an updated version of the jsch.jar included.

Regards,
Holger

Is there a way to make the package a dependency without adding it into the package?
I see no errors, but I also see no session key, message or code returned.
Will double check the updates, pretty sure we are up to date on the jar fixes

I do have the test package I’m working in set to have the wmPublic as a dependency. Sorry, I misunderstood.

Hi Mark,

Still have problems? If so I could send you a package.

That would be great. Thanks

Here it comes.
EnhancedSFTPClient.zip (12.6 KB)

Thanks everyone, think this will work for me.
So only difference was I set package dependency version to the version I’m using and you set to ..
Besides that, I had switched to a sftp login which I knew was working. This causes a null point error.
Must have only the duel login scenario for this code to work. Also must save the alias with the password, the update and change to key and save. Only works in this order, any other creates a null point error.
And to boot the client I was trying to connect to locked my account and unfortunately error messages doesn’t return from this java for me unless it was successful. So I’ve been chasing nothing…

I got “com.jcraft.jsch.JSchException: Auth fail” when trying to connect SFTP with a disabled account, not sure if this is the “locked account” you mentioned. Please provide more detail about your error.

And I also found a bug that might cause failed to retrieve reused sessionKey. The “return sessionKey” code is placed in wrong position.
Please use attached new package or adjust the code as below.


...
		//Cache sessionKey for reuse
		sessionKey = sftpSessionManager.addSession(session, sftpUserAlias.getSessionTimeout(), userAlias); 	
	}
		
	//Return sessionKey
	CommonUtils.mergeOutput(dataCursor, "sessionKey", sessionKey);
			
	populateResult(dataCursor, null, 2);
} catch (Throwable th) {
	CommonUtils.throwAsServiceException(th);
...

EnhancedSFTPClient.zip (12.6 KB)

That is exactly what the locked out issue was. those errors are not coming back as failed returnCode/Msg. Can only find that in the results as long as you stop right after trying to login.
Updated the code.
Thanks again

The native login service will throw exception either in this case.

The flow exits on the java errors. I’ll just wrap everything in a try/catch and grab the last error on fail. Thanks

Seems there is a slight hiccup. I tried creating a new user alias. Saved with password, then saved with key. NullPointerException.
Seems the code works the first time, but any past that don’t work. I even deleted my original working alias, and now nothing works.
Seems error is somewhere in the retrivePassword
“Caused by: java.lang.NullPointerException
at kit.enhancedSFTPClient.retrivePasswordAsString(enhancedSFTPClient.java:141)
at kit.enhancedSFTPClient.login(enhancedSFTPClient.java:87)”

Is there a way to flush whatever it’s looking for and start new?

If you have problem to retrieve password value, you could use service pub.security.outboundPasswords:setPassword to force adding a new one or use service pub.security.outboundPasswords:updatePassword to update an existing one. For one sftp user alias, make sure both password below exist.

The key input follow the pattern below:
For sftp client user password, it’s “wm.is.admin.sftpclient.password.”
For sftp client key phrase, it’s “wm.is.admin.sftpclient.pass.phrase.”
Example my user alias is “test”, then corresponding key is “wm.is.admin.sftpclient.password.test” and “wm.is.admin.sftpclient.pass.phrase.test”.

You need invoke service pub.security.util:createSecureString to convert a String to SecureString, and pass it the these services I mentioned above.

And if you have security error to invoke these services, set extended setting watt.security.ope.AllowInternalPasswordAccess=true, then restart IS.