public void run() {
    try {
      state.setValue(TransportProtocolState.NEGOTIATING_PROTOCOL);
      log.info("Registering transport protocol messages with inputstream");
      algorithmsOut = new TransportProtocolAlgorithmSync();
      algorithmsIn = new TransportProtocolAlgorithmSync();

      // Create the input/output streams
      sshIn = new TransportProtocolInputStream(this, provider.getInputStream(), algorithmsIn);
      sshOut = new TransportProtocolOutputStream(provider.getOutputStream(), this, algorithmsOut);

      // Register the transport layer messages that this class will handle
      messageStore.registerMessage(SshMsgDisconnect.SSH_MSG_DISCONNECT, SshMsgDisconnect.class);
      messageStore.registerMessage(SshMsgIgnore.SSH_MSG_IGNORE, SshMsgIgnore.class);
      messageStore.registerMessage(
          SshMsgUnimplemented.SSH_MSG_UNIMPLEMENTED, SshMsgUnimplemented.class);
      messageStore.registerMessage(SshMsgDebug.SSH_MSG_DEBUG, SshMsgDebug.class);
      messageStore.registerMessage(SshMsgKexInit.SSH_MSG_KEX_INIT, SshMsgKexInit.class);
      messageStore.registerMessage(SshMsgNewKeys.SSH_MSG_NEWKEYS, SshMsgNewKeys.class);
      registerTransportMessages();

      List list = SshKeyExchangeFactory.getSupportedKeyExchanges();
      Iterator it = list.iterator();

      while (it.hasNext()) {
        String keyExchange = (String) it.next();
        SshKeyExchange kex = SshKeyExchangeFactory.newInstance(keyExchange);
        kex.init(this);
        kexs.put(keyExchange, kex);
      }

      // call abstract to initialise the local ident string
      setLocalIdent();

      // negotiate the protocol version
      negotiateVersion();
      startBinaryPacketProtocol();
    } catch (Throwable e) {
      if (e instanceof IOException) {
        state.setLastError((IOException) e);
      }

      if (state.getValue() != TransportProtocolState.DISCONNECTED) {
        log.error("The Transport Protocol thread failed", e);

        // log.info(e.getMessage());
        stop();
      }
    } finally {
      thread = null;
    }

    log.debug("The Transport Protocol has been stopped");
  }
Example #2
0
  /**
   * Creates a new SshMsgKexInit object.
   *
   * @param props
   */
  public SshMsgKexInit(SshConnectionProperties props) {
    super(SSH_MSG_KEX_INIT);

    // Create some random data
    cookie = new byte[16];

    // Seed the random number generator
    Random r = ConfigurationLoader.getRND();

    // Get the next random bytes into our cookie
    r.nextBytes(cookie);

    // Get the supported algorithms from the factory objects but adding the
    // preffered algorithm to the top of the list
    supportedKex =
        sortAlgorithmList(SshKeyExchangeFactory.getSupportedKeyExchanges(), props.getPrefKex());
    supportedPK = sortAlgorithmList(SshKeyPairFactory.getSupportedKeys(), props.getPrefPublicKey());
    supportedEncryptCS =
        sortAlgorithmList(SshCipherFactory.getSupportedCiphers(), props.getPrefCSEncryption());
    supportedEncryptSC =
        sortAlgorithmList(SshCipherFactory.getSupportedCiphers(), props.getPrefSCEncryption());
    supportedMacCS = sortAlgorithmList(SshHmacFactory.getSupportedMacs(), props.getPrefCSMac());
    supportedMacSC = sortAlgorithmList(SshHmacFactory.getSupportedMacs(), props.getPrefSCMac());
    supportedCompCS =
        sortAlgorithmList(SshCompressionFactory.getSupportedCompression(), props.getPrefCSComp());
    supportedCompSC =
        sortAlgorithmList(SshCompressionFactory.getSupportedCompression(), props.getPrefSCComp());

    // We currently don't support language preferences
    supportedLangCS = new ArrayList();
    supportedLangSC = new ArrayList();

    // We don't guess (I don't see the point of this in the protocol!)
    firstKexFollows = false;
  }