Package org.vngx.jsch.exception

Examples of org.vngx.jsch.exception.JSchException


   */
  public Session createSession(String username, String host, int port, SessionConfig config) throws JSchException {
    try {
      return new Session(host, port, username, config);
    } catch(Exception e) {
      throw new JSchException("Failed to create Session: "+e, e);
    }
  }
View Full Code Here


      sendRequests();
      new RequestExec(_command).request(_session, this);
    } catch(JSchException je) {
      throw je;
    } catch(Exception e) {
      throw new JSchException("Failed to start ChannelExec", e);
    }

    if( _io.in != null ) {
      _thread = new Thread(this, "Exec thread " + _session.getHost());
      _thread.setDaemon(_session.isDaemonThread());
View Full Code Here

   * @throws JSchException
   */
  static void addPort(Session session, String bindAddress, int port, String target, int localPort, SocketFactory factory) throws JSchException {
    synchronized ( PORT_POOL ) {
      if( getPort(session, port) != null ) {
        throw new JSchException("PortForwardingR: remote port " + port + " is already registered.");
      }
      ForwardedPortData fpdata = new ForwardedPortData();
      fpdata._session = session;
      fpdata._remotePort = port;
      fpdata._target = target;
View Full Code Here

   * @throws JSchException
   */
  static void addPort(Session session, String bindAddress, int port, String daemon, Object[] arg) throws JSchException {
    synchronized ( PORT_POOL ) {
      if( getPort(session, port) != null ) {
        throw new JSchException("PortForwardingR: remote port " + port + " is already registered.");
      }
      ForwardedPortData fpdata = new ForwardedPortData();
      fpdata._session = session;
      fpdata._remotePort = port;
      fpdata._target = daemon;
View Full Code Here

   */
  @Override
  public void connect() throws JSchException {
    try {
      if( !_session.isConnected() ) {
        throw new JSchException("Failed to open channel: session is not connected");
      }
      Buffer buffer = new Buffer(150);
      Packet packet = new Packet(buffer);
      // send
      // byte   SSH_MSG_CHANNEL_OPEN(90)
      // string channel type         //
      // uint32 sender channel       // 0
      // uint32 initial window size  // 0x100000(65536)
      // uint32 maxmum packet size   // 0x4000(16384)
      packet.reset();
      buffer.putByte(SSH_MSG_CHANNEL_OPEN);
      buffer.putString(_type);
      buffer.putInt(_id);
      buffer.putInt(_localWindowSize);
      buffer.putInt(_localMaxPacketSize);
      buffer.putString(_host);
      buffer.putInt(_port);
      buffer.putString(_originatorIPAddress);
      buffer.putInt(_originatorPort);
      _session.write(packet);

      int retry = 1000;
      while( _recipient == -1 && _session.isConnected() && retry-- > 0 && !_eofRemote ) {
        try { Thread.sleep(50); } catch(InterruptedException e) { /* Ignore error. */ }
      }
      if( !_session.isConnected() ) {
        throw new JSchException("Failed to open channel: session is not connected");
      } else if( retry == 0 || _eofRemote ) {
        throw new JSchException("Failed to open channel: no response");
      }
      _connected = true;

      if( _io.in != null ) {
        _thread = new Thread(this, "DirectTCPIP thread " + _session.getHost());
        _thread.setDaemon(_session.isDaemonThread());
        _thread.start();
      }
    } catch(JSchException e) {
      _connected = false;
      disconnect();
      throw e;
    } catch(Exception e) {
      _connected = false;
      disconnect();
      throw new JSchException("Failed to open channel "+getClass().getSimpleName()+": "+_exitstatus, e);
    }
  }
View Full Code Here

        try {
          Thread.sleep(10);
        } catch(InterruptedException e) { /* Ignore error. */ }
        if( timeout > 0L && (System.currentTimeMillis() - start) > timeout ) {
          _channel._reply = 0;
          throw new JSchException("Channel request timed out after "+_channel._connectTimeout+"ms, "+getClass().getSimpleName());
        }
      }
      if( _channel._reply == 0 ) {  // Should this be an exception?
        throw new JSchException("Server responded with failure for channel request, "+getClass().getSimpleName());
      }
    }
  }
View Full Code Here

    try // Attempt to read in private key file
      fc = new FileInputStream(prvfile).getChannel();
      ByteBuffer bb = ByteBuffer.wrap(prvkey = new byte[(int) fc.size()]);
      fc.read(bb);
    } catch(Exception e) {
      throw new JSchException("Failed to read private key file: "+e, e);
    } finally {
      if( fc != null ) {
        try { fc.close(); } catch(IOException ioe) { /* Ignore error. */ }
        fc = null;
      }
    }

    String _pubfile = pubfile;
    if( pubfile == null ) {
      _pubfile = prvfile + ".pub";
    }

    try // Attempt to read in the public key file
      fc = new FileInputStream(_pubfile).getChannel();
      ByteBuffer bb = ByteBuffer.wrap(pubkey = new byte[(int) fc.size()]);
      fc.read(bb);
    } catch(Exception e) {
      if( pubfile != null ) {
        // The pubfile is explicitly given, but not accessible.
        throw new JSchException("Failed to read public key file: "+e, e);
      }
      pubkey = null// TODO Temp until figured out...
    } finally {
      if( fc != null ) {
        try { fc.close(); } catch(IOException ioe) { /* Ignore error. */ }
View Full Code Here

            _keyType = KeyType.SSH_RSA;
          } else if( buf[i] == 'S' && buf[i + 1] == 'S' && buf[i + 2] == 'H' ) { // FSecure
            _keyType = KeyType.UNKNOWN;
            _vendor = FSECURE;
          } else {
            throw new JSchException("invalid privatekey: " + _identity);
          }
          i += 3;
          continue;
        }
        if( buf[i] == 'A' && i+7 < len && buf[i + 1] == 'E' && buf[i + 2] == 'S' && buf[i + 3] == '-'
            && buf[i + 4] == '2' && buf[i + 5] == '5' && buf[i + 6] == '6' && buf[i + 7] == '-' ) {
          i += 8;
          if( CipherManager.getManager().isSupported(Cipher.CIPHER_AES256_CBC) ) {
            _cipher = CipherManager.getManager().createCipher(Cipher.CIPHER_AES256_CBC);
            _key = new byte[_cipher.getBlockSize()];
            _iv = new byte[_cipher.getIVSize()];
          } else {
            throw new JSchException("privatekey: aes256-cbc is not available " + _identity);
          }
          continue;
        }
        // If AES-192 encryption
        if( buf[i] == 'A' && i + 7 < len && buf[i + 1] == 'E' && buf[i + 2] == 'S' && buf[i + 3] == '-'
            && buf[i + 4] == '1' && buf[i + 5] == '9' && buf[i + 6] == '2' && buf[i + 7] == '-' ) {
          i += 8;
          if( CipherManager.getManager().isSupported(Cipher.CIPHER_AES192_CBC) ) {
            _cipher = CipherManager.getManager().createCipher(Cipher.CIPHER_AES192_CBC);
            _key = new byte[_cipher.getBlockSize()];
            _iv = new byte[_cipher.getIVSize()];
          } else {
            throw new JSchException("privatekey: aes192-cbc is not available " + _identity);
          }
          continue;
        }
        // If AES-128 encryption
        if( buf[i] == 'A' && i + 7 < len && buf[i + 1] == 'E' && buf[i + 2] == 'S' && buf[i + 3] == '-'
            && buf[i + 4] == '1' && buf[i + 5] == '2' && buf[i + 6] == '8' && buf[i + 7] == '-' ) {
          i += 8;
          if( CipherManager.getManager().isSupported(Cipher.CIPHER_AES128_CBC) ) {
            _cipher = CipherManager.getManager().createCipher(Cipher.CIPHER_AES128_CBC);
            _key = new byte[_cipher.getBlockSize()];
            _iv = new byte[_cipher.getIVSize()];
          } else {
            throw new JSchException("privatekey: aes128-cbc is not available " + _identity);
          }
          continue;
        }
        if( buf[i] == 'C' && i+3 < len && buf[i + 1] == 'B' && buf[i + 2] == 'C' && buf[i + 3] == ',' ) {
          i += 4;
          for( int ii = 0; ii < _iv.length; ii++ ) {
            _iv[ii] = (byte) (((a2b(buf[i++]) << 4) & 0xf0) + (a2b(buf[i++]) & 0xf));
          }
          continue;
        }
        if( buf[i] == 0x0d && i + 1 < len && buf[i + 1] == 0x0a ) {
          i++;
          continue;
        }
        if( buf[i] == 0x0a && i + 1 < len ) {
          if( buf[i + 1] == 0x0a ) {
            i += 2;
            break;
          }
          if( buf[i + 1] == 0x0d && i + 2 < len && buf[i + 2] == 0x0a ) {
            i += 3;
            break;
          }
          boolean inheader = false;
          for( int j = i + 1; j < len; j++ ) {
            if( buf[j] == 0x0a ) {
              break;
            }
            if( buf[j] == ':' ) {
              inheader = true;
              break;
            }
          }
          if( !inheader ) {
            i++;
            _encrypted = false;    // no passphrase
            break;
          }
        }
        i++;
      }

      if( _keyType == null ) {
        throw new JSchException("invalid privatekey: " + _identity);
      }

      int start = i;
      while( i < len ) {
        if( buf[i] == 0x0a ) {
          boolean xd = (buf[i - 1] == 0x0d);
          System.arraycopy(buf, i + 1, buf, i - (xd ? 1 : 0), len - i - 1 - (xd ? 1 : 0));
          if( xd ) {
            len--;
          }
          len--;
          continue;
        }
        if( buf[i] == '-' ) {
          break;
        }
        i++;
      }
      _encodedData = Util.fromBase64(buf, start, i - start);

      if( _encodedData.length > 4 && // FSecure
          _encodedData[0] == (byte) 0x3f
          && _encodedData[1] == (byte) 0x6f
          && _encodedData[2] == (byte) 0xf9
          && _encodedData[3] == (byte) 0xeb ) {

        Buffer _buf = new Buffer(_encodedData);
        _buf.getInt()// 0x3f6ff9be
        _buf.getInt();
        @SuppressWarnings("unused")
        byte[] typeName = _buf.getString();
        byte[] cipherName = _buf.getString();
        String cipher = Util.byte2str(cipherName);
        if( cipher.equals("3des-cbc") ) {
          _buf.getInt();
          byte[] foo = new byte[_encodedData.length - _buf.getOffSet()];
          _buf.getBytes(foo);
          _encodedData = foo;
          _encrypted = true;
          throw new JSchException("unknown privatekey format: " + _identity);
        } else if( cipher.equals("none") ) {
          _buf.getInt();
          //_buf.getInt();
          _encrypted = false;
          byte[] foo = new byte[_encodedData.length - _buf.getOffSet()];
          _buf.getBytes(foo);
          _encodedData = foo;
        }
      }

      if( pubkey == null ) {
        return;
      }

      buf = pubkey;
      len = buf.length;

      if( buf.length > 4 && // FSecure's public key
          buf[0] == '-' && buf[1] == '-' && buf[2] == '-' && buf[3] == '-' ) {
        i = 0;
        do {
          i++;
        } while( len > i && buf[i] != 0x0a );
        if( len <= i ) {
          return;
        }
        while( i < len ) {
          if( buf[i] == 0x0a ) {
            boolean inheader = false;
            for( int j = i + 1; j < len; j++ ) {
              if( buf[j] == 0x0a ) {
                break;
              }
              if( buf[j] == ':' ) {
                inheader = true;
                break;
              }
            }
            if( !inheader ) {
              i++;
              break;
            }
          }
          i++;
        }
        if( len <= i ) {
          return;
        }

        start = i;
        while( i < len ) {
          if( buf[i] == 0x0a ) {
            System.arraycopy(buf, i + 1, buf, i, len - i - 1);
            len--;
            continue;
          }
          if( buf[i] == '-' ) {
            break;
          }
          i++;
        }
        _publicKeyBlob = Util.fromBase64(buf, start, i - start);

        if( _keyType == KeyType.UNKNOWN && _publicKeyBlob.length > 8 ) {
          if( _publicKeyBlob[8] == 'd' ) {
            _keyType = KeyType.SSH_DSS;
          } else if( _publicKeyBlob[8] == 'r' ) {
            _keyType = KeyType.SSH_RSA;
          }
        }
      } else {
        if( buf[0] != 's' || buf[1] != 's' || buf[2] != 'h' || buf[3] != '-' ) {
          return;
        }
        i = 0;
        while( i < len ) {
          if( buf[i] == ' ' ) {
            break;
          }
          i++;
        }
        i++;
        if( i >= len ) {
          return;
        }
        start = i;
        while( i < len ) {
          if( buf[i] == ' ' || buf[i] == '\n' ) {
            break;
          }
          i++;
        }
        _publicKeyBlob = Util.fromBase64(buf, start, i - start);
        if( _publicKeyBlob.length < 4 + 7 ) {  // It must start with "ssh-XXX".
          _publicKeyBlob = null;
        }
      }
    } catch(JSchException e) {
      throw e;
    } catch(Exception e) {
      throw new JSchException("Failed to create IdentityFile instance: "+e, e);
    }
  }
View Full Code Here

        return true;
      }
      _pDSA = _qDSA = _gDSA = _pubKeyDSA = _prvKeyDSA = null;
      return false;
    } catch(Exception e) {
      throw new JSchException("Failed to set passphrase: "+e, e);
    } finally {
      Util.bzero(passphrase);
    }
  }
View Full Code Here

        case SSH_MSG_USERAUTH_FAILURE:
          userAuthFailure()// Receive methods which can continue
          return false;

        default:
          throw new JSchException("Invalid UserAuth 'none' response: " + _buffer.getCommand());
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.vngx.jsch.exception.JSchException

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.