Exemplo n.º 1
0
  /**
   * 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;
    }
  }