diff options
Diffstat (limited to 'lib/src/main/java/com/trilead/ssh2/packets')
7 files changed, 109 insertions, 20 deletions
diff --git a/lib/src/main/java/com/trilead/ssh2/packets/PacketChannelTrileadPing.java b/lib/src/main/java/com/trilead/ssh2/packets/PacketChannelTrileadPing.java new file mode 100644 index 0000000..18002aa --- /dev/null +++ b/lib/src/main/java/com/trilead/ssh2/packets/PacketChannelTrileadPing.java @@ -0,0 +1,35 @@ +
+package com.trilead.ssh2.packets;
+
+/**
+ * PacketChannelTrileadPing.
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: PacketChannelTrileadPing.java,v 1.1 2008/03/03 07:01:36
+ * cplattne Exp $
+ */
+public class PacketChannelTrileadPing
+{
+ byte[] payload;
+
+ public int recipientChannelID;
+
+ public PacketChannelTrileadPing(int recipientChannelID)
+ {
+ this.recipientChannelID = recipientChannelID;
+ }
+
+ public byte[] getPayload()
+ {
+ if (payload == null)
+ {
+ TypesWriter tw = new TypesWriter();
+ tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST);
+ tw.writeUINT32(recipientChannelID);
+ tw.writeString("trilead-ping");
+ tw.writeBoolean(true);
+ payload = tw.getBytes();
+ }
+ return payload;
+ }
+}
diff --git a/lib/src/main/java/com/trilead/ssh2/packets/PacketDisconnect.java b/lib/src/main/java/com/trilead/ssh2/packets/PacketDisconnect.java index b88bf11..1811fb3 100644 --- a/lib/src/main/java/com/trilead/ssh2/packets/PacketDisconnect.java +++ b/lib/src/main/java/com/trilead/ssh2/packets/PacketDisconnect.java @@ -1,11 +1,13 @@ +
package com.trilead.ssh2.packets;
+
import java.io.IOException;
/**
* PacketDisconnect.
*
* @author Christian Plattner, plattner@trilead.com
- * @version $Id: PacketDisconnect.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ * @version $Id: PacketDisconnect.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
*/
public class PacketDisconnect
{
@@ -25,8 +27,7 @@ public class PacketDisconnect int packet_type = tr.readByte();
if (packet_type != Packets.SSH_MSG_DISCONNECT)
- throw new IOException("This is not a Disconnect Packet! ("
- + packet_type + ")");
+ throw new IOException("This is not a Disconnect Packet! (" + packet_type + ")");
reason = tr.readUINT32();
desc = tr.readString();
@@ -39,7 +40,7 @@ public class PacketDisconnect this.desc = desc;
this.lang = lang;
}
-
+
public byte[] getPayload()
{
if (payload == null)
diff --git a/lib/src/main/java/com/trilead/ssh2/packets/PacketGlobalCancelForwardRequest.java b/lib/src/main/java/com/trilead/ssh2/packets/PacketGlobalCancelForwardRequest.java index e102322..bc54b2e 100644 --- a/lib/src/main/java/com/trilead/ssh2/packets/PacketGlobalCancelForwardRequest.java +++ b/lib/src/main/java/com/trilead/ssh2/packets/PacketGlobalCancelForwardRequest.java @@ -5,7 +5,8 @@ package com.trilead.ssh2.packets; * PacketGlobalCancelForwardRequest.
*
* @author Christian Plattner, plattner@trilead.com
- * @version $Id: PacketGlobalCancelForwardRequest.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ * @version $Id: PacketGlobalCancelForwardRequest.java,v 1.1 2007/10/15 12:49:55
+ * cplattne Exp $
*/
public class PacketGlobalCancelForwardRequest
{
@@ -28,7 +29,7 @@ public class PacketGlobalCancelForwardRequest {
TypesWriter tw = new TypesWriter();
tw.writeByte(Packets.SSH_MSG_GLOBAL_REQUEST);
-
+
tw.writeString("cancel-tcpip-forward");
tw.writeBoolean(wantReply);
tw.writeString(bindAddress);
diff --git a/lib/src/main/java/com/trilead/ssh2/packets/PacketGlobalTrileadPing.java b/lib/src/main/java/com/trilead/ssh2/packets/PacketGlobalTrileadPing.java new file mode 100644 index 0000000..5b9013d --- /dev/null +++ b/lib/src/main/java/com/trilead/ssh2/packets/PacketGlobalTrileadPing.java @@ -0,0 +1,32 @@ +
+package com.trilead.ssh2.packets;
+
+/**
+ * PacketGlobalTrileadPing.
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: PacketGlobalTrileadPing.java,v 1.1 2008/03/03 07:01:36 cplattne Exp $
+ */
+public class PacketGlobalTrileadPing
+{
+ byte[] payload;
+
+ public PacketGlobalTrileadPing()
+ {
+ }
+
+ public byte[] getPayload()
+ {
+ if (payload == null)
+ {
+ TypesWriter tw = new TypesWriter();
+ tw.writeByte(Packets.SSH_MSG_GLOBAL_REQUEST);
+
+ tw.writeString("trilead-ping");
+ tw.writeBoolean(true);
+
+ payload = tw.getBytes();
+ }
+ return payload;
+ }
+}
diff --git a/lib/src/main/java/com/trilead/ssh2/packets/PacketServiceAccept.java b/lib/src/main/java/com/trilead/ssh2/packets/PacketServiceAccept.java index f0b3c70..5081651 100644 --- a/lib/src/main/java/com/trilead/ssh2/packets/PacketServiceAccept.java +++ b/lib/src/main/java/com/trilead/ssh2/packets/PacketServiceAccept.java @@ -1,3 +1,4 @@ +
package com.trilead.ssh2.packets;
import java.io.IOException;
@@ -6,14 +7,14 @@ import java.io.IOException; * PacketServiceAccept.
*
* @author Christian Plattner, plattner@trilead.com
- * @version $Id: PacketServiceAccept.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ * @version $Id: PacketServiceAccept.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
*/
public class PacketServiceAccept
{
byte[] payload;
String serviceName;
-
+
public PacketServiceAccept(String serviceName)
{
this.serviceName = serviceName;
@@ -29,11 +30,19 @@ public class PacketServiceAccept int packet_type = tr.readByte();
if (packet_type != Packets.SSH_MSG_SERVICE_ACCEPT)
- throw new IOException("This is not a SSH_MSG_SERVICE_ACCEPT! ("
- + packet_type + ")");
+ throw new IOException("This is not a SSH_MSG_SERVICE_ACCEPT! (" + packet_type + ")");
+
+ /* Be clever in case the server is not. Some servers seem to violate RFC4253 */
+
+ if (tr.remain() > 0)
+ {
+ serviceName = tr.readString();
+ }
+ else
+ {
+ serviceName = "";
+ }
- serviceName = tr.readString();
-
if (tr.remain() != 0)
throw new IOException("Padding in SSH_MSG_SERVICE_ACCEPT packet!");
}
diff --git a/lib/src/main/java/com/trilead/ssh2/packets/TypesReader.java b/lib/src/main/java/com/trilead/ssh2/packets/TypesReader.java index 2b770cb..c8d73e7 100644 --- a/lib/src/main/java/com/trilead/ssh2/packets/TypesReader.java +++ b/lib/src/main/java/com/trilead/ssh2/packets/TypesReader.java @@ -11,7 +11,7 @@ import com.trilead.ssh2.util.Tokenizer; * TypesReader.
*
* @author Christian Plattner, plattner@trilead.com
- * @version $Id: TypesReader.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ * @version $Id: TypesReader.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
*/
public class TypesReader
{
@@ -157,7 +157,8 @@ public class TypesReader if ((len + pos) > max)
throw new IOException("Malformed SSH string.");
- String res = new String(arr, pos, len);
+ String res = new String(arr, pos, len, "ISO-8859-1");
+
pos += len;
return res;
diff --git a/lib/src/main/java/com/trilead/ssh2/packets/TypesWriter.java b/lib/src/main/java/com/trilead/ssh2/packets/TypesWriter.java index 41fe7b5..f2e5ef3 100644 --- a/lib/src/main/java/com/trilead/ssh2/packets/TypesWriter.java +++ b/lib/src/main/java/com/trilead/ssh2/packets/TypesWriter.java @@ -8,7 +8,7 @@ import java.math.BigInteger; * TypesWriter.
*
* @author Christian Plattner, plattner@trilead.com
- * @version $Id: TypesWriter.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ * @version $Id: TypesWriter.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
*/
public class TypesWriter
{
@@ -39,7 +39,7 @@ public class TypesWriter System.arraycopy(arr, 0, dst, 0, pos);
return dst;
}
-
+
public void getBytes(byte dst[])
{
System.arraycopy(arr, 0, dst, 0, pos);
@@ -113,7 +113,7 @@ public class TypesWriter {
writeBytes(buff, 0, buff.length);
}
-
+
public void writeBytes(byte[] buff, int off, int len)
{
if ((pos + len) > arr.length)
@@ -131,16 +131,26 @@ public class TypesWriter public void writeString(String v)
{
- byte[] b = v.getBytes();
+ byte[] b;
+
+ try
+ {
+ /* All Java JVMs must support ISO-8859-1 */
+ b = v.getBytes("ISO-8859-1");
+ }
+ catch (UnsupportedEncodingException ignore)
+ {
+ b = v.getBytes();
+ }
writeUINT32(b.length);
writeBytes(b, 0, b.length);
}
-
+
public void writeString(String v, String charsetName) throws UnsupportedEncodingException
{
byte[] b = (charsetName == null) ? v.getBytes() : v.getBytes(charsetName);
-
+
writeUINT32(b.length);
writeBytes(b, 0, b.length);
}
|