Package org.apache.sshd.common

Examples of org.apache.sshd.common.SshException


        String curveName = getString();
        byte[] groupBytes = getStringAsBytes();
        BigInteger exponent = getMPInt();

        if (!expectedCurveName.equals(curveName)) {
            throw new SshException("Expected curve " + expectedCurveName + " but was " + curveName);
        }

        ECPoint group = ECCurves.decodeECPoint(groupBytes, spec.getCurve());
        if (group == null) {
            throw new InvalidKeySpecException("Couldn't decode EC group");
View Full Code Here


                src = (InetSocketAddress) serverSession.getRemoteAddress();
                dst = (InetSocketAddress) serverSession.getLocalAddress();
                break;
        }
        if (closeFuture.isClosed()) {
            throw new SshException("Session has been closed");
        }
        openFuture = new DefaultOpenFuture(lock);
        log.info("Send SSH_MSG_CHANNEL_OPEN on channel {}", this);
        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN);
        buffer.putString(type);
View Full Code Here

        buffer.putBoolean(true);
        buffer.putString(remote.getHostName());
        buffer.putInt(remote.getPort());
        Buffer result = session.request(buffer);
        if (result == null) {
            throw new SshException("Tcpip forwarding request denied by server");
        }
        int port = remote.getPort() == 0 ? result.getInt() : remote.getPort();
        // TODO: Is it really safe to only store the local address after the request ?
        remoteToLocal.put(port, local);
        return new SshdSocketAddress(remote.getHostName(), port);
View Full Code Here

        write(b, 0, 1);
    }

    public synchronized void write(byte[] buf, int s, int l) throws IOException {
        if (closed) {
            throw new SshException("Already closed");
        }
        while (l > 0) {
            // The maximum amount we should admit without flushing again
            // is enough to make up one full packet within our allowed
            // window size.  We give ourselves a credit equal to the last
View Full Code Here

    }

    @Override
    public synchronized void flush() throws IOException {
        if (closed) {
            throw new SshException("Already closed");
        }
        try {
            while (bufferLength > 0) {
                Buffer buf = buffer;
                int total = bufferLength;
                int length = Math.min(Math.min(remoteWindow.waitForSpace(), total), remoteWindow.getPacketSize());
                int pos = buf.wpos();
                buf.wpos(cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA ? 14 : 10);
                buf.putInt(length);
                buf.wpos(buf.wpos() + length);
                if (total == length) {
                    newBuffer(length);
                } else {
                    int leftover = total - length;
                    newBuffer(Math.max(leftover, length));
                    buffer.putRawBytes(buf.array(), pos - leftover, leftover);
                    bufferLength = leftover;
                }
                lastSize = length;
                remoteWindow.waitAndConsume(length);
                log.debug("Send {} on channel {}", cmd == SshConstants.SSH_MSG_CHANNEL_DATA ? "SSH_MSG_CHANNEL_DATA" : "SSH_MSG_CHANNEL_EXTENDED_DATA", channel.getId());
                channel.writePacket(buf);
            }
        } catch (WindowClosedException e) {
            closed = true;
            throw e;
        } catch (SshException e) {
            throw e;
        } catch (Exception e) {
            throw new SshException(e);
        }
    }
View Full Code Here

    }

    public boolean next(Buffer buffer) throws Exception {
        byte cmd = buffer.getByte();
        if (cmd != expected) {
            throw new SshException(SshConstants.SSH2_DISCONNECT_KEY_EXCHANGE_FAILED,
                    "Protocol error: expected packet " + expected + ", got " + cmd);
        }

        if (cmd == SshConstants.SSH_MSG_KEX_DH_GEX_GROUP) {
            log.debug("Received SSH_MSG_KEX_DH_GEX_GROUP");
            p = buffer.getMPIntAsBytes();
            g = buffer.getMPIntAsBytes();

            dh = getDH(new BigInteger(p), new BigInteger(g));
            hash =  dh.getHash();
            hash.init();
            e = dh.getE();

            log.debug("Send SSH_MSG_KEX_DH_GEX_INIT");
            buffer = session.createBuffer(SshConstants.SSH_MSG_KEX_DH_GEX_INIT);
            buffer.putMPInt(e);
            session.writePacket(buffer);
            expected = SshConstants.SSH_MSG_KEX_DH_GEX_REPLY;
            return false;
        }

        if (cmd == SshConstants.SSH_MSG_KEX_DH_GEX_REPLY) {
            log.debug("Received SSH_MSG_KEX_DH_GEX_REPLY");
            byte[] K_S = buffer.getBytes();
            f = buffer.getMPIntAsBytes();
            byte[] sig = buffer.getBytes();
            dh.setF(f);
            K = dh.getK();

            buffer = new Buffer(K_S);
            serverKey = buffer.getRawPublicKey();
            final String keyAlg;
            if (serverKey instanceof RSAPublicKey) {
                keyAlg = KeyPairProvider.SSH_RSA;
            } else if (serverKey instanceof DSAPublicKey) {
                keyAlg = KeyPairProvider.SSH_DSS;
            } else if (serverKey instanceof ECPublicKey) {
                keyAlg = ECCurves.ECDSA_SHA2_PREFIX + ECCurves.getCurveName(((ECPublicKey) serverKey).getParams());
            } else {
                throw new SshException("Unsupported server key type");
            }

            buffer = new Buffer();
            buffer.putString(V_C);
            buffer.putString(V_S);
            buffer.putString(I_C);
            buffer.putString(I_S);
            buffer.putString(K_S);
            buffer.putInt(min);
            buffer.putInt(prf);
            buffer.putInt(max);
            buffer.putMPInt(p);
            buffer.putMPInt(g);
            buffer.putMPInt(e);
            buffer.putMPInt(f);
            buffer.putMPInt(K);
            hash.update(buffer.array(), 0, buffer.available());
            H = hash.digest();

            Signature verif = NamedFactory.Utils.create(session.getFactoryManager().getSignatureFactories(), keyAlg);
            verif.init(serverKey, null);
            verif.update(H, 0, H.length);
            if (!verif.verify(sig)) {
                throw new SshException(SshConstants.SSH2_DISCONNECT_KEY_EXCHANGE_FAILED,
                        "KeyExchange signature verification failed");
            }
            return true;
        }
View Full Code Here

    public void verify() throws SshException {
        try {
            await();
        }
        catch (InterruptedException e) {
            throw new SshException("Authentication interrupted", e);
        }
        if (!isSuccess()) {
            throw new SshException("Authentication failed", getException());
        }
    }
View Full Code Here

        if (serverVersion == null) {
            return false;
        }
        log.info("Server version string: {}", serverVersion);
        if (!(serverVersion.startsWith("SSH-2.0-") || serverVersion.startsWith("SSH-1.99-"))) {
            throw new SshException(SshConstants.SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED,
                                   "Unsupported protocol version: " + serverVersion);
        }
        return true;
    }
View Full Code Here

    protected void checkKeys() throws SshException {
        ServerKeyVerifier serverKeyVerifier = getFactoryManager().getServerKeyVerifier();
        SocketAddress remoteAddress = ioSession.getRemoteAddress();

        if (!serverKeyVerifier.verifyServerKey(this, remoteAddress, kex.getServerKey())) {
            throw new SshException("Server key did not validate");
        }
    }
View Full Code Here

    public void verify() throws SshException {
        try {
            await();
        }
        catch (InterruptedException e) {
            throw new SshException("Channel opening interrupted", e);
        }
        if (!isOpened()) {
            throw new SshException("Channel opening failed", getException());
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.sshd.common.SshException

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.