Example #1
0
 public void putRawPublicKey(PublicKey key) {
   if (key instanceof RSAPublicKey) {
     putString(KeyPairProvider.SSH_RSA);
     putMPInt(((RSAPublicKey) key).getPublicExponent());
     putMPInt(((RSAPublicKey) key).getModulus());
   } else if (key instanceof DSAPublicKey) {
     putString(KeyPairProvider.SSH_DSS);
     putMPInt(((DSAPublicKey) key).getParams().getP());
     putMPInt(((DSAPublicKey) key).getParams().getQ());
     putMPInt(((DSAPublicKey) key).getParams().getG());
     putMPInt(((DSAPublicKey) key).getY());
   } else {
     throw new IllegalStateException("Unsupported algorithm: " + key.getAlgorithm());
   }
 }
Example #2
0
 public void putKeyPair(KeyPair key) {
   if (key.getPrivate() instanceof RSAPrivateCrtKey) {
     putString(KeyPairProvider.SSH_RSA);
     putMPInt(((RSAPublicKey) key.getPublic()).getPublicExponent());
     putMPInt(((RSAPublicKey) key.getPublic()).getModulus());
     putMPInt(((RSAPrivateCrtKey) key.getPrivate()).getPrivateExponent());
     putMPInt(((RSAPrivateCrtKey) key.getPrivate()).getCrtCoefficient());
     putMPInt(((RSAPrivateCrtKey) key.getPrivate()).getPrimeQ());
     putMPInt(((RSAPrivateCrtKey) key.getPrivate()).getPrimeP());
   } else if (key.getPublic() instanceof DSAPublicKey) {
     putString(KeyPairProvider.SSH_DSS);
     putMPInt(((DSAPublicKey) key.getPublic()).getParams().getP());
     putMPInt(((DSAPublicKey) key.getPublic()).getParams().getQ());
     putMPInt(((DSAPublicKey) key.getPublic()).getParams().getG());
     putMPInt(((DSAPublicKey) key.getPublic()).getY());
     putMPInt(((DSAPrivateKey) key.getPrivate()).getX());
   } else {
     throw new IllegalStateException("Unsupported algorithm: " + key.getPublic().getAlgorithm());
   }
 }
Example #3
0
  protected void doOpen() throws Exception {
    super.doOpen();

    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("*****@*****.**");
      buffer.putBoolean(false);
      session.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());
      session.writePacket(buffer);
    }

    if (!env.isEmpty()) {
      log.info("Send SSH_MSG_CHANNEL_REQUEST env");
      for (Map.Entry<String, String> entry : env.entrySet()) {
        buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
        buffer.putInt(recipient);
        buffer.putString("env");
        buffer.putBoolean(false);
        buffer.putString(entry.getKey());
        buffer.putString(entry.getValue());
        session.writePacket(buffer);
      }
    }

    log.info("Send SSH_MSG_CHANNEL_REQUEST shell");
    buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
    buffer.putInt(recipient);
    buffer.putString("shell");
    buffer.putBoolean(false);
    session.writePacket(buffer);
  }
Example #4
0
 protected void sendInitialServiceRequest() throws IOException {
   if (initialServiceRequestSent) {
     return;
   }
   initialServiceRequestSent = true;
   log.debug("Send SSH_MSG_SERVICE_REQUEST for {}", currentServiceFactory.getName());
   Buffer request = createBuffer(SshConstants.SSH_MSG_SERVICE_REQUEST);
   request.putString(currentServiceFactory.getName());
   writePacket(request);
   // Assuming that MINA-SSHD only implements "explicit server authentication" it is permissible
   // for the client's service to start sending data before the service-accept has been received.
   // If "implicit authentication" were to ever be supported, then this would need to be
   // called after service-accept comes back.  See SSH-TRANSPORT.
   currentService.start();
 }
Example #5
0
 public void putString(String string) {
   putString(string.getBytes());
 }