Ejemplo n.º 1
0
  /**
   * @param key
   * @param update_key
   * @return
   * @throws CryptoException
   */
  public byte[] update(byte[] key, byte[] update_key) throws CryptoException {
    byte[] shasig = new byte[20];
    byte[] update = new byte[this.keylength]; // changed from 8 - rdesktop
    // 1.2.0
    byte[] thekey = new byte[key.length];

    synchronized (digestLock) {
      sha1.reset();
      sha1.update(update_key, 0, keylength);
      sha1.update(pad_54, 0, 40);
      sha1.update(key, 0, keylength); // changed from 8 - rdesktop
      // 1.2.0
      shasig = sha1.digest();
      sha1.reset();

      md5.reset();
      md5.update(update_key, 0, keylength); // changed from 8 - rdesktop
      // 1.2.0
      md5.update(pad_92, 0, 48);
      md5.update(shasig, 0, 20);
      thekey = md5.digest();
      md5.reset();

      System.arraycopy(thekey, 0, update, 0, this.keylength);
      rc4_update.engineInitDecrypt(update);
      // added
      thekey = rc4_update.crypt(thekey, 0, this.keylength);

      if (this.keylength == 8) {
        this.make40bit(thekey);
      }
    }

    return thekey;
  }
Ejemplo n.º 2
0
  /**
   * Generate encryption keys of applicable size for connection
   *
   * @param rc4_key_size Size of keys to generate (1 if 40-bit encryption, otherwise 128-bit)
   * @throws CryptoException
   */
  public void generate_keys(int rc4_key_size) throws CryptoException {
    byte[] session_key = new byte[48];
    byte[] temp_hash = new byte[48];
    byte[] input = new byte[48];

    System.arraycopy(this.client_random, 0, input, 0, 24);
    System.arraycopy(this.server_random, 0, input, 24, 24);

    temp_hash = this.hash48(input, this.client_random, this.server_random, 65);
    session_key = this.hash48(temp_hash, this.client_random, this.server_random, 88);

    System.arraycopy(session_key, 0, this.sec_sign_key, 0, 16);
    // changed from 8 - rdesktop 1.2.0

    this.sec_decrypt_key = this.hash16(session_key, this.client_random, this.server_random, 16);
    this.sec_encrypt_key = this.hash16(session_key, this.client_random, this.server_random, 32);

    if (rc4_key_size == 1) {
      logger.info("40 Bit Encryption enabled");
      this.make40bit(this.sec_sign_key);
      this.make40bit(this.sec_decrypt_key);
      this.make40bit(this.sec_encrypt_key);
      this.keylength = 8;
    } else {
      logger.info("128 Bit Encryption enabled");
      this.keylength = 16;
    }

    System.arraycopy(
        this.sec_decrypt_key,
        0,
        this.sec_decrypt_update_key,
        0,
        16); // changed from 8 - rdesktop 1.2.0
    System.arraycopy(
        this.sec_encrypt_key,
        0,
        this.sec_encrypt_update_key,
        0,
        16); // changed from 8 - rdesktop 1.2.0

    byte[] key = new byte[this.keylength];
    System.arraycopy(this.sec_encrypt_key, 0, key, 0, this.keylength);
    rc4_enc.engineInitEncrypt(key);
    System.arraycopy(this.sec_decrypt_key, 0, key, 0, this.keylength);
    rc4_dec.engineInitDecrypt(key);
  }