Rayane Chandar
2014-09-23 23:28:02 UTC
Hi,
I noticed that when you call this method in JSch class:
publicvoidaddIdentity(String name, byte[]prvkey, byte[]pubkey, byte[] passphrase) throwsJSchException
The method returns with the parameter prvkeyno longer to it's orignal value. Which makes it difficult to call this method many times (in case the credentials do not change and you wish to redo a connection) with the same prvKey since it is modified after the first call.
But if inside IdentityFileclass, in (privateIdentityFile(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throwsJSchException), instead of doing :
byte[] buf=prvkey; (this does not prevent from modifying inside the method, the original passed parameter)
you do a :
byte[] buf = new byte[prvkey.length];
System.arraycopy(prvkey, 0, buf, 0, prvkey.length);Youâll operate on a copy, and the original remains intact at the end of the method.
What I do now is calling the addIdentity by giving it a copy of my private key prvkey ( a copy by System.arraycopy, before calling the method).
Hoping I've been clear.
Regards,
I noticed that when you call this method in JSch class:
publicvoidaddIdentity(String name, byte[]prvkey, byte[]pubkey, byte[] passphrase) throwsJSchException
The method returns with the parameter prvkeyno longer to it's orignal value. Which makes it difficult to call this method many times (in case the credentials do not change and you wish to redo a connection) with the same prvKey since it is modified after the first call.
But if inside IdentityFileclass, in (privateIdentityFile(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throwsJSchException), instead of doing :
byte[] buf=prvkey; (this does not prevent from modifying inside the method, the original passed parameter)
you do a :
byte[] buf = new byte[prvkey.length];
System.arraycopy(prvkey, 0, buf, 0, prvkey.length);Youâll operate on a copy, and the original remains intact at the end of the method.
What I do now is calling the addIdentity by giving it a copy of my private key prvkey ( a copy by System.arraycopy, before calling the method).
Hoping I've been clear.
Regards,