本文整理汇总了Java中com.trilead.ssh2.packets.Packets类的典型用法代码示例。如果您正苦于以下问题:Java Packets类的具体用法?Java Packets怎么用?Java Packets使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Packets类属于com.trilead.ssh2.packets包,在下文中一共展示了Packets类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: sendEOF
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void sendEOF(Channel c) throws IOException
{
byte[] msg = new byte[5];
synchronized (c)
{
if (c.state != Channel.STATE_OPEN)
return;
msg[0] = Packets.SSH_MSG_CHANNEL_EOF;
msg[1] = (byte) (c.remoteID >> 24);
msg[2] = (byte) (c.remoteID >> 16);
msg[3] = (byte) (c.remoteID >> 8);
msg[4] = (byte) (c.remoteID);
}
synchronized (c.channelSendLock)
{
if (c.closeMessageSent == true)
return;
tm.sendMessage(msg);
}
if (log.isEnabled())
log.log(50, "Sent EOF (Channel " + c.localID + "/" + c.remoteID + ")");
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:27,代码来源:ChannelManager.java
示例2: msgGlobalRequest
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void msgGlobalRequest(byte[] msg, int msglen) throws IOException
{
/* Currently we do not support any kind of global request */
TypesReader tr = new TypesReader(msg, 0, msglen);
tr.readByte(); // skip packet type
String requestName = tr.readString();
boolean wantReply = tr.readBoolean();
if (wantReply)
{
byte[] reply_failure = new byte[1];
reply_failure[0] = Packets.SSH_MSG_REQUEST_FAILURE;
tm.sendAsynchronousMessage(reply_failure);
}
/* We do not clean up the requestName String - that is OK for debug */
if (log.isEnabled())
log.log(80, "Got SSH_MSG_GLOBAL_REQUEST (" + requestName + ")");
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:24,代码来源:ChannelManager.java
示例3: msgGlobalRequest
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void msgGlobalRequest(byte[] msg, int msglen) throws IOException {
/* Currently we do not support any kind of global request */
TypesReader tr = new TypesReader(msg, 0, msglen);
tr.readByte(); // skip packet type
String requestName = tr.readString();
boolean wantReply = tr.readBoolean();
if (wantReply) {
byte[] reply_failure = new byte[1];
reply_failure[0] = Packets.SSH_MSG_REQUEST_FAILURE;
tm.sendAsynchronousMessage(reply_failure);
}
/* We do not clean up the requestName String - that is OK for debug */
if (log.isEnabled())
log.log(80, "Got SSH_MSG_GLOBAL_REQUEST (" + requestName + ")");
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:22,代码来源:ChannelManager.java
示例4: sendEOF
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void sendEOF(Channel c) throws IOException {
byte[] msg = new byte[5];
synchronized (c) {
if (c.state != Channel.STATE_OPEN)
return;
msg[0] = Packets.SSH_MSG_CHANNEL_EOF;
msg[1] = (byte) (c.remoteID >> 24);
msg[2] = (byte) (c.remoteID >> 16);
msg[3] = (byte) (c.remoteID >> 8);
msg[4] = (byte) (c.remoteID);
}
synchronized (c.channelSendLock) {
if (c.closeMessageSent == true)
return;
tm.sendMessage(msg);
}
if (log.isEnabled())
log.log(50, "Sent EOF (Channel " + c.localID + "/" + c.remoteID
+ ")");
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:25,代码来源:ChannelManager.java
示例5: closeChannel
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void closeChannel(Channel c, String reason, boolean force) throws IOException
{
byte msg[] = new byte[5];
synchronized (c)
{
if (force)
{
c.state = Channel.STATE_CLOSED;
c.EOF = true;
}
c.setReasonClosed(reason);
msg[0] = Packets.SSH_MSG_CHANNEL_CLOSE;
msg[1] = (byte) (c.remoteID >> 24);
msg[2] = (byte) (c.remoteID >> 16);
msg[3] = (byte) (c.remoteID >> 8);
msg[4] = (byte) (c.remoteID);
c.notifyAll();
}
synchronized (c.channelSendLock)
{
if (c.closeMessageSent == true)
return;
tm.sendMessage(msg);
c.closeMessageSent = true;
}
if (log.isEnabled())
log.log(50, "Sent SSH_MSG_CHANNEL_CLOSE (channel " + c.localID + ")");
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:35,代码来源:ChannelManager.java
示例6: getNextMessage
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
byte[] getNextMessage() throws IOException
{
while (true)
{
byte[] msg = deQueue();
if (msg[0] != Packets.SSH_MSG_USERAUTH_BANNER)
return msg;
PacketUserauthBanner sb = new PacketUserauthBanner(msg, 0, msg.length);
banner = sb.getBanner();
}
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:15,代码来源:AuthenticationManager.java
示例7: initialize
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
private boolean initialize(String user) throws IOException
{
if (initDone == false)
{
tm.registerMessageHandler(this, 0, 255);
PacketServiceRequest sr = new PacketServiceRequest("ssh-userauth");
tm.sendMessage(sr.getPayload());
PacketUserauthRequestNone urn = new PacketUserauthRequestNone("ssh-connection", user);
tm.sendMessage(urn.getPayload());
byte[] msg = getNextMessage();
new PacketServiceAccept(msg, 0, msg.length);
msg = getNextMessage();
initDone = true;
if (msg[0] == Packets.SSH_MSG_USERAUTH_SUCCESS)
{
authenticated = true;
tm.removeMessageHandler(this, 0, 255);
return true;
}
if (msg[0] == Packets.SSH_MSG_USERAUTH_FAILURE)
{
PacketUserauthFailure puf = new PacketUserauthFailure(msg, 0, msg.length);
remainingMethods = puf.getAuthThatCanContinue();
isPartialSuccess = puf.isPartialSuccess();
return false;
}
throw new IOException("Unexpected SSH message (type " + msg[0] + ")");
}
return authenticated;
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:39,代码来源:AuthenticationManager.java
示例8: authenticatePassword
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public boolean authenticatePassword(String user, String pass) throws IOException
{
try
{
initialize(user);
if (methodPossible("password") == false)
throw new IOException("Authentication method password not supported by the server at this stage.");
PacketUserauthRequestPassword ua = new PacketUserauthRequestPassword("ssh-connection", user, pass);
tm.sendMessage(ua.getPayload());
byte[] ar = getNextMessage();
if (ar[0] == Packets.SSH_MSG_USERAUTH_SUCCESS)
{
authenticated = true;
tm.removeMessageHandler(this, 0, 255);
return true;
}
if (ar[0] == Packets.SSH_MSG_USERAUTH_FAILURE)
{
PacketUserauthFailure puf = new PacketUserauthFailure(ar, 0, ar.length);
remainingMethods = puf.getAuthThatCanContinue();
isPartialSuccess = puf.isPartialSuccess();
return false;
}
throw new IOException("Unexpected SSH message (type " + ar[0] + ")");
}
catch (IOException e)
{
tm.close(e, false);
throw (IOException) new IOException("Password authentication failed.").initCause(e);
}
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:41,代码来源:AuthenticationManager.java
示例9: closeChannel
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void closeChannel(Channel c, String reason, boolean force)
throws IOException {
byte msg[] = new byte[5];
synchronized (c) {
if (force) {
c.state = Channel.STATE_CLOSED;
c.EOF = true;
}
c.setReasonClosed(reason);
msg[0] = Packets.SSH_MSG_CHANNEL_CLOSE;
msg[1] = (byte) (c.remoteID >> 24);
msg[2] = (byte) (c.remoteID >> 16);
msg[3] = (byte) (c.remoteID >> 8);
msg[4] = (byte) (c.remoteID);
c.notifyAll();
}
synchronized (c.channelSendLock) {
if (c.closeMessageSent == true)
return;
tm.sendMessage(msg);
c.closeMessageSent = true;
}
if (log.isEnabled())
log.log(50, "Sent SSH_MSG_CHANNEL_CLOSE (channel " + c.localID
+ ")");
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:33,代码来源:ChannelManager.java
示例10: authenticatePassword
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public boolean authenticatePassword(String user, String pass)
throws IOException {
try {
initialize(user);
if (methodPossible("password") == false)
throw new IOException(
"Authentication method password not supported by the server at this stage.");
PacketUserauthRequestPassword ua = new PacketUserauthRequestPassword(
"ssh-connection", user, pass);
tm.sendMessage(ua.getPayload());
byte[] ar = getNextMessage();
if (ar[0] == Packets.SSH_MSG_USERAUTH_SUCCESS) {
authenticated = true;
tm.removeMessageHandler(this, 0, 255);
return true;
}
if (ar[0] == Packets.SSH_MSG_USERAUTH_FAILURE) {
PacketUserauthFailure puf = new PacketUserauthFailure(ar, 0,
ar.length);
remainingMethods = puf.getAuthThatCanContinue();
isPartialSuccess = puf.isPartialSuccess();
return false;
}
throw new IOException("Unexpected SSH message (type " + ar[0] + ")");
} catch (IOException e) {
tm.close(e, false);
throw (IOException) new IOException(
"Password authentication failed.").initCause(e);
}
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:40,代码来源:AuthenticationManager.java
示例11: getNextMessage
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
byte[] getNextMessage() throws IOException {
while (true) {
byte[] msg = deQueue();
if (msg[0] != Packets.SSH_MSG_USERAUTH_BANNER)
return msg;
PacketUserauthBanner sb = new PacketUserauthBanner(msg, 0,
msg.length);
banner = sb.getBanner();
}
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:14,代码来源:AuthenticationManager.java
示例12: initialize
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
private boolean initialize(String user) throws IOException {
if (initDone == false) {
tm.registerMessageHandler(this, 0, 255);
PacketServiceRequest sr = new PacketServiceRequest("ssh-userauth");
tm.sendMessage(sr.getPayload());
PacketUserauthRequestNone urn = new PacketUserauthRequestNone(
"ssh-connection", user);
tm.sendMessage(urn.getPayload());
byte[] msg = getNextMessage();
new PacketServiceAccept(msg, 0, msg.length);
msg = getNextMessage();
initDone = true;
if (msg[0] == Packets.SSH_MSG_USERAUTH_SUCCESS) {
authenticated = true;
tm.removeMessageHandler(this, 0, 255);
return true;
}
if (msg[0] == Packets.SSH_MSG_USERAUTH_FAILURE) {
PacketUserauthFailure puf = new PacketUserauthFailure(msg, 0,
msg.length);
remainingMethods = puf.getAuthThatCanContinue();
isPartialSuccess = puf.isPartialSuccess();
return false;
}
throw new IOException("Unexpected SSH message (type " + msg[0]
+ ")");
}
return authenticated;
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:38,代码来源:AuthenticationManager.java
示例13: sendData
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void sendData(Channel c, byte[] buffer, int pos, int len) throws IOException
{
while (len > 0)
{
int thislen = 0;
byte[] msg;
synchronized (c)
{
while (true)
{
if (c.state == Channel.STATE_CLOSED)
throw new IOException("SSH channel is closed. (" + c.getReasonClosed() + ")");
if (c.state != Channel.STATE_OPEN)
throw new IOException("SSH channel in strange state. (" + c.state + ")");
if (c.remoteWindow != 0)
break;
try
{
c.wait();
}
catch (InterruptedException ignore)
{
}
}
/* len > 0, no sign extension can happen when comparing */
thislen = (c.remoteWindow >= len) ? len : (int) c.remoteWindow;
int estimatedMaxDataLen = c.remoteMaxPacketSize - (tm.getPacketOverheadEstimate() + 9);
/* The worst case scenario =) a true bottleneck */
if (estimatedMaxDataLen <= 0)
{
estimatedMaxDataLen = 1;
}
if (thislen > estimatedMaxDataLen)
thislen = estimatedMaxDataLen;
c.remoteWindow -= thislen;
msg = new byte[1 + 8 + thislen];
msg[0] = Packets.SSH_MSG_CHANNEL_DATA;
msg[1] = (byte) (c.remoteID >> 24);
msg[2] = (byte) (c.remoteID >> 16);
msg[3] = (byte) (c.remoteID >> 8);
msg[4] = (byte) (c.remoteID);
msg[5] = (byte) (thislen >> 24);
msg[6] = (byte) (thislen >> 16);
msg[7] = (byte) (thislen >> 8);
msg[8] = (byte) (thislen);
System.arraycopy(buffer, pos, msg, 9, thislen);
}
synchronized (c.channelSendLock)
{
if (c.closeMessageSent == true)
throw new IOException("SSH channel is closed. (" + c.getReasonClosed() + ")");
tm.sendMessage(msg);
}
pos += thislen;
len -= thislen;
}
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:75,代码来源:ChannelManager.java
示例14: msgChannelExtendedData
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void msgChannelExtendedData(byte[] msg, int msglen) throws IOException
{
if (msglen <= 13)
throw new IOException("SSH_MSG_CHANNEL_EXTENDED_DATA message has wrong size (" + msglen + ")");
int id = ((msg[1] & 0xff) << 24) | ((msg[2] & 0xff) << 16) | ((msg[3] & 0xff) << 8) | (msg[4] & 0xff);
int dataType = ((msg[5] & 0xff) << 24) | ((msg[6] & 0xff) << 16) | ((msg[7] & 0xff) << 8) | (msg[8] & 0xff);
int len = ((msg[9] & 0xff) << 24) | ((msg[10] & 0xff) << 16) | ((msg[11] & 0xff) << 8) | (msg[12] & 0xff);
Channel c = getChannel(id);
if (c == null)
throw new IOException("Unexpected SSH_MSG_CHANNEL_EXTENDED_DATA message for non-existent channel " + id);
if (dataType != Packets.SSH_EXTENDED_DATA_STDERR)
throw new IOException("SSH_MSG_CHANNEL_EXTENDED_DATA message has unknown type (" + dataType + ")");
if (len != (msglen - 13))
throw new IOException("SSH_MSG_CHANNEL_EXTENDED_DATA message has wrong len (calculated " + (msglen - 13)
+ ", got " + len + ")");
if (log.isEnabled())
log.log(80, "Got SSH_MSG_CHANNEL_EXTENDED_DATA (channel " + id + ", " + len + ")");
synchronized (c)
{
if (c.state == Channel.STATE_CLOSED)
return; // ignore
if (c.state != Channel.STATE_OPEN)
throw new IOException("Got SSH_MSG_CHANNEL_EXTENDED_DATA, but channel is not in correct state ("
+ c.state + ")");
if (c.localWindow < len)
throw new IOException("Remote sent too much data, does not fit into window.");
c.localWindow -= len;
System.arraycopy(msg, 13, c.stderrBuffer, c.stderrWritepos, len);
c.stderrWritepos += len;
c.notifyAll();
}
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:45,代码来源:ChannelManager.java
示例15: receiveMessage
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public int receiveMessage(byte buffer[], int off, int len) throws IOException
{
if (recv_packet_header_present == false)
{
cis.read(recv_packet_header_buffer, 0, 5);
}
else
recv_packet_header_present = false;
int packet_length = ((recv_packet_header_buffer[0] & 0xff) << 24)
| ((recv_packet_header_buffer[1] & 0xff) << 16) | ((recv_packet_header_buffer[2] & 0xff) << 8)
| ((recv_packet_header_buffer[3] & 0xff));
int padding_length = recv_packet_header_buffer[4] & 0xff;
if (packet_length > 35000 || packet_length < 12)
throw new IOException("Illegal packet size! (" + packet_length + ")");
int payload_length = packet_length - padding_length - 1;
if (payload_length < 0)
throw new IOException("Illegal padding_length in packet from remote (" + padding_length + ")");
if (payload_length >= len)
throw new IOException("Receive buffer too small (" + len + ", need " + payload_length + ")");
cis.read(buffer, off, payload_length);
cis.read(recv_padding_buffer, 0, padding_length);
if (recv_mac != null)
{
cis.readPlain(recv_mac_buffer, 0, recv_mac_buffer.length);
recv_mac.initMac(recv_seq_number);
recv_mac.update(recv_packet_header_buffer, 0, 5);
recv_mac.update(buffer, off, payload_length);
recv_mac.update(recv_padding_buffer, 0, padding_length);
recv_mac.getMac(recv_mac_buffer_cmp, 0);
for (int i = 0; i < recv_mac_buffer.length; i++)
{
if (recv_mac_buffer[i] != recv_mac_buffer_cmp[i])
throw new IOException("Remote sent corrupt MAC.");
}
}
recv_seq_number++;
if (log.isEnabled())
{
log.log(90, "Received " + Packets.getMessageName(buffer[off] & 0xff) + " " + payload_length
+ " bytes payload");
}
if (recv_comp != null && can_recv_compress) {
int[] uncomp_len = new int[] { payload_length };
buffer = recv_comp.uncompress(buffer, off, uncomp_len);
if (buffer == null) {
throw new IOException("Error while inflating remote data");
} else {
return uncomp_len[0];
}
} else {
return payload_length;
}
}
开发者ID:dragonlinux,项目名称:connectbot,代码行数:68,代码来源:TransportConnection.java
示例16: sendMessage
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void sendMessage(byte[] message, int off, int len, int padd) throws IOException
{
if (padd < 4)
padd = 4;
else if (padd > 64)
padd = 64;
int packet_len = 5 + len + padd; /* Minimum allowed padding is 4 */
int slack = packet_len % send_padd_blocksize;
if (slack != 0)
{
packet_len += (send_padd_blocksize - slack);
}
if (packet_len < 16)
packet_len = 16;
int padd_len = packet_len - (5 + len);
if (useRandomPadding)
{
for (int i = 0; i < padd_len; i = i + 4)
{
/*
* don't waste calls to rnd.nextInt() (by using only 8bit of the
* output). just believe me: even though we may write here up to 3
* bytes which won't be used, there is no "buffer overflow" (i.e.,
* arrayindexoutofbounds). the padding buffer is big enough =) (256
* bytes, and that is bigger than any current cipher block size + 64).
*/
int r = rnd.nextInt();
send_padding_buffer[i] = (byte) r;
send_padding_buffer[i + 1] = (byte) (r >> 8);
send_padding_buffer[i + 2] = (byte) (r >> 16);
send_padding_buffer[i + 3] = (byte) (r >> 24);
}
}
else
{
/* use zero padding for unencrypted traffic */
for (int i = 0; i < padd_len; i++)
send_padding_buffer[i] = 0;
/* Actually this code is paranoid: we never filled any
* bytes into the padding buffer so far, therefore it should
* consist of zeros only.
*/
}
send_packet_header_buffer[0] = (byte) ((packet_len - 4) >> 24);
send_packet_header_buffer[1] = (byte) ((packet_len - 4) >> 16);
send_packet_header_buffer[2] = (byte) ((packet_len - 4) >> 8);
send_packet_header_buffer[3] = (byte) ((packet_len - 4));
send_packet_header_buffer[4] = (byte) padd_len;
cos.write(send_packet_header_buffer, 0, 5);
cos.write(message, off, len);
cos.write(send_padding_buffer, 0, padd_len);
if (send_mac != null)
{
send_mac.initMac(send_seq_number);
send_mac.update(send_packet_header_buffer, 0, 5);
send_mac.update(message, off, len);
send_mac.update(send_padding_buffer, 0, padd_len);
send_mac.getMac(send_mac_buffer, 0);
cos.writePlain(send_mac_buffer, 0, send_mac_buffer.length);
}
cos.flush();
if (log.isEnabled())
{
log.log(90, "Sent " + Packets.getMessageName(message[off] & 0xff) + " " + len + " bytes payload");
}
send_seq_number++;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:82,代码来源:TransportConnection.java
示例17: receiveMessage
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public int receiveMessage(byte buffer[], int off, int len) throws IOException
{
if (recv_packet_header_present == false)
{
cis.read(recv_packet_header_buffer, 0, 5);
}
else
recv_packet_header_present = false;
int packet_length = ((recv_packet_header_buffer[0] & 0xff) << 24)
| ((recv_packet_header_buffer[1] & 0xff) << 16) | ((recv_packet_header_buffer[2] & 0xff) << 8)
| ((recv_packet_header_buffer[3] & 0xff));
int padding_length = recv_packet_header_buffer[4] & 0xff;
if (packet_length > 35000 || packet_length < 12)
throw new IOException("Illegal packet size! (" + packet_length + ")");
int payload_length = packet_length - padding_length - 1;
if (payload_length < 0)
throw new IOException("Illegal padding_length in packet from remote (" + padding_length + ")");
if (payload_length >= len)
throw new IOException("Receive buffer too small (" + len + ", need " + payload_length + ")");
cis.read(buffer, off, payload_length);
cis.read(recv_padding_buffer, 0, padding_length);
if (recv_mac != null)
{
cis.readPlain(recv_mac_buffer, 0, recv_mac_buffer.length);
recv_mac.initMac(recv_seq_number);
recv_mac.update(recv_packet_header_buffer, 0, 5);
recv_mac.update(buffer, off, payload_length);
recv_mac.update(recv_padding_buffer, 0, padding_length);
recv_mac.getMac(recv_mac_buffer_cmp, 0);
for (int i = 0; i < recv_mac_buffer.length; i++)
{
if (recv_mac_buffer[i] != recv_mac_buffer_cmp[i])
throw new IOException("Remote sent corrupt MAC.");
}
}
recv_seq_number++;
if (log.isEnabled())
{
log.log(90, "Received " + Packets.getMessageName(buffer[off] & 0xff) + " " + payload_length
+ " bytes payload");
}
return payload_length;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:57,代码来源:TransportConnection.java
示例18: msgChannelExtendedData
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void msgChannelExtendedData(byte[] msg, int msglen)
throws IOException {
if (msglen <= 13)
throw new IOException(
"SSH_MSG_CHANNEL_EXTENDED_DATA message has wrong size ("
+ msglen + ")");
int id = ((msg[1] & 0xff) << 24) | ((msg[2] & 0xff) << 16)
| ((msg[3] & 0xff) << 8) | (msg[4] & 0xff);
int dataType = ((msg[5] & 0xff) << 24) | ((msg[6] & 0xff) << 16)
| ((msg[7] & 0xff) << 8) | (msg[8] & 0xff);
int len = ((msg[9] & 0xff) << 24) | ((msg[10] & 0xff) << 16)
| ((msg[11] & 0xff) << 8) | (msg[12] & 0xff);
Channel c = getChannel(id);
if (c == null)
throw new IOException(
"Unexpected SSH_MSG_CHANNEL_EXTENDED_DATA message for non-existent channel "
+ id);
if (dataType != Packets.SSH_EXTENDED_DATA_STDERR)
throw new IOException(
"SSH_MSG_CHANNEL_EXTENDED_DATA message has unknown type ("
+ dataType + ")");
if (len != (msglen - 13))
throw new IOException(
"SSH_MSG_CHANNEL_EXTENDED_DATA message has wrong len (calculated "
+ (msglen - 13) + ", got " + len + ")");
if (log.isEnabled())
log.log(80, "Got SSH_MSG_CHANNEL_EXTENDED_DATA (channel " + id
+ ", " + len + ")");
synchronized (c) {
if (c.state == Channel.STATE_CLOSED)
return; // ignore
if (c.state != Channel.STATE_OPEN)
throw new IOException(
"Got SSH_MSG_CHANNEL_EXTENDED_DATA, but channel is not in correct state ("
+ c.state + ")");
if (c.localWindow < len)
throw new IOException(
"Remote sent too much data, does not fit into window.");
c.localWindow -= len;
System.arraycopy(msg, 13, c.stderrBuffer, c.stderrWritepos, len);
c.stderrWritepos += len;
c.notifyAll();
}
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:57,代码来源:ChannelManager.java
示例19: sendData
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public void sendData(Channel c, byte[] buffer, int pos, int len)
throws IOException {
while (len > 0) {
int thislen = 0;
byte[] msg;
synchronized (c) {
while (true) {
if (c.state == Channel.STATE_CLOSED)
throw new IOException("SSH channel is closed. ("
+ c.getReasonClosed() + ")");
if (c.state != Channel.STATE_OPEN)
throw new IOException("SSH channel in strange state. ("
+ c.state + ")");
if (c.remoteWindow != 0)
break;
try {
c.wait();
} catch (InterruptedException ignore) {
}
}
/* len > 0, no sign extension can happen when comparing */
thislen = (c.remoteWindow >= len) ? len : (int) c.remoteWindow;
int estimatedMaxDataLen = c.remoteMaxPacketSize
- (tm.getPacketOverheadEstimate() + 9);
/* The worst case scenario =) a true bottleneck */
if (estimatedMaxDataLen <= 0) {
estimatedMaxDataLen = 1;
}
if (thislen > estimatedMaxDataLen)
thislen = estimatedMaxDataLen;
c.remoteWindow -= thislen;
msg = new byte[1 + 8 + thislen];
msg[0] = Packets.SSH_MSG_CHANNEL_DATA;
msg[1] = (byte) (c.remoteID >> 24);
msg[2] = (byte) (c.remoteID >> 16);
msg[3] = (byte) (c.remoteID >> 8);
msg[4] = (byte) (c.remoteID);
msg[5] = (byte) (thislen >> 24);
msg[6] = (byte) (thislen >> 16);
msg[7] = (byte) (thislen >> 8);
msg[8] = (byte) (thislen);
System.arraycopy(buffer, pos, msg, 9, thislen);
}
synchronized (c.channelSendLock) {
if (c.closeMessageSent == true)
throw new IOException("SSH channel is closed. ("
+ c.getReasonClosed() + ")");
tm.sendMessage(msg);
}
pos += thislen;
len -= thislen;
}
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:71,代码来源:ChannelManager.java
示例20: receiveMessage
import com.trilead.ssh2.packets.Packets; //导入依赖的package包/类
public int receiveMessage(byte buffer[], int off, int len)
throws IOException {
if (recv_packet_header_present == false) {
cis.read(recv_packet_header_buffer, 0, 5);
} else
recv_packet_header_present = false;
int packet_length = ((recv_packet_header_buffer[0] & 0xff) << 24)
| ((recv_packet_header_buffer[1] & 0xff) << 16)
| ((recv_packet_header_buffer[2] & 0xff) << 8)
| ((recv_packet_header_buffer[3] & 0xff));
int padding_length = recv_packet_header_buffer[4] & 0xff;
if (packet_length > 35000 || packet_length < 12)
throw new IOException("Illegal packet size! (" + packet_length
+ ")");
int payload_length = packet_length - padding_length - 1;
if (payload_length < 0)
throw new IOException(
"Illegal padding_length in packet from remote ("
+ padding_length + ")");
if (payload_length >= len)
throw new IOException("Receive buffer too small (" + len
+ ", need " + payload_length + ")");
cis.read(buffer, off, payload_length);
cis.read(recv_padding_buffer, 0, padding_length);
if (recv_mac != null) {
cis.readPlain(recv_mac_buffer, 0, recv_mac_buffer.length);
recv_mac.initMac(recv_seq_number);
recv_mac.update(recv_packet_header_buffer, 0, 5);
recv_mac.update(buffer, off, payload_length);
recv_mac.update(recv_padding_buffer, 0, padding_length);
recv_mac.getMac(recv_mac_buffer_cmp, 0);
for (int i = 0; i < recv_mac_buffer.length; i++) {
if (recv_mac_buffer[i] != recv_mac_buffer_cmp[i])
throw new IOException("Remote sent corrupt MAC.");
}
}
recv_seq_number++;
if (log.isEnabled()) {
log.log(90,
"Received " + Packets.getMessageName(buffer[off] & 0xff)
+ " " + payload_length + " bytes payload");
}
if (recv_comp != null && can_recv_compress) {
int[] uncomp_len = new int[] { payload_length };
buffer = recv_comp.uncompress(buffer, off, uncomp_len);
if (buffer == null) {
throw new IOException("Error while inflating remote data");
} else {
return uncomp_len[0];
}
} else {
return payload_length;
}
}
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:69,代码来源:TransportConnection.java
注:本文中的com.trilead.ssh2.packets.Packets类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论