-/*
- rdesktop: A Remote Desktop Protocol client.
- RDP licensing negotiation
- Copyright (C) Matthew Chapman 1999-2002
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "rdesktop.h"
-
-#include <openssl/rc4.h>
-
-extern char g_username[16];
-extern char hostname[16];
-
-static uint8 g_licence_key[16];
-static uint8 g_licence_sign_key[16];
-
-BOOL g_licence_issued = False;
-
-/* Generate a session key and RC4 keys, given client and server randoms */
-void
-licence_generate_keys(uint8 * client_key, uint8 * server_key, uint8 * client_rsa)
-{
- uint8 session_key[48];
- uint8 temp_hash[48];
-
- /* Generate session key - two rounds of sec_hash_48 */
- sec_hash_48(temp_hash, client_rsa, client_key, server_key, 65);
- sec_hash_48(session_key, temp_hash, server_key, client_key, 65);
-
- /* Store first 16 bytes of session key, for generating signatures */
- memcpy(g_licence_sign_key, session_key, 16);
-
- /* Generate RC4 key */
- sec_hash_16(g_licence_key, &session_key[16], client_key, server_key);
-
- {
- int i;
-
- printf("g_license_key:\n");
- for (i = 0; i < 16; ++i)
- printf(" 0x%02x", g_licence_key[i]);
- printf("\n");
-
- printf("g_license_sign_key:\n");
- for (i = 0; i < 16; ++i)
- printf(" 0x%02x", g_licence_sign_key[i]);
- printf("\n");
- }
-}
-
-// "TEST" in UTF-16
-unsigned char license_token[] = {
- 0x54, 0x00, 0x45, 0x00, 0x53, 0x00, 0x54, 0x00, 0x00, 0x00
-};
-
-void
-send_authreq()
-{
- RC4_KEY crypt_key;
- uint8 in_token[LICENCE_TOKEN_SIZE], encrypt_token[LICENCE_TOKEN_SIZE];
- uint8 signature[LICENCE_SIGNATURE_SIZE];
-
- STREAM s = sec_init(38, SEC_LICENCE_NEG);
-
- out_uint8(s, LICENCE_TAG_AUTHREQ);
- out_uint8(s, 3); // version
- out_uint16_le(s, 38); // length
-
- // unknown
- out_uint16_le(s, 0xffff);
- out_uint16_le(s, 0xffff);
- out_uint16_le(s, 0x0000);
-
- out_uint16_le(s, LICENCE_TOKEN_SIZE);
- memcpy(in_token, license_token, LICENCE_TOKEN_SIZE);
-
- // encrypt the token
- RC4_set_key(&crypt_key, 16, g_licence_key);
- RC4(&crypt_key, LICENCE_TOKEN_SIZE, in_token, encrypt_token);
-
- out_uint8p(s, encrypt_token, LICENCE_TOKEN_SIZE);
-
- // what are we supposed to sign here, really? guess at the
- // token, nothing else has been sent...
- sec_sign(signature, 16, g_licence_sign_key, 16, encrypt_token, LICENCE_TOKEN_SIZE);
- out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
-
- s_mark_end(s);
- sec_send(s, SEC_LICENCE_NEG);
-}
-