Package net.schmizz.sshj.transport

Examples of net.schmizz.sshj.transport.TransportException


    @Override
    public void handle(Message msg, SSHPacket buf)
            throws SSHException {
        if (!msg.in(50, 80)) // ssh-userauth packets have message numbers between 50-80
            throw new TransportException(DisconnectReason.PROTOCOL_ERROR);

        switch (msg) {

            case USERAUTH_BANNER: {
                banner = buf.readString();
View Full Code Here


                    to.putRawBytes(tempBuf, 0, BUF_SIZE - stream.avail_out);
                    break;
                case JZlib.Z_BUF_ERROR:
                    return;
                default:
                    throw new TransportException(DisconnectReason.COMPRESSION_ERROR, "uncompress: inflate returned "
                            + status);
            }
        }
    }
View Full Code Here

    @Override
    public boolean next(Message msg, SSHPacket packet)
            throws GeneralSecurityException, TransportException {
        if (msg != Message.KEXDH_31)
            throw new TransportException(DisconnectReason.KEY_EXCHANGE_FAILED, "Unexpected packet: " + msg);

        log.info("Received SSH_MSG_KEXDH_REPLY");
        final byte[] K_S;
        final BigInteger f;
        final byte[] sig; // signature sent by server
        try {
            K_S = packet.readBytes();
            f = packet.readMPInt();
            sig = packet.readBytes();
            hostKey = new Buffer.PlainBuffer(K_S).readPublicKey();
        } catch (Buffer.BufferException be) {
            throw new TransportException(be);
        }

        dh.computeK(f);

        final Buffer.PlainBuffer buf = new Buffer.PlainBuffer()
                .putString(V_C)
                .putString(V_S)
                .putString(I_C)
                .putString(I_S)
                .putString(K_S)
                .putMPInt(dh.getE())
                .putMPInt(f)
                .putMPInt(dh.getK());
        sha1.update(buf.array(), buf.rpos(), buf.available());
        H = sha1.digest();

        Signature signature = Factory.Named.Util.create(trans.getConfig().getSignatureFactories(),
                                                        KeyType.fromKey(hostKey).toString());
        signature.init(hostKey, null);
        signature.update(H, 0, H.length);
        if (!signature.verify(sig))
            throw new TransportException(DisconnectReason.KEY_EXCHANGE_FAILED,
                                         "KeyExchange signature verification failed");
        return true;
    }
View Full Code Here

   public void testExceptionClassesRetry() {
      assert ssh.shouldRetry(new ConnectionException("Read timed out", new SSHException("Read timed out",
            new SocketTimeoutException("Read timed out"))));
      assert ssh.shouldRetry(new SFTPException("Failure!"));
      assert ssh.shouldRetry(new SocketTimeoutException("connect timed out"));
      assert ssh.shouldRetry(new TransportException("socket closed"));
      assert ssh.shouldRetry(new ConnectionException("problem"));
      assert ssh.shouldRetry(new ConnectException("Connection refused"));
      assert !ssh.shouldRetry(new IOException("channel %s is not open", new NullPointerException()));
   }
View Full Code Here

   public void testExceptionClassesRetry() {
      assert ssh.shouldRetry(new ConnectionException("Read timed out", new SSHException("Read timed out",
            new SocketTimeoutException("Read timed out"))));
      assert ssh.shouldRetry(new SFTPException("Failure!"));
      assert ssh.shouldRetry(new SocketTimeoutException("connect timed out"));
      assert ssh.shouldRetry(new TransportException("socket closed"));
      assert ssh.shouldRetry(new ConnectionException("problem"));
      assert ssh.shouldRetry(new ConnectException("Connection refused"));
      assert !ssh.shouldRetry(new IOException("channel %s is not open", new NullPointerException()));
   }
View Full Code Here

    @Override
    public boolean next(Message msg, SSHPacket packet)
            throws GeneralSecurityException, TransportException {
        if (msg != Message.KEXDH_31)
            throw new TransportException(DisconnectReason.KEY_EXCHANGE_FAILED, "Unexpected packet: " + msg);

        log.debug("Received SSH_MSG_KEXDH_REPLY");
        final byte[] K_S;
        final BigInteger f;
        final byte[] sig; // signature sent by server
        try {
            K_S = packet.readBytes();
            f = packet.readMPInt();
            sig = packet.readBytes();
            hostKey = new Buffer.PlainBuffer(K_S).readPublicKey();
        } catch (Buffer.BufferException be) {
            throw new TransportException(be);
        }

        dh.computeK(f);

        final Buffer.PlainBuffer buf = new Buffer.PlainBuffer()
                .putString(V_C)
                .putString(V_S)
                .putString(I_C)
                .putString(I_S)
                .putString(K_S)
                .putMPInt(dh.getE())
                .putMPInt(f)
                .putMPInt(dh.getK());
        sha1.update(buf.array(), buf.rpos(), buf.available());
        H = sha1.digest();

        Signature signature = Factory.Named.Util.create(trans.getConfig().getSignatureFactories(),
                                                        KeyType.fromKey(hostKey).toString());
        signature.init(hostKey, null);
        signature.update(H, 0, H.length);
        if (!signature.verify(sig))
            throw new TransportException(DisconnectReason.KEY_EXCHANGE_FAILED,
                                         "KeyExchange signature verification failed");
        return true;
    }
View Full Code Here

    @Override
    public void handle(Message msg, SSHPacket buf)
            throws SSHException {
        if (!msg.in(50, 80)) // ssh-userauth packets have message numbers between 50-80
            throw new TransportException(DisconnectReason.PROTOCOL_ERROR);

        authenticated.lock();
        try {
            switch (msg) {
View Full Code Here

                    to.putRawBytes(tempBuf, 0, BUF_SIZE - stream.avail_out);
                    break;
                case JZlib.Z_BUF_ERROR:
                    return;
                default:
                    throw new TransportException(DisconnectReason.COMPRESSION_ERROR, "uncompress: inflate returned "
                            + status);
            }
        }
    }
View Full Code Here

   public void testExceptionClassesRetry() {
      assert ssh.shouldRetry(new ConnectionException("Read timed out", new SSHException("Read timed out",
            new SocketTimeoutException("Read timed out"))));
      assert ssh.shouldRetry(new SFTPException("Failure!"));
      assert ssh.shouldRetry(new SocketTimeoutException("connect timed out"));
      assert ssh.shouldRetry(new TransportException("socket closed"));
      assert ssh.shouldRetry(new ConnectionException("problem"));
      assert ssh.shouldRetry(new ConnectException("Connection refused"));
      assert !ssh.shouldRetry(new IOException("channel %s is not open", new NullPointerException()));
   }
View Full Code Here

TOP

Related Classes of net.schmizz.sshj.transport.TransportException

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.