Renamed some Buffer methods to better reflect the SSH datatype

This commit is contained in:
Shikhar Bhushan
2011-05-22 09:43:19 +01:00
parent 3c3715eccf
commit 17d8e91f05
25 changed files with 91 additions and 91 deletions

View File

@@ -222,7 +222,7 @@ public class Buffer<T extends Buffer<T>> {
* @return the byte-array read * @return the byte-array read
*/ */
public byte[] readBytes() { public byte[] readBytes() {
int len = readInt(); int len = readUInt32AsInt();
if (len < 0 || len > 32768) if (len < 0 || len > 32768)
throw new BufferException("Bad item length: " + len); throw new BufferException("Bad item length: " + len);
byte[] b = new byte[len]; byte[] b = new byte[len];
@@ -251,7 +251,7 @@ public class Buffer<T extends Buffer<T>> {
* @return this * @return this
*/ */
public T putBytes(byte[] b, int off, int len) { public T putBytes(byte[] b, int off, int len) {
return putInt(len - off).putRawBytes(b, off, len); return putUInt32(len - off).putRawBytes(b, off, len);
} }
public void readRawBytes(byte[] buf) { public void readRawBytes(byte[] buf) {
@@ -294,11 +294,11 @@ public class Buffer<T extends Buffer<T>> {
return (T) this; return (T) this;
} }
public int readInt() { public int readUInt32AsInt() {
return (int) readLong(); return (int) readUInt32();
} }
public long readLong() { public long readUInt32() {
ensureAvailable(4); ensureAvailable(4);
return data[rpos++] << 24 & 0xff000000L | return data[rpos++] << 24 & 0xff000000L |
data[rpos++] << 16 & 0x00ff0000L | data[rpos++] << 16 & 0x00ff0000L |
@@ -314,7 +314,7 @@ public class Buffer<T extends Buffer<T>> {
* @return this * @return this
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T putInt(long uint32) { public T putUInt32(long uint32) {
ensureCapacity(4); ensureCapacity(4);
if (uint32 < 0 || uint32 > 0xffffffffL) if (uint32 < 0 || uint32 > 0xffffffffL)
throw new BufferException("Invalid value: " + uint32); throw new BufferException("Invalid value: " + uint32);
@@ -356,10 +356,10 @@ public class Buffer<T extends Buffer<T>> {
int i = foo.length; int i = foo.length;
if ((foo[0] & 0x80) != 0) { if ((foo[0] & 0x80) != 0) {
i++; i++;
putInt(i); putUInt32(i);
putByte((byte) 0); putByte((byte) 0);
} else } else
putInt(i); putUInt32(i);
return putRawBytes(foo); return putRawBytes(foo);
} }
@@ -367,15 +367,15 @@ public class Buffer<T extends Buffer<T>> {
return readBytes(); return readBytes();
} }
public long readUINT64() { public long readUInt64() {
long uint64 = (readLong() << 32) + (readLong() & 0xffffffffL); long uint64 = (readUInt32() << 32) + (readUInt32() & 0xffffffffL);
if (uint64 < 0) if (uint64 < 0)
throw new BufferException("Cannot handle values > Long.MAX_VALUE"); throw new BufferException("Cannot handle values > Long.MAX_VALUE");
return uint64; return uint64;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T putUINT64(long uint64) { public T putUInt64(long uint64) {
if (uint64 < 0) if (uint64 < 0)
throw new BufferException("Invalid value: " + uint64); throw new BufferException("Invalid value: " + uint64);
data[wpos++] = (byte) (uint64 >> 56); data[wpos++] = (byte) (uint64 >> 56);
@@ -395,7 +395,7 @@ public class Buffer<T extends Buffer<T>> {
* @return the string as a Java {@code String} * @return the string as a Java {@code String}
*/ */
public String readString() { public String readString() {
int len = readInt(); int len = readUInt32AsInt();
if (len < 0 || len > 32768) if (len < 0 || len > 32768)
throw new BufferException("Bad item length: " + len); throw new BufferException("Bad item length: " + len);
ensureAvailable(len); ensureAvailable(len);
@@ -444,7 +444,7 @@ public class Buffer<T extends Buffer<T>> {
public T putSensitiveString(char[] str) { public T putSensitiveString(char[] str) {
if (str == null) if (str == null)
return putString(""); return putString("");
putInt(str.length); putUInt32(str.length);
ensureCapacity(str.length); ensureCapacity(str.length);
for (char c : str) for (char c : str)
data[wpos++] = (byte) c; data[wpos++] = (byte) c;

View File

@@ -103,7 +103,7 @@ public class ConnectionImpl
private Channel getChannel(SSHPacket buffer) private Channel getChannel(SSHPacket buffer)
throws ConnectionException { throws ConnectionException {
int recipient = buffer.readInt(); int recipient = buffer.readUInt32AsInt();
Channel channel = get(recipient); Channel channel = get(recipient);
if (channel != null) if (channel != null)
return channel; return channel;
@@ -218,7 +218,7 @@ public class ConnectionImpl
openers.get(type).handleOpen(buf); openers.get(type).handleOpen(buf);
else { else {
log.warn("No opener found for `{}` CHANNEL_OPEN request -- rejecting", type); log.warn("No opener found for `{}` CHANNEL_OPEN request -- rejecting", type);
sendOpenFailure(buf.readInt(), OpenFailException.Reason.UNKNOWN_CHANNEL_TYPE, ""); sendOpenFailure(buf.readUInt32AsInt(), OpenFailException.Reason.UNKNOWN_CHANNEL_TYPE, "");
} }
} }
@@ -226,8 +226,8 @@ public class ConnectionImpl
public void sendOpenFailure(int recipient, Reason reason, String message) public void sendOpenFailure(int recipient, Reason reason, String message)
throws TransportException { throws TransportException {
trans.write(new SSHPacket(Message.CHANNEL_OPEN_FAILURE) trans.write(new SSHPacket(Message.CHANNEL_OPEN_FAILURE)
.putInt(recipient) .putUInt32(recipient)
.putInt(reason.getCode()) .putUInt32(reason.getCode())
.putString(message)); .putString(message));
} }

View File

@@ -183,11 +183,11 @@ public abstract class AbstractChannel
break; break;
case CHANNEL_EXTENDED_DATA: case CHANNEL_EXTENDED_DATA:
gotExtendedData(buf.readInt(), buf); gotExtendedData(buf.readUInt32AsInt(), buf);
break; break;
case CHANNEL_WINDOW_ADJUST: case CHANNEL_WINDOW_ADJUST:
gotWindowAdjustment(buf.readInt()); gotWindowAdjustment(buf.readUInt32AsInt());
break; break;
case CHANNEL_REQUEST: case CHANNEL_REQUEST:
@@ -333,12 +333,12 @@ public abstract class AbstractChannel
} }
protected SSHPacket newBuffer(Message cmd) { protected SSHPacket newBuffer(Message cmd) {
return new SSHPacket(cmd).putInt(recipient); return new SSHPacket(cmd).putUInt32(recipient);
} }
protected void receiveInto(ChannelInputStream stream, SSHPacket buf) protected void receiveInto(ChannelInputStream stream, SSHPacket buf)
throws ConnectionException, TransportException { throws ConnectionException, TransportException {
final int len = buf.readInt(); final int len = buf.readUInt32AsInt();
if (len < 0 || len > getLocalMaxPacketSize() || len > buf.available()) if (len < 0 || len > getLocalMaxPacketSize() || len > buf.available())
throw new ConnectionException(DisconnectReason.PROTOCOL_ERROR, "Bad item length: " + len); throw new ConnectionException(DisconnectReason.PROTOCOL_ERROR, "Bad item length: " + len);
if (log.isTraceEnabled()) if (log.isTraceEnabled())

View File

@@ -163,7 +163,7 @@ public final class ChannelInputStream
if (adjustment > 0) { if (adjustment > 0) {
log.info("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment); log.info("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment);
trans.write(new SSHPacket(Message.CHANNEL_WINDOW_ADJUST) trans.write(new SSHPacket(Message.CHANNEL_WINDOW_ADJUST)
.putInt(chan.getRecipient()).putInt(adjustment)); .putUInt32(chan.getRecipient()).putUInt32(adjustment));
win.expand(adjustment); win.expand(adjustment);
} }
} }

View File

@@ -74,8 +74,8 @@ public final class ChannelOutputStream
buffer.rpos(5); buffer.rpos(5);
buffer.wpos(5); buffer.wpos(5);
buffer.putMessageID(Message.CHANNEL_DATA); buffer.putMessageID(Message.CHANNEL_DATA);
buffer.putInt(0); // meant to be recipient buffer.putUInt32(0); // meant to be recipient
buffer.putInt(0); // meant to be data length buffer.putUInt32(0); // meant to be data length
} }
@Override @Override
@@ -153,8 +153,8 @@ public final class ChannelOutputStream
private void putRecipientAndLength() { private void putRecipientAndLength() {
final int origPos = buffer.wpos(); final int origPos = buffer.wpos();
buffer.wpos(6); buffer.wpos(6);
buffer.putInt(chan.getRecipient()); buffer.putUInt32(chan.getRecipient());
buffer.putInt(bufferLength); buffer.putUInt32(bufferLength);
buffer.wpos(origPos); buffer.wpos(origPos);
} }

View File

@@ -68,21 +68,21 @@ public abstract class AbstractDirectChannel
} }
private void gotOpenConfirmation(SSHPacket buf) { private void gotOpenConfirmation(SSHPacket buf) {
init(buf.readInt(), buf.readInt(), buf.readInt()); init(buf.readUInt32AsInt(), buf.readUInt32AsInt(), buf.readUInt32AsInt());
open.set(); open.set();
} }
private void gotOpenFailure(SSHPacket buf) { private void gotOpenFailure(SSHPacket buf) {
open.deliverError(new OpenFailException(getType(), buf.readInt(), buf.readString())); open.deliverError(new OpenFailException(getType(), buf.readUInt32AsInt(), buf.readString()));
finishOff(); finishOff();
} }
protected SSHPacket buildOpenReq() { protected SSHPacket buildOpenReq() {
return new SSHPacket(Message.CHANNEL_OPEN) return new SSHPacket(Message.CHANNEL_OPEN)
.putString(getType()) .putString(getType())
.putInt(getID()) .putUInt32(getID())
.putInt(getLocalWinSize()) .putUInt32(getLocalWinSize())
.putInt(getLocalMaxPacketSize()); .putUInt32(getLocalMaxPacketSize());
} }
@Override @Override

View File

@@ -59,9 +59,9 @@ public class LocalPortForwarder {
protected SSHPacket buildOpenReq() { protected SSHPacket buildOpenReq() {
return super.buildOpenReq() return super.buildOpenReq()
.putString(host) .putString(host)
.putInt(port) .putUInt32(port)
.putString(ss.getInetAddress().getHostAddress()) .putString(ss.getInetAddress().getHostAddress())
.putInt(ss.getLocalPort()); .putUInt32(ss.getLocalPort());
} }
} }

View File

@@ -140,7 +140,7 @@ public enum PTYMode {
Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); Buffer.PlainBuffer buf = new Buffer.PlainBuffer();
for (Entry<PTYMode, Integer> entry : modes.entrySet()) { for (Entry<PTYMode, Integer> entry : modes.entrySet()) {
buf.putByte(entry.getKey().getOpcode()); buf.putByte(entry.getKey().getOpcode());
buf.putInt(entry.getValue()); buf.putUInt32(entry.getValue());
} }
buf.putByte((byte) 0); buf.putByte((byte) 0);
return buf.getCompactData(); return buf.getCompactData();

View File

@@ -86,10 +86,10 @@ public class SessionChannel
true, true,
new Buffer.PlainBuffer() new Buffer.PlainBuffer()
.putString(term) .putString(term)
.putInt(cols) .putUInt32(cols)
.putInt(rows) .putUInt32(rows)
.putInt(width) .putUInt32(width)
.putInt(height) .putUInt32(height)
.putBytes(PTYMode.encode(modes)) .putBytes(PTYMode.encode(modes))
).await(conn.getTimeout(), TimeUnit.SECONDS); ).await(conn.getTimeout(), TimeUnit.SECONDS);
} }
@@ -106,10 +106,10 @@ public class SessionChannel
"pty-req", "pty-req",
false, false,
new Buffer.PlainBuffer() new Buffer.PlainBuffer()
.putInt(cols) .putUInt32(cols)
.putInt(rows) .putUInt32(rows)
.putInt(width) .putUInt32(width)
.putInt(height) .putUInt32(height)
); );
} }
@@ -150,7 +150,7 @@ public class SessionChannel
if ("xon-xoff".equals(req)) if ("xon-xoff".equals(req))
canDoFlowControl = buf.readBoolean(); canDoFlowControl = buf.readBoolean();
else if ("exit-status".equals(req)) else if ("exit-status".equals(req))
exitStatus = buf.readInt(); exitStatus = buf.readUInt32AsInt();
else if ("exit-signal".equals(req)) { else if ("exit-signal".equals(req)) {
exitSignal = Signal.fromString(buf.readString()); exitSignal = Signal.fromString(buf.readString());
wasCoreDumped = buf.readBoolean(); // core dumped wasCoreDumped = buf.readBoolean(); // core dumped
@@ -170,7 +170,7 @@ public class SessionChannel
.putBoolean(false) .putBoolean(false)
.putString(authProto) .putString(authProto)
.putString(authCookie) .putString(authCookie)
.putInt(screen) .putUInt32(screen)
).await(conn.getTimeout(), TimeUnit.SECONDS); ).await(conn.getTimeout(), TimeUnit.SECONDS);
} }

View File

@@ -69,9 +69,9 @@ public abstract class AbstractForwardedChannel
// Must ensure channel is attached before confirming, data could start coming in immediately! // Must ensure channel is attached before confirming, data could start coming in immediately!
conn.attach(this); conn.attach(this);
trans.write(newBuffer(Message.CHANNEL_OPEN_CONFIRMATION) trans.write(newBuffer(Message.CHANNEL_OPEN_CONFIRMATION)
.putInt(getID()) .putUInt32(getID())
.putInt(getLocalWinSize()) .putUInt32(getLocalWinSize())
.putInt(getLocalMaxPacketSize())); .putUInt32(getLocalMaxPacketSize()));
open.set(); open.set();
} }

