-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue127 #128
Issue127 #128
Changes from 2 commits
f7f7be8
fee4dd7
f8220b3
f71753e
7c2f3e1
ffe145d
c156b66
8de3843
6431bcf
48a6ff2
1cc013c
af03841
b127caf
55e3ef3
636d0d1
77a878e
c7d1466
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
public interface Compression{ | ||
static public final int INFLATER=0; | ||
static public final int DEFLATER=1; | ||
void init(int type, int level) throws Exception; | ||
void init(Session session, int type, int level) throws Exception; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #126 I've attempted to restore the backwards incompatibilities I introduced in several public interfaces. Could we change revert this method signature back, and then instead add something like this?
That way this interface maintains backwards compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've reverted the change but solved it a bit differently to keep code duplication in juz.Compression and jzlib.Compression to a minimum. There is now a default setSession-method doing nothing and a static logMessage in Session with a Supplier that is now called in both Compression-implementations. |
||
byte[] compress(byte[] buf, int start, int[] len); | ||
byte[] uncompress(byte[] buf, int start, int[] len); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ public class JSch{ | |
/** | ||
* The version number. | ||
*/ | ||
public static final String VERSION = Version.getVersion(); | ||
public static final String VERSION = "0.2.0"; //Version.getVersion(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part needs to be reverted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That part wasn't intended to be in the commit |
||
|
||
static Hashtable<String, String> config=new Hashtable<>(); | ||
static{ | ||
|
@@ -280,13 +280,14 @@ public void setConfigRepository(ConfigRepository configRepository) { | |
|
||
private HostKeyRepository known_hosts=null; | ||
|
||
private static final Logger DEVNULL=new Logger(){ | ||
static final Logger DEVNULL=new Logger(){ | ||
@Override | ||
public boolean isEnabled(int level){return false;} | ||
@Override | ||
public void log(int level, String message){} | ||
}; | ||
static Logger logger=DEVNULL; | ||
private Logger instLogger; | ||
|
||
public JSch(){ | ||
} | ||
|
@@ -682,6 +683,17 @@ public static void setLogger(Logger logger){ | |
JSch.logger=logger; | ||
} | ||
|
||
public Logger getInstanceLogger() { | ||
if (this.instLogger == null) { | ||
return logger; | ||
} | ||
return instLogger; | ||
} | ||
|
||
public void setInstanceLogger(Logger logger) { | ||
this.instLogger = logger; | ||
} | ||
|
||
public static Logger getLogger(){ | ||
return logger; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,11 @@ public abstract class KeyExchange{ | |
|
||
public abstract void init(Session session, | ||
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception; | ||
public void doInit(Session session, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should make this public. I'd change it to package private. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed it. I've copied init's method signature to make sure that the parameters are identical. |
||
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception { | ||
this.session = session; | ||
init(session, V_S, V_C, I_S, I_C); | ||
} | ||
public abstract boolean next(Buffer buf) throws Exception; | ||
|
||
public abstract int getState(); | ||
|
@@ -96,13 +101,13 @@ protected static String[] guess(Session session, byte[]I_S, byte[]I_C) throws Ex | |
Buffer sb=new Buffer(I_S); sb.setOffSet(17); | ||
Buffer cb=new Buffer(I_C); cb.setOffSet(17); | ||
|
||
if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
if(session.getLogger().isEnabled(Logger.INFO)){ | ||
for(int i=0; i<PROPOSAL_MAX; i++){ | ||
JSch.getLogger().log(Logger.INFO, | ||
session.getLogger().log(Logger.INFO, | ||
"kex: server: "+Util.byte2str(sb.getString())); | ||
} | ||
for(int i=0; i<PROPOSAL_MAX; i++){ | ||
JSch.getLogger().log(Logger.INFO, | ||
session.getLogger().log(Logger.INFO, | ||
"kex: client: "+Util.byte2str(cb.getString())); | ||
} | ||
sb.setOffSet(17); | ||
|
@@ -164,17 +169,17 @@ else if(guess[i]==null){ | |
throw new JSchException(e.toString(), e); | ||
} | ||
|
||
if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
JSch.getLogger().log(Logger.INFO, | ||
if(session.getLogger().isEnabled(Logger.INFO)){ | ||
session.getLogger().log(Logger.INFO, | ||
"kex: algorithm: "+guess[PROPOSAL_KEX_ALGS]); | ||
JSch.getLogger().log(Logger.INFO, | ||
session.getLogger().log(Logger.INFO, | ||
"kex: host key algorithm: "+guess[PROPOSAL_SERVER_HOST_KEY_ALGS]); | ||
JSch.getLogger().log(Logger.INFO, | ||
session.getLogger().log(Logger.INFO, | ||
"kex: server->client"+ | ||
" cipher: "+guess[PROPOSAL_ENC_ALGS_STOC]+ | ||
" MAC: "+(_s2cAEAD?("<implicit>"):(guess[PROPOSAL_MAC_ALGS_STOC]))+ | ||
" compression: "+guess[PROPOSAL_COMP_ALGS_STOC]); | ||
JSch.getLogger().log(Logger.INFO, | ||
session.getLogger().log(Logger.INFO, | ||
"kex: client->server"+ | ||
" cipher: "+guess[PROPOSAL_ENC_ALGS_CTOS]+ | ||
" MAC: "+(_c2sAEAD?("<implicit>"):(guess[PROPOSAL_MAC_ALGS_CTOS]))+ | ||
|
@@ -255,8 +260,8 @@ protected boolean verify(String alg, byte[] K_S, int index, | |
sig.update(H); | ||
result=sig.verify(sig_of_H); | ||
|
||
if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
JSch.getLogger().log(Logger.INFO, | ||
if(session.getLogger().isEnabled(Logger.INFO)){ | ||
session.getLogger().log(Logger.INFO, | ||
"ssh_rsa_verify: "+foo+" signature "+result); | ||
} | ||
} | ||
|
@@ -300,8 +305,8 @@ else if(alg.equals("ssh-dss")){ | |
sig.update(H); | ||
result=sig.verify(sig_of_H); | ||
|
||
if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
JSch.getLogger().log(Logger.INFO, | ||
if(session.getLogger().isEnabled(Logger.INFO)){ | ||
session.getLogger().log(Logger.INFO, | ||
"ssh_dss_verify: signature "+result); | ||
} | ||
} | ||
|
@@ -345,8 +350,8 @@ else if(alg.equals("ecdsa-sha2-nistp256") || | |
|
||
result=sig.verify(sig_of_H); | ||
|
||
if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
JSch.getLogger().log(Logger.INFO, | ||
if(session.getLogger().isEnabled(Logger.INFO)){ | ||
session.getLogger().log(Logger.INFO, | ||
"ssh_ecdsa_verify: "+alg+" signature "+result); | ||
} | ||
} | ||
|
@@ -378,8 +383,8 @@ else if(alg.equals("ssh-ed25519") || | |
|
||
result=sig.verify(sig_of_H); | ||
|
||
if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
JSch.getLogger().log(Logger.INFO, | ||
if(session.getLogger().isEnabled(Logger.INFO)){ | ||
session.getLogger().log(Logger.INFO, | ||
"ssh_eddsa_verify: "+alg+" signature "+result); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,15 @@ public void writePrivateKey(OutputStream out, byte[] passphrase){ | |
|
||
abstract byte[] getKeyTypeName(); | ||
public abstract int getKeyType(); | ||
|
||
public String getKeyTypeName(String encoding) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part seems unrelated to the logging changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is. Shouldn't be part of the commit, either. |
||
try { | ||
return new String(getKeyTypeName(), encoding); | ||
} | ||
catch(UnsupportedEncodingException uee) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the blob of the public key. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,6 +201,7 @@ public void run(){ | |
OutputStream out=socket.getOutputStream(); | ||
if(socketPath!=null && socketPath.length()>0){ | ||
ChannelDirectStreamLocal channel = new ChannelDirectStreamLocal(); | ||
channel.setSession(session); | ||
channel.init(); | ||
channel.setInputStream(in); | ||
channel.setOutputStream(out); | ||
|
@@ -211,7 +212,9 @@ public void run(){ | |
channel.connect(connectTimeout); | ||
} else { | ||
ChannelDirectTCPIP channel = new ChannelDirectTCPIP(); | ||
channel.setSession(session); | ||
channel.init(); | ||
channel.setSession(session); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be. I'll remove the second one (I suppose while going over the changes I've missed the first setSession I've already added and added the second one). |
||
channel.setInputStream(in); | ||
channel.setOutputStream(out); | ||
session.addChannel(channel); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should perhaps we just add a
Session session
argument to each of the constructors of theChannelXXX
implementations instead of adding an explicitsetSession(session)
call below?That would then allow us to remove the
addChannel()
method inSession
&PortWatcher
classes I think?@mwiede any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've solved it this way to keep the number of affected classes as low as possible. As far as I can see, the solution with
setChannel()
(that is implemented in the abstract classChannel
) would allow you to do the same, or do I miss something here?