public static byte[] encode(Map<PTYMode, Integer> modes) { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); for (Entry<PTYMode, Integer> entry : modes.entrySet()) { buf.putByte(entry.getKey().getOpcode()); buf.putUInt32(entry.getValue()); } buf.putByte((byte) 0); return buf.getCompactData(); }
public byte[] toBytes() { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); buf.putUInt32(mask); if (has(Flag.SIZE)) buf.putUInt64(size); if (has(Flag.UIDGID)) { buf.putUInt32(uid); buf.putUInt32(gid); } if (has(Flag.MODE)) buf.putUInt32(mode.getMask()); if (has(Flag.ACMODTIME)) { buf.putUInt32(atime); buf.putUInt32(mtime); } if (has(Flag.EXTENDED)) { buf.putUInt32(ext.size()); for (Entry<String, String> entry : ext.entrySet()) { buf.putString(entry.getKey()); buf.putString(entry.getValue()); } } return buf.getCompactData(); }
@Test public void testDataTypes() throws Buffer.BufferException { // bool assertEquals(handyBuf.putBoolean(true).readBoolean(), true); // byte assertEquals(handyBuf.putByte((byte) 10).readByte(), (byte) 10); // byte array assertArrayEquals(handyBuf.putBytes("some string".getBytes()).readBytes(), "some string".getBytes()); // mpint BigInteger bi = new BigInteger("1111111111111111111111111111111"); assertEquals(handyBuf.putMPInt(bi).readMPInt(), bi); // string assertEquals(handyBuf.putString("some string").readString(), "some string"); // uint32 assertEquals(handyBuf.putUInt32(0xffffffffL).readUInt32(), 0xffffffffL); }
public byte[] toBytes() { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); buf.putUInt32(mask); if (has(Flag.SIZE)) buf.putUInt64(size); if (has(Flag.UIDGID)) { buf.putUInt32(uid); buf.putUInt32(gid); } if (has(Flag.MODE)) buf.putUInt32(mode.getMask()); if (has(Flag.ACMODTIME)) { buf.putUInt32(atime); buf.putUInt32(mtime); } if (has(Flag.EXTENDED)) { buf.putUInt32(ext.size()); for (Entry<String, String> entry : ext.entrySet()) { buf.putString(entry.getKey()); buf.putString(entry.getValue()); } } return buf.getCompactData(); }
@Override public void allocatePTY(String term, int cols, int rows, int width, int height, Map<PTYMode, Integer> modes) throws ConnectionException, TransportException { sendChannelRequest( "pty-req", true, new Buffer.PlainBuffer() .putString(term) .putUInt32(cols) .putUInt32(rows) .putUInt32(width) .putUInt32(height) .putBytes(PTYMode.encode(modes)) ).await(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
@Override public void allocatePTY(String term, int cols, int rows, int width, int height, Map<PTYMode, Integer> modes) throws ConnectionException, TransportException { sendChannelRequest( "pty-req", true, new Buffer.PlainBuffer() .putString(term) .putUInt32(cols) .putUInt32(rows) .putUInt32(width) .putUInt32(height) .putBytes(PTYMode.encode(modes)) ).await(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
@Override public void reqX11Forwarding(String authProto, String authCookie, int screen) throws ConnectionException, TransportException { sendChannelRequest( "x11-req", true, new Buffer.PlainBuffer() .putBoolean(false) .putString(authProto) .putString(authCookie) .putUInt32(screen) ).await(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
@Override public void reqX11Forwarding(String authProto, String authCookie, int screen) throws ConnectionException, TransportException { sendChannelRequest( "x11-req", true, new Buffer.PlainBuffer() .putBoolean(false) .putString(authProto) .putString(authCookie) .putUInt32(screen) ).await(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
protected SSHPacket req(String reqName, Forward forward) throws ConnectionException, TransportException { final byte[] specifics = new Buffer.PlainBuffer().putString(forward.address).putUInt32(forward.port) .getCompactData(); return conn.sendGlobalRequest(reqName, true, specifics) .retrieve(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
protected SSHPacket req(String reqName, Forward forward) throws ConnectionException, TransportException { final byte[] specifics = new Buffer.PlainBuffer().putString(forward.address).putUInt32(forward.port) .getCompactData(); return conn.sendGlobalRequest(reqName, true, specifics) .retrieve(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
public static byte[] encode(Map<PTYMode, Integer> modes) { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); for (Entry<PTYMode, Integer> entry : modes.entrySet()) { buf.putByte(entry.getKey().getOpcode()); buf.putUInt32(entry.getValue()); } buf.putByte((byte) 0); return buf.getCompactData(); }
public static byte[] encode(Map<PTYMode, Integer> modes) { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); for (Entry<PTYMode, Integer> entry : modes.entrySet()) { buf.putByte(entry.getKey().getOpcode()); buf.putUInt32(entry.getValue()); } buf.putByte((byte) 0); return buf.getCompactData(); }
private boolean parseGexReply(SSHPacket buffer) throws Buffer.BufferException, GeneralSecurityException, TransportException { byte[] K_S = buffer.readBytes(); byte[] f = buffer.readBytes(); byte[] sig = buffer.readBytes(); hostKey = new Buffer.PlainBuffer(K_S).readPublicKey(); dh.computeK(f); BigInteger k = dh.getK(); final Buffer.PlainBuffer buf = initializedBuffer() .putString(K_S) .putUInt32(minBits) .putUInt32(preferredBits) .putUInt32(maxBits) .putMPInt(((DH) dh).getP()) .putMPInt(((DH) dh).getG()) .putBytes(dh.getE()) .putBytes(f) .putMPInt(k); digest.update(buf.array(), buf.rpos(), buf.available()); H = digest.digest(); Signature signature = Factory.Named.Util.create(trans.getConfig().getSignatureFactories(), KeyType.fromKey(hostKey).toString()); signature.initVerify(hostKey); signature.update(H, 0, H.length); if (!signature.verify(sig)) throw new TransportException(DisconnectReason.KEY_EXCHANGE_FAILED, "KeyExchange signature verification failed"); return true; }
@Override public void allocatePTY(String term, int cols, int rows, int width, int height, Map<PTYMode, Integer> modes) throws ConnectionException, TransportException { sendChannelRequest( "pty-req", true, new Buffer.PlainBuffer() .putString(term) .putUInt32(cols) .putUInt32(rows) .putUInt32(width) .putUInt32(height) .putBytes(PTYMode.encode(modes)) ).await(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
protected SSHPacket req(String reqName, Forward forward) throws ConnectionException, TransportException { final byte[] specifics = new Buffer.PlainBuffer().putString(forward.address).putUInt32(forward.port) .getCompactData(); return conn.sendGlobalRequest(reqName, true, specifics) .retrieve(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
@Override public void reqX11Forwarding(String authProto, String authCookie, int screen) throws ConnectionException, TransportException { sendChannelRequest( "x11-req", true, new Buffer.PlainBuffer() .putBoolean(false) .putString(authProto) .putString(authCookie) .putUInt32(screen) ).await(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
@Test public void shouldExpandCapacityOfUInt32(){ PlainBuffer buf = new PlainBuffer(); for(int i=0;i<Buffer.DEFAULT_SIZE+1;i+=4) { buf.putUInt32(1l); } /* Buffer should have been expanded at this point*/ assertEquals(Buffer.DEFAULT_SIZE*2,buf.data.length); }