View File

@@ -168,7 +168,7 @@ public class RemotePortForwarder
throws ConnectionException, TransportException { throws ConnectionException, TransportException {
SSHPacket reply = req(PF_REQ, forward); SSHPacket reply = req(PF_REQ, forward);
if (forward.port == 0) if (forward.port == 0)
forward.port = reply.readInt(); forward.port = reply.readUInt32AsInt();
log.info("Remote end listening on {}", forward); log.info("Remote end listening on {}", forward);
listeners.put(forward, listener); listeners.put(forward, listener);
return forward; return forward;
@@ -193,7 +193,7 @@ public class RemotePortForwarder
protected SSHPacket req(String reqName, Forward forward) protected SSHPacket req(String reqName, Forward forward)
throws ConnectionException, TransportException { throws ConnectionException, TransportException {
final byte[] specifics = new Buffer.PlainBuffer().putString(forward.address).putInt(forward.port) final byte[] specifics = new Buffer.PlainBuffer().putString(forward.address).putUInt32(forward.port)
.getCompactData(); .getCompactData();
return conn.sendGlobalRequest(reqName, true, specifics) return conn.sendGlobalRequest(reqName, true, specifics)
.retrieve(conn.getTimeout(), TimeUnit.SECONDS); .retrieve(conn.getTimeout(), TimeUnit.SECONDS);
@@ -211,9 +211,9 @@ public class RemotePortForwarder
@Override @Override
public void handleOpen(SSHPacket buf) public void handleOpen(SSHPacket buf)
throws ConnectionException, TransportException { throws ConnectionException, TransportException {
final ForwardedTCPIPChannel chan = new ForwardedTCPIPChannel(conn, buf.readInt(), buf.readInt(), buf.readInt(), final ForwardedTCPIPChannel chan = new ForwardedTCPIPChannel(conn, buf.readUInt32AsInt(), buf.readUInt32AsInt(), buf.readUInt32AsInt(),
new Forward(buf.readString(), buf.readInt()), new Forward(buf.readString(), buf.readUInt32AsInt()),
buf.readString(), buf.readInt()); buf.readString(), buf.readUInt32AsInt());
if (listeners.containsKey(chan.getParentForward())) if (listeners.containsKey(chan.getParentForward()))
callListener(listeners.get(chan.getParentForward()), chan); callListener(listeners.get(chan.getParentForward()), chan);
else else

View File

@@ -56,9 +56,9 @@ public class X11Forwarder
public void handleOpen(SSHPacket buf) public void handleOpen(SSHPacket buf)
throws ConnectionException, TransportException { throws ConnectionException, TransportException {
callListener(listener, new X11Channel(conn, callListener(listener, new X11Channel(conn,
buf.readInt(), buf.readUInt32AsInt(),
buf.readInt(), buf.readInt(), buf.readUInt32AsInt(), buf.readUInt32AsInt(),
buf.readString(), buf.readInt())); buf.readString(), buf.readUInt32AsInt()));
} }
/** Stop handling {@code x11} channel open requests. De-registers itself with connection layer. */ /** Stop handling {@code x11} channel open requests. De-registers itself with connection layer. */

View File

@@ -119,26 +119,26 @@ public final class FileAttributes {
public byte[] toBytes() { public byte[] toBytes() {
Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); Buffer.PlainBuffer buf = new Buffer.PlainBuffer();
buf.putInt(mask); buf.putUInt32(mask);
if (has(Flag.SIZE)) if (has(Flag.SIZE))
buf.putUINT64(size); buf.putUInt64(size);
if (has(Flag.UIDGID)) { if (has(Flag.UIDGID)) {
buf.putInt(uid); buf.putUInt32(uid);
buf.putInt(gid); buf.putUInt32(gid);
} }
if (has(Flag.MODE)) if (has(Flag.MODE))
buf.putInt(mode.getMask()); buf.putUInt32(mode.getMask());
if (has(Flag.ACMODTIME)) { if (has(Flag.ACMODTIME)) {
buf.putInt(atime); buf.putUInt32(atime);
buf.putInt(mtime); buf.putUInt32(mtime);
} }
if (has(Flag.EXTENDED)) { if (has(Flag.EXTENDED)) {
buf.putInt(ext.size()); buf.putUInt32(ext.size());
for (Entry<String, String> entry : ext.entrySet()) { for (Entry<String, String> entry : ext.entrySet()) {
buf.putString(entry.getKey()); buf.putString(entry.getKey());
buf.putString(entry.getValue()); buf.putString(entry.getValue());

View File

@@ -37,7 +37,7 @@ public class RemoteDirectory
switch (res.getType()) { switch (res.getType()) {
case NAME: case NAME:
final int count = res.readInt(); final int count = res.readUInt32AsInt();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final String name = res.readString(); final String name = res.readString();
res.readString(); // long name - IGNORED - shdve never been in the protocol res.readString(); // long name - IGNORED - shdve never been in the protocol

View File

@@ -55,10 +55,10 @@ public class RemoteFile
public int read(long fileOffset, byte[] to, int offset, int len) public int read(long fileOffset, byte[] to, int offset, int len)
throws IOException { throws IOException {
Response res = requester.doRequest(newRequest(PacketType.READ).putUINT64(fileOffset).putInt(len)); Response res = requester.doRequest(newRequest(PacketType.READ).putUInt64(fileOffset).putUInt32(len));
switch (res.getType()) { switch (res.getType()) {
case DATA: case DATA:
int recvLen = res.readInt(); int recvLen = res.readUInt32AsInt();
System.arraycopy(res.array(), res.rpos(), to, offset, recvLen); System.arraycopy(res.array(), res.rpos(), to, offset, recvLen);
return recvLen; return recvLen;
@@ -74,8 +74,8 @@ public class RemoteFile
public void write(long fileOffset, byte[] data, int off, int len) public void write(long fileOffset, byte[] data, int off, int len)
throws IOException { throws IOException {
requester.doRequest(newRequest(PacketType.WRITE) requester.doRequest(newRequest(PacketType.WRITE)
.putUINT64(fileOffset) .putUInt64(fileOffset)
.putInt(len - off) .putUInt32(len - off)
.putRawBytes(data, off, len) .putRawBytes(data, off, len)
).ensureStatusPacketIsOK(); ).ensureStatusPacketIsOK();
} }

View File

@@ -29,7 +29,7 @@ public class Request
this.type = type; this.type = type;
this.reqID = reqID; this.reqID = reqID;
responsePromise = new Promise<Response, SFTPException>("sftp / " + reqID, SFTPException.chainer); responsePromise = new Promise<Response, SFTPException>("sftp / " + reqID, SFTPException.chainer);
putInt(reqID); putUInt32(reqID);
} }
public long getRequestID() { public long getRequestID() {

View File

@@ -55,7 +55,7 @@ public class Response
super(pk); super(pk);
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
this.type = readType(); this.type = readType();
this.reqID = readLong(); this.reqID = readUInt32();
} }
public int getProtocolVersion() { public int getProtocolVersion() {
@@ -71,7 +71,7 @@ public class Response
} }
public StatusCode readStatusCode() { public StatusCode readStatusCode() {
return StatusCode.fromInt(readInt()); return StatusCode.fromInt(readUInt32AsInt());
} }
public Response ensurePacketTypeIs(PacketType pt) public Response ensurePacketTypeIs(PacketType pt)

View File

@@ -65,7 +65,7 @@ public class SFTPEngine
public SFTPEngine init() public SFTPEngine init()
throws IOException { throws IOException {
transmit(new SFTPPacket<Request>(PacketType.INIT).putInt(MAX_SUPPORTED_VERSION)); transmit(new SFTPPacket<Request>(PacketType.INIT).putUInt32(MAX_SUPPORTED_VERSION));
final SFTPPacket<Response> response = reader.readPacket(); final SFTPPacket<Response> response = reader.readPacket();
@@ -73,7 +73,7 @@ public class SFTPEngine
if (type != PacketType.VERSION) if (type != PacketType.VERSION)
throw new SFTPException("Expected INIT packet, received: " + type); throw new SFTPException("Expected INIT packet, received: " + type);
operativeVersion = response.readInt(); operativeVersion = response.readUInt32AsInt();
log.info("Server version {}", operativeVersion); log.info("Server version {}", operativeVersion);
if (MAX_SUPPORTED_VERSION < operativeVersion) if (MAX_SUPPORTED_VERSION < operativeVersion)
throw new SFTPException("Server reported incompatible protocol version: " + operativeVersion); throw new SFTPException("Server reported incompatible protocol version: " + operativeVersion);
@@ -120,7 +120,7 @@ public class SFTPEngine
public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa) public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa)
throws IOException { throws IOException {
final String handle = doRequest( final String handle = doRequest(
newRequest(PacketType.OPEN).putString(path).putInt(OpenMode.toMask(modes)).putFileAttributes(fa) newRequest(PacketType.OPEN).putString(path).putUInt32(OpenMode.toMask(modes)).putFileAttributes(fa)
).ensurePacketTypeIs(PacketType.HANDLE).readString(); ).ensurePacketTypeIs(PacketType.HANDLE).readString();
return new RemoteFile(this, path, handle); return new RemoteFile(this, path, handle);
} }
@@ -244,7 +244,7 @@ public class SFTPEngine
protected static String readSingleName(Response res) protected static String readSingleName(Response res)
throws IOException { throws IOException {
res.ensurePacketTypeIs(PacketType.NAME); res.ensurePacketTypeIs(PacketType.NAME);
if (res.readInt() == 1) if (res.readUInt32AsInt() == 1)
return res.readString(); return res.readString();
else else
throw new SFTPException("Unexpected data in " + res.getType() + " packet"); throw new SFTPException("Unexpected data in " + res.getType() + " packet");

View File

@@ -35,17 +35,17 @@ public class SFTPPacket<T extends SFTPPacket<T>>
public FileAttributes readFileAttributes() { public FileAttributes readFileAttributes() {
final FileAttributes.Builder builder = new FileAttributes.Builder(); final FileAttributes.Builder builder = new FileAttributes.Builder();
final int mask = readInt(); final int mask = readUInt32AsInt();
if (FileAttributes.Flag.SIZE.isSet(mask)) if (FileAttributes.Flag.SIZE.isSet(mask))
builder.withSize(readUINT64()); builder.withSize(readUInt64());
if (FileAttributes.Flag.UIDGID.isSet(mask)) if (FileAttributes.Flag.UIDGID.isSet(mask))
builder.withUIDGID(readInt(), readInt()); builder.withUIDGID(readUInt32AsInt(), readUInt32AsInt());
if (FileAttributes.Flag.MODE.isSet(mask)) if (FileAttributes.Flag.MODE.isSet(mask))
builder.withPermissions(readInt()); builder.withPermissions(readUInt32AsInt());
if (FileAttributes.Flag.ACMODTIME.isSet(mask)) if (FileAttributes.Flag.ACMODTIME.isSet(mask))
builder.withAtimeMtime(readInt(), readInt()); builder.withAtimeMtime(readUInt32AsInt(), readUInt32AsInt());
if (FileAttributes.Flag.EXTENDED.isSet(mask)) { if (FileAttributes.Flag.EXTENDED.isSet(mask)) {
final int extCount = readInt(); final int extCount = readUInt32AsInt();
for (int i = 0; i < extCount; i++) for (int i = 0; i < extCount; i++)
builder.withExtended(readString(), readString()); builder.withExtended(readString(), readString());
} }

View File

@@ -157,7 +157,7 @@ final class Decoder
throws TransportException { throws TransportException {
cipher.update(inputBuffer.array(), 0, cipherSize); cipher.update(inputBuffer.array(), 0, cipherSize);
final int len = inputBuffer.readInt(); // Read packet length final int len = inputBuffer.readUInt32AsInt(); // Read packet length
if (isInvalidPacketLength(len)) { // Check packet length validity if (isInvalidPacketLength(len)) { // Check packet length validity
log.info("Error decoding packet (invalid length) {}", inputBuffer.printHex()); log.info("Error decoding packet (invalid length) {}", inputBuffer.printHex());

View File

@@ -116,7 +116,7 @@ final class Encoder
// Put packet header // Put packet header
buffer.wpos(startOfPacket); buffer.wpos(startOfPacket);
buffer.putInt(packetLen); buffer.putUInt32(packetLen);
buffer.putByte((byte) padLen); buffer.putByte((byte) padLen);
// Now wpos will mark end of padding // Now wpos will mark end of padding

View File

@@ -82,7 +82,7 @@ class Proposal {
packet.putString(""); packet.putString("");
packet.putBoolean(false); // Optimistic next packet does not follow packet.putBoolean(false); // Optimistic next packet does not follow
packet.putInt(0); // "Reserved" for future by spec packet.putUInt32(0); // "Reserved" for future by spec
} }
public Proposal(SSHPacket packet) { public Proposal(SSHPacket packet) {

View File

@@ -345,7 +345,7 @@ public final class TransportImpl
throws TransportException { throws TransportException {
final long seq = decoder.getSequenceNumber(); final long seq = decoder.getSequenceNumber();
log.info("Sending SSH_MSG_UNIMPLEMENTED for packet #{}", seq); log.info("Sending SSH_MSG_UNIMPLEMENTED for packet #{}", seq);
return write(new SSHPacket(Message.UNIMPLEMENTED).putInt(seq)); return write(new SSHPacket(Message.UNIMPLEMENTED).putUInt32(seq));
} }
@Override @Override
@@ -438,7 +438,7 @@ public final class TransportImpl
log.debug("Sending SSH_MSG_DISCONNECT: reason=[{}], msg=[{}]", reason, message); log.debug("Sending SSH_MSG_DISCONNECT: reason=[{}], msg=[{}]", reason, message);
try { try {
write(new SSHPacket(Message.DISCONNECT) write(new SSHPacket(Message.DISCONNECT)
.putInt(reason.toInt()) .putUInt32(reason.toInt())
.putString(message) .putString(message)
.putString("")); .putString(""));
} catch (IOException worthless) { } catch (IOException worthless) {
@@ -509,7 +509,7 @@ public final class TransportImpl
private void gotDisconnect(SSHPacket buf) private void gotDisconnect(SSHPacket buf)
throws TransportException { throws TransportException {
DisconnectReason code = DisconnectReason.fromInt(buf.readInt()); DisconnectReason code = DisconnectReason.fromInt(buf.readUInt32AsInt());
String message = buf.readString(); String message = buf.readString();
log.info("Received SSH_MSG_DISCONNECT (reason={}, msg={})", code, message); log.info("Received SSH_MSG_DISCONNECT (reason={}, msg={})", code, message);
throw new TransportException(code, "Disconnected; server said: " + message); throw new TransportException(code, "Disconnected; server said: " + message);
@@ -537,7 +537,7 @@ public final class TransportImpl
*/ */
private void gotUnimplemented(SSHPacket buf) private void gotUnimplemented(SSHPacket buf)
throws SSHException { throws SSHException {
long seqNum = buf.readLong(); long seqNum = buf.readUInt32();
log.info("Received SSH_MSG_UNIMPLEMENTED #{}", seqNum); log.info("Received SSH_MSG_UNIMPLEMENTED #{}", seqNum);
if (kexer.isKexOngoing()) if (kexer.isKexOngoing())
throw new TransportException("Received SSH_MSG_UNIMPLEMENTED while exchanging keys"); throw new TransportException("Received SSH_MSG_UNIMPLEMENTED while exchanging keys");

View File

@@ -65,7 +65,7 @@ public class AuthKeyboardInteractive
} else { } else {
provider.init(makeAccountResource(), buf.readString(), buf.readString()); provider.init(makeAccountResource(), buf.readString(), buf.readString());
buf.readString(); // lang-tag buf.readString(); // lang-tag
final int numPrompts = buf.readInt(); final int numPrompts = buf.readUInt32AsInt();
final CharArrWrap[] userReplies = new CharArrWrap[numPrompts]; final CharArrWrap[] userReplies = new CharArrWrap[numPrompts];
for (int i = 0; i < numPrompts; i++) { for (int i = 0; i < numPrompts; i++) {
final String prompt = buf.readString(); final String prompt = buf.readString();
@@ -79,7 +79,7 @@ public class AuthKeyboardInteractive
private void respond(CharArrWrap[] userReplies) private void respond(CharArrWrap[] userReplies)
throws TransportException { throws TransportException {
final SSHPacket pkt = new SSHPacket(Message.USERAUTH_INFO_RESPONSE).putInt(userReplies.length); final SSHPacket pkt = new SSHPacket(Message.USERAUTH_INFO_RESPONSE).putUInt32(userReplies.length);
for (final CharArrWrap response : userReplies) for (final CharArrWrap response : userReplies)
pkt.putSensitiveString(response.arr); pkt.putSensitiveString(response.arr);
params.getTransport().write(pkt); params.getTransport().write(pkt);

View File

@@ -59,7 +59,7 @@ public class BufferTest {
assertEquals(handyBuf.putString("some string").readString(), "some string"); assertEquals(handyBuf.putString("some string").readString(), "some string");
// uint32 // uint32
assertEquals(handyBuf.putInt(0xffffffffL).readLong(), 0xffffffffL); assertEquals(handyBuf.putUInt32(0xffffffffL).readUInt32(), 0xffffffffL);
} }
@Test @Test