public Buffer read(Buffer buf)
{
int j = 0;
while (true)
{
buf.Reset();
io.getByte(buf.buffer, buf.index, cipher_size); buf.index+=cipher_size;
if (s2ccipher!=null)
{
s2ccipher.update(buf.buffer, 0, cipher_size, buf.buffer, 0);
}
// j=((buf.buffer[0]<<24)&0xff000000)|
// ((buf.buffer[1]<<16)&0x00ff0000)|
// ((buf.buffer[2]<< 8)&0x0000ff00)|
// ((buf.buffer[3] )&0x000000ff);
j = Util.ToInt32(buf.buffer, 0);
j = j - 4 - cipher_size + 8;
if (j < 0 || (buf.index + j) > buf.buffer.Length)
{
throw new IOException("invalid data");
}
if (j > 0)
{
io.getByte(buf.buffer, buf.index, j); buf.index+=(j);
if(s2ccipher!=null)
{
s2ccipher.update(buf.buffer, cipher_size, j, buf.buffer, cipher_size);
}
}
if (s2cmac != null)
{
s2cmac.update(seqi);
s2cmac.update(buf.buffer, 0, buf.index);
byte[] result = s2cmac.doFinal();
io.getByte(mac_buf, 0, mac_buf.Length);
if (!result.SequenceEqual(mac_buf))
{
throw new IOException("MAC Error");
}
}
seqi++;
if (inflater != null)
{
//inflater.uncompress(buf);
int pad=buf.buffer[4];
uncompress_len[0]=buf.index-5-pad;
byte[] foo=inflater.uncompress(buf.buffer, 5, uncompress_len);
if(foo!=null)
{
buf.buffer=foo;
buf.index=5+uncompress_len[0];
}
else
{
System.Console.Error.WriteLine("fail in inflater");
break;
}
}
int type=buf.buffer[5]&0xff;
//System.Console.WriteLine("read: "+type);
if(type==SSH_MSG_DISCONNECT)
{
buf.Rewind();
buf.ReadInt();buf.ReadShort();
int reason_code=buf.ReadInt();
byte[] description=buf.ReadString();
byte[] language_tag=buf.ReadString();
/*
System.Console.Error.WriteLine("SSH_MSG_DISCONNECT:"+
" "+reason_code+
" "+Encoding.UTF8.GetString(description)+
" "+Encoding.UTF8.GetString(language_tag));
*/
throw new JSchException(
"SSH_MSG_DISCONNECT:"+
" "+reason_code+
" "+description+
" "+language_tag);
//break;
}
else if(type==SSH_MSG_IGNORE)
{
}
else if(type==SSH_MSG_DEBUG)
{
buf.Rewind();
buf.ReadInt();buf.ReadShort();
/*
byte always_display=(byte)buf.getByte();
byte[] message=buf.getString();
byte[] language_tag=buf.getString();
System.Console.Error.WriteLine("SSH_MSG_DEBUG:"+
" "+Encoding.UTF8.GetString(message)+
" "+Encoding.UTF8.GetString(language_tag));
*/
}
else if(type==SSH_MSG_CHANNEL_WINDOW_ADJUST)
{
buf.Rewind();
buf.ReadInt();buf.ReadShort();
Channel c=Channel.getChannel(buf.ReadInt(), this);
if(c==null)
{
}
else
{
c.addRemoteWindowSize(buf.ReadInt());
}
}
else
{
break;
}
}
buf.Rewind();
return buf;
}