コード例 #1
0
ファイル: Secure.java プロジェクト: frenche/properJavaRDP-1
  /**
   * Intialise a packet at the Secure layer
   *
   * @param flags Encryption flags
   * @param length Length of packet
   * @return Intialised packet
   * @throws RdesktopException
   */
  public RdpPacket_Localised init(int flags, int length) throws RdesktopException {
    int headerlength = 0;
    RdpPacket_Localised buffer;

    if (!this.licenceIssued) headerlength = ((flags & SEC_ENCRYPT) != 0) ? 12 : 4;
    else headerlength = ((flags & SEC_ENCRYPT) != 0) ? 12 : 0;

    buffer = McsLayer.init(length + headerlength);
    buffer.pushLayer(RdpPacket.SECURE_HEADER, headerlength);
    // buffer.setHeader(RdpPacket_Localised.SECURE_HEADER);
    // buffer.incrementPosition(headerlength);
    // buffer.setStart(buffer.getPosition());
    return buffer;
  }
コード例 #2
0
ファイル: Secure.java プロジェクト: frenche/properJavaRDP-1
  /**
   * Connect to server
   *
   * @param host Address of server to connect to
   * @param port Port to connect to
   * @throws UnknownHostException
   * @throws IOException
   * @throws RdesktopException
   * @throws SocketException
   * @throws CryptoException
   * @throws OrderException
   */
  public void connect(InetAddress host, int port)
      throws UnknownHostException, IOException, RdesktopException, SocketException, CryptoException,
          OrderException {
    if (Options.hostname == "") {
      InetAddress localhost = InetAddress.getLocalHost();
      String name = localhost.getHostName();
      StringTokenizer tok = new StringTokenizer(name, ".");
      Options.hostname = tok.nextToken();
      Options.hostname.trim();
    }

    RdpPacket_Localised mcs_data = this.sendMcsData();
    McsLayer.connect(host, port, mcs_data);

    this.processMcsData(mcs_data);
    if (Constants.encryption) {
      this.establishKey();
    }
  }
コード例 #3
0
ファイル: Secure.java プロジェクト: frenche/properJavaRDP-1
  /**
   * Receive a Secure layer PDU from the MCS layer
   *
   * @return Packet representing received Secure PDU
   * @throws RdesktopException
   * @throws IOException
   * @throws CryptoException
   * @throws OrderException
   */
  public RdpPacket_Localised receive()
      throws RdesktopException, IOException, CryptoException, OrderException {
    int sec_flags = 0;
    RdpPacket_Localised buffer = null;
    while (true) {
      int[] channel = new int[1];
      buffer = McsLayer.receive(channel);
      if (buffer == null) return null;
      buffer.setHeader(RdpPacket.SECURE_HEADER);
      if (Constants.encryption || (!this.licenceIssued)) {

        sec_flags = buffer.getLittleEndian32();

        if ((sec_flags & SEC_LICENCE_NEG) != 0) {
          licence.process(buffer);
          continue;
        }
        if ((sec_flags & SEC_ENCRYPT) != 0) {
          buffer.incrementPosition(8); // signature
          byte[] data = new byte[buffer.size() - buffer.getPosition()];
          buffer.copyToByteArray(data, 0, buffer.getPosition(), data.length);
          byte[] packet = this.decrypt(data);

          buffer.copyFromByteArray(packet, 0, buffer.getPosition(), packet.length);

          // buffer.setStart(buffer.getPosition());
          // return buffer;
        }
      }

      if (channel[0] != MCS.MCS_GLOBAL_CHANNEL) {
        channels.channel_process(buffer, channel[0]);
        continue;
      }

      buffer.setStart(buffer.getPosition());
      return buffer;
    }
  }
コード例 #4
0
ファイル: Secure.java プロジェクト: frenche/properJavaRDP-1
  /**
   * Prepare data as a Secure PDU and pass down to the MCS layer
   *
   * @param sec_data Data to send
   * @param flags Encryption flags
   * @param channel Channel over which to send data
   * @throws RdesktopException
   * @throws IOException
   * @throws CryptoException
   */
  public void send_to_channel(RdpPacket_Localised sec_data, int flags, int channel)
      throws RdesktopException, IOException, CryptoException {
    int datalength = 0;
    byte[] signature = null;
    byte[] data;
    byte[] buffer;

    sec_data.setPosition(sec_data.getHeader(RdpPacket.SECURE_HEADER));

    if (this.licenceIssued == false || (flags & SEC_ENCRYPT) != 0) {
      sec_data.setLittleEndian32(flags);
    }

    if (Options.debug_hexdump) {
      int length = sec_data.getEnd() - sec_data.getPosition();
      byte[] packet = new byte[length];
      sec_data.copyToByteArray(
          packet, 0, sec_data.getPosition(), sec_data.getEnd() - sec_data.getPosition());
      System.out.println("Sending packet:");
      System.out.println(net.propero.rdp.tools.HexDump.dumpHexString(packet));
    }

    if ((flags & SEC_ENCRYPT) != 0) {
      flags &= ~SEC_ENCRYPT;
      datalength = sec_data.getEnd() - sec_data.getPosition() - 8;
      data = new byte[datalength];
      buffer = null;
      sec_data.copyToByteArray(data, 0, sec_data.getPosition() + 8, datalength);
      signature = this.sign(this.sec_sign_key, 8, this.keylength, data, datalength);

      buffer = this.encrypt(data, datalength);

      sec_data.copyFromByteArray(signature, 0, sec_data.getPosition(), 8);
      sec_data.copyFromByteArray(buffer, 0, sec_data.getPosition() + 8, datalength);
    }
    // McsLayer.send(sec_data);
    McsLayer.send_to_channel(sec_data, channel);
  }
コード例 #5
0
ファイル: Secure.java プロジェクト: frenche/properJavaRDP-1
 /** Close connection */
 public void disconnect() {
   McsLayer.disconnect();
 }
コード例 #6
0
ファイル: Secure.java プロジェクト: frenche/properJavaRDP-1
 /** @return MCS user ID */
 public int getUserID() {
   return McsLayer.getUserID();
 }