public byte[] forSSHAgent() throws JSchException { if(isEncrypted()){ throw new JSchException("key is encrypted."); } Buffer buf = new Buffer(); buf.putString(sshdss); buf.putString(P_array); buf.putString(Q_array); buf.putString(G_array); buf.putString(pub_array); buf.putString(prv_array); buf.putString(Util.str2byte(publicKeyComment)); byte[] result = new byte[buf.getLength()]; buf.getByte(result, 0, result.length); return result; }
public Signature getVerifier() { try { Class<?> c = Class.forName(JSch.getConfig("signature.dss")); SignatureDSA dsa = (SignatureDSA) c.newInstance(); dsa.init(); if (pub_array == null && P_array == null && getPublicKeyBlob() != null) { Buffer buf = new Buffer(getPublicKeyBlob()); buf.getString(); P_array = buf.getString(); Q_array = buf.getString(); G_array = buf.getString(); pub_array = buf.getString(); } dsa.setPubKey(pub_array, P_array, Q_array, G_array); return dsa; } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); } return null; }
static SftpATTRS getATTR(Buffer buf){ SftpATTRS attr=new SftpATTRS(); attr.flags=buf.getInt(); if((attr.flags&SSH_FILEXFER_ATTR_SIZE)!=0){ attr.size=buf.getLong(); } if((attr.flags&SSH_FILEXFER_ATTR_UIDGID)!=0){ attr.uid=buf.getInt(); attr.gid=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0){ attr.permissions=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0){ attr.atime=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0){ attr.mtime=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_EXTENDED)!=0){ int count=buf.getInt(); if(count>0){ attr.extended=new String[count*2]; for(int i=0; i<count; i++){ attr.extended[i*2]=new String(buf.getString()); attr.extended[i*2+1]=new String(buf.getString()); } } } return attr; }
private void throwStatusError(Buffer buf, int i) throws SftpException{ if(server_version>=3 && // WindRiver's sftp will send invalid buf.getLength()>=4){ // SSH_FXP_STATUS packet. byte[] str=buf.getString(); //byte[] tag=buf.getString(); throw new SftpException(i, Util.byte2str(str, UTF8)); } else{ throw new SftpException(i, "Failure"); } }
public void request(Session session, Channel channel) throws Exception { super.request(session, channel); Buffer buf = new Buffer(); Packet packet = new Packet(buf); packet.reset(); buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); buf.putInt(channel.getRecipient()); buf.putString(Util.str2byte("shell")); buf.putByte((byte) (waitForReply() ? 1 : 0)); write(packet); } }
void getData(Buffer buf) { setRecipient(buf.getInt()); setRemoteWindowSize(buf.getUInt()); setRemotePacketSize(buf.getInt()); byte[] addr = buf.getString(); int port = buf.getInt(); buf.getString(); buf.getInt(); Session _session = null; try { _session = getSession(); } catch (JSchException e) { logger.log(Level.SEVERE, e.getMessage(), e); } this.config = getPort(_session, Util.byte2str(addr), port); if (this.config == null) { this.config = getPort(_session, null, port); } if (this.config == null) { logger.log(Level.SEVERE, "ChannelForwardedTCPIP: " + Util.byte2str(addr) + ":" + port + " is not registered"); } }
private synchronized void init() throws java.io.IOException { buffer = new Buffer(rmpsize); packet = new Packet(buffer); byte[] _buf = buffer.buffer; if (_buf.length - (14 + 0) - Session.buffer_margin <= 0) { buffer = null; packet = null; throw new IOException("failed to initialize the channel."); } }
static SftpStatVFS getStatVFS(Buffer buf) { SftpStatVFS statvfs = new SftpStatVFS(); statvfs.bsize = buf.getLong(); statvfs.frsize = buf.getLong(); statvfs.blocks = buf.getLong(); statvfs.bfree = buf.getLong(); statvfs.bavail = buf.getLong(); statvfs.files = buf.getLong(); statvfs.ffree = buf.getLong(); statvfs.favail = buf.getLong(); statvfs.fsid = buf.getLong(); int flag = (int) buf.getLong(); statvfs.namemax = buf.getLong(); statvfs.flag = (flag & 1/*SSH2_FXE_STATVFS_ST_RDONLY*/) != 0 ? 1/*ST_RDONLY*/ : 0; statvfs.flag |= (flag & 2/*SSH2_FXE_STATVFS_ST_NOSUID*/) != 0 ? 2/*ST_NOSUID*/ : 0; return statvfs; }
public void write(Packet packet) throws Exception{ // System.err.println("in_kex="+in_kex+" "+(packet.buffer.getCommand())); while(in_kex){ byte command=packet.buffer.getCommand(); //System.err.println("command: "+command); if(command==SSH_MSG_KEXINIT || command==SSH_MSG_NEWKEYS || command==SSH_MSG_KEXDH_INIT || command==SSH_MSG_KEXDH_REPLY || command==SSH_MSG_KEX_DH_GEX_GROUP || command==SSH_MSG_KEX_DH_GEX_INIT || command==SSH_MSG_KEX_DH_GEX_REPLY || command==SSH_MSG_KEX_DH_GEX_REQUEST || command==SSH_MSG_DISCONNECT){ break; } try{Thread.sleep(10);} catch(java.lang.InterruptedException e){}; } _write(packet); }