Package org.apache.sshd.common.util

Examples of org.apache.sshd.common.util.Buffer$BufferException


    protected void doOpen() throws IOException {
        invertedIn = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA);
    }

    protected void doWriteData(byte[] data, int off, int len) throws IOException {
        Buffer message = null;
        synchronized (receiveBuffer) {
            receiveBuffer.putBuffer(new Buffer(data, off, len));
            if (receiveBuffer.available() >= 4) {
                off = receiveBuffer.rpos();
                len = receiveBuffer.getInt();
                receiveBuffer.rpos(off);
                if (receiveBuffer.available() >= 4 + len) {
                    message = new Buffer(receiveBuffer.getBytes());
                    receiveBuffer.compact();
                }
            }
        }
        if (message != null) {
View Full Code Here


    }

    protected void sendNextKey(PublicKey key) throws IOException {
        try {
            log.info("Send SSH_MSG_USERAUTH_REQUEST for publickey");
            Buffer buffer = session.createBuffer(SshConstants.Message.SSH_MSG_USERAUTH_REQUEST, 0);
            int pos1 = buffer.wpos() - 1;
            buffer.putString(username);
            buffer.putString(service);
            buffer.putString("publickey");
            buffer.putByte((byte) 1);
            buffer.putString((key instanceof RSAPublicKey) ? KeyPairProvider.SSH_RSA : KeyPairProvider.SSH_DSS);
            int pos2 = buffer.wpos();
            buffer.putPublicKey(key);


            Buffer bs = new Buffer();
            bs.putString(session.getKex().getH());
            bs.putCommand(SshConstants.Message.SSH_MSG_USERAUTH_REQUEST);
            bs.putString(username);
            bs.putString(service);
            bs.putString("publickey");
            bs.putByte((byte) 1);
            bs.putString((key instanceof RSAPublicKey) ? KeyPairProvider.SSH_RSA : KeyPairProvider.SSH_DSS);
            bs.putPublicKey(key);

            Buffer bs2 = new Buffer();
            bs2.putString((key instanceof RSAPublicKey) ? KeyPairProvider.SSH_RSA : KeyPairProvider.SSH_DSS);
            bs2.putBytes(agent.sign(key, bs.getCompactData()));
            buffer.putBytes(bs2.array(), bs2.rpos(), bs2.available());

            session.writePacket(buffer);
        } catch (IOException e) {
            throw e;
        } catch (Exception e) {
View Full Code Here

    public void setEnv(String key, String value) {
        env.put(key, value);
    }

    protected void doOpen() throws IOException {
        Buffer buffer;

        if (agentForwarding) {
            log.info("Send agent forwarding request");
            buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
            buffer.putInt(recipient);
            buffer.putString("auth-agent-req@openssh.com");
            buffer.putBoolean(false);
            writePacket(buffer);
        }

        if (usePty) {
            log.info("Send SSH_MSG_CHANNEL_REQUEST pty-req");
            buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
            buffer.putInt(recipient);
            buffer.putString("pty-req");
            buffer.putBoolean(false);
            buffer.putString(ptyType);
            buffer.putInt(ptyColumns);
            buffer.putInt(ptyLines);
            buffer.putInt(ptyHeight);
            buffer.putInt(ptyWidth);
            Buffer modes = new Buffer();
            for (PtyMode mode : ptyModes.keySet()) {
                modes.putByte((byte) mode.toInt());
                modes.putInt(ptyModes.get(mode));
            }
            modes.putByte((byte) 0);
            buffer.putBytes(modes.getCompactData());
            writePacket(buffer);
        }

        if (!env.isEmpty()) {
            log.info("Send SSH_MSG_CHANNEL_REQUEST env");
View Full Code Here

    /**
     * Receive binary data
     */
    protected int data(byte[] buf, int start, int len) throws IOException {
        Buffer incoming = new Buffer(buf,  start, len);
        // If we already have partial data, we need to append it to the buffer and use it
        if (receiveBuffer.available() > 0) {
            receiveBuffer.putBuffer(incoming);
            incoming = receiveBuffer;
        }
        // Process commands
        int rpos = incoming.rpos();
        while (receive(incoming));
        int read = incoming.rpos() - rpos;
        // Compact and add remaining data
        receiveBuffer.compact();
        if (receiveBuffer != incoming && incoming.available() > 0) {
            receiveBuffer.putBuffer(incoming);
        }
        return read;
    }
View Full Code Here

    /**
     * Process an SFTP packet
     */
    protected void process(Buffer incoming) throws IOException {
        Buffer buffer = new Buffer();
        buffer.putBuffer(incoming);
        buffer.rpos(5);
        int id = buffer.getInt();
        buffer.rpos(0);
        synchronized (messages) {
            messages.put(id, buffer);
            messages.notifyAll();
        }
    }
View Full Code Here

    }

    protected Buffer receive(int id) throws IOException {
        synchronized (messages) {
            while (true) {
                Buffer buffer = messages.get(id);
                if (buffer != null) {
                    return buffer;
                }
                try {
                    messages.wait();
View Full Code Here

        DataInputStream dis = new DataInputStream(channel.getInvertedOut());
        int length = dis.readInt();
        if (length < 5) {
            throw new IllegalArgumentException();
        }
        Buffer buffer = new Buffer(length + 4);
        buffer.putInt(length);
        int nb = length;
        while (nb > 0) {
            int l = dis.read(buffer.array(), buffer.wpos(), nb);
            if (l < 0) {
                throw new IllegalArgumentException();
            }
            buffer.wpos(buffer.wpos() + l);
            nb -= l;
        }
        return buffer;
    }
View Full Code Here

        this.subsystem = subsystem;
    }

    protected void doOpen() throws IOException {
        log.info("Send SSH_MSG_CHANNEL_REQUEST exec");
        Buffer buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
        buffer.putInt(recipient);
        buffer.putString("subsystem");
        buffer.putBoolean(false);
        buffer.putString(subsystem);
        writePacket(buffer);

        super.doOpen();
    }
View Full Code Here

        DataOutputStream dos = new DataOutputStream(channel.getInvertedIn());
        dos.writeInt(5);
        dos.writeByte(SSH_FXP_INIT);
        dos.writeInt(3);
        dos.flush();
        Buffer buffer = null;
        synchronized (messages) {
            while (messages.isEmpty()) {
                try {
                    messages.wait();
                } catch (InterruptedException e) {
                    throw (IOException) new InterruptedIOException().initCause(e);
                }
            }
            buffer = messages.remove(messages.keySet().iterator().next());

        }
        int length = buffer.getInt();
        int type = buffer.getByte();
        int id = buffer.getInt();
        if (type == SSH_FXP_VERSION) {
            if (id != 3) {
                throw new SshException("Unable to use SFTP v3, server replied with version " + id);
            }
        } else if (type == SSH_FXP_STATUS) {
            int substatus = buffer.getInt();
            String msg = buffer.getString();
            String lang = buffer.getString();
            throw new SshException("SFTP error (" + substatus + "): " + msg);
        } else {
            throw new SshException("Unexpected SFTP packet received: " + type);
        }
    }
View Full Code Here

            buffer.putInt(attributes.mtime);
        }
    }

    public Handle open(String path, EnumSet<OpenMode> options) throws IOException {
        Buffer buffer = new Buffer();
        buffer.putString(path);
        int mode = 0;
        for (OpenMode m : options) {
            switch (m) {
                case Read:      mode |= SSH_FXF_READ; break;
                case Write:     mode |= SSH_FXF_WRITE; break;
                case Append:    mode |= SSH_FXF_APPEND; break;
                case Create:    mode |= SSH_FXF_CREAT; break;
                case Truncate:  mode |= SSH_FXF_TRUNC; break;
                case Exclusive: mode |= SSH_FXF_EXCL; break;
            }
        }
        buffer.putInt(mode);
        buffer.putInt(0);
        return checkHandle(receive(send(SSH_FXP_OPEN, buffer)));
    }
View Full Code Here

TOP

Related Classes of org.apache.sshd.common.util.Buffer$BufferException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.