diff options
Diffstat (limited to 'lib/src/main/java/com')
5 files changed, 55 insertions, 7 deletions
diff --git a/lib/src/main/java/com/trilead/ssh2/compression/CompressionFactory.java b/lib/src/main/java/com/trilead/ssh2/compression/CompressionFactory.java index a846f58..9f8d7ef 100644 --- a/lib/src/main/java/com/trilead/ssh2/compression/CompressionFactory.java +++ b/lib/src/main/java/com/trilead/ssh2/compression/CompressionFactory.java @@ -43,7 +43,7 @@ public class CompressionFactory { /* Higher Priority First */ compressors.addElement(new CompressorEntry("zlib", "com.trilead.ssh2.compression.Zlib")); - compressors.addElement(new CompressorEntry("zlib@openssh.com", "com.trilead.ssh2.compression.Zlib")); + compressors.addElement(new CompressorEntry("zlib@openssh.com", "com.trilead.ssh2.compression.ZlibOpenSSH")); compressors.addElement(new CompressorEntry("none", "")); } diff --git a/lib/src/main/java/com/trilead/ssh2/compression/ICompressor.java b/lib/src/main/java/com/trilead/ssh2/compression/ICompressor.java index 3f76326..0b435b9 100644 --- a/lib/src/main/java/com/trilead/ssh2/compression/ICompressor.java +++ b/lib/src/main/java/com/trilead/ssh2/compression/ICompressor.java @@ -27,4 +27,6 @@ public interface ICompressor { int compress(byte[] buf, int start, int len, byte[] output); byte[] uncompress(byte[] buf, int start, int[] len); + + boolean canCompressPreauth(); } diff --git a/lib/src/main/java/com/trilead/ssh2/compression/Zlib.java b/lib/src/main/java/com/trilead/ssh2/compression/Zlib.java index e9cc017..c1203a3 100644 --- a/lib/src/main/java/com/trilead/ssh2/compression/Zlib.java +++ b/lib/src/main/java/com/trilead/ssh2/compression/Zlib.java @@ -47,6 +47,10 @@ public class Zlib implements ICompressor { inflated_buf = new byte[DEFAULT_BUF_SIZE]; } + public boolean canCompressPreauth() { + return true; + } + public int getBufferSize() { return DEFAULT_BUF_SIZE; } diff --git a/lib/src/main/java/com/trilead/ssh2/compression/ZlibOpenSSH.java b/lib/src/main/java/com/trilead/ssh2/compression/ZlibOpenSSH.java new file mode 100644 index 0000000..266fff9 --- /dev/null +++ b/lib/src/main/java/com/trilead/ssh2/compression/ZlibOpenSSH.java @@ -0,0 +1,35 @@ +/* + * ConnectBot: simple, powerful, open-source SSH client for Android + * Copyright 2007 Kenny Root, Jeffrey Sharkey + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.trilead.ssh2.compression; + +/** + * Defines how zlib@openssh.org compression works. + * See + * http://www.openssh.org/txt/draft-miller-secsh-compression-delayed-00.txt + * compression is disabled until userauth has occurred. + * + * @author Matt Johnston + * + */ +public class ZlibOpenSSH extends Zlib { + + public boolean canCompressPreauth() { + return false; + } + +} diff --git a/lib/src/main/java/com/trilead/ssh2/transport/TransportConnection.java b/lib/src/main/java/com/trilead/ssh2/transport/TransportConnection.java index 77eaded..2c04ce4 100644 --- a/lib/src/main/java/com/trilead/ssh2/transport/TransportConnection.java +++ b/lib/src/main/java/com/trilead/ssh2/transport/TransportConnection.java @@ -56,7 +56,9 @@ public class TransportConnection ICompressor send_comp = null;
- boolean can_compress = false;
+ boolean can_recv_compress = false;
+
+ boolean can_send_compress = false;
byte[] recv_comp_buffer;
@@ -117,16 +119,20 @@ public class TransportConnection {
recv_comp = comp;
- if (comp != null)
+ if (comp != null) {
recv_comp_buffer = new byte[comp.getBufferSize()];
+ can_recv_compress |= recv_comp.canCompressPreauth();
+ }
}
public void changeSendCompression(ICompressor comp)
{
send_comp = comp;
- if (comp != null)
+ if (comp != null) {
send_comp_buffer = new byte[comp.getBufferSize()];
+ can_send_compress |= send_comp.canCompressPreauth();
+ }
}
public void sendMessage(byte[] message) throws IOException
@@ -152,7 +158,7 @@ public class TransportConnection else if (padd > 64)
padd = 64;
- if (send_comp != null && can_compress) {
+ if (send_comp != null && can_send_compress) {
if (send_comp_buffer.length < message.length + 1024)
send_comp_buffer = new byte[message.length + 1024];
len = send_comp.compress(message, off, len, send_comp_buffer);
@@ -313,7 +319,7 @@ public class TransportConnection + " bytes payload");
}
- if (recv_comp != null && can_compress) {
+ if (recv_comp != null && can_recv_compress) {
int[] uncomp_len = new int[] { payload_length };
buffer = recv_comp.uncompress(buffer, off, uncomp_len);
@@ -331,6 +337,7 @@ public class TransportConnection *
*/
public void startCompression() {
- can_compress = true;
+ can_recv_compress = true;
+ can_send_compress = true;
}
}
|