/[rdesktop]/sourceforge.net/trunk/rdesktop/licence.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/licence.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 437 by jsorg71, Mon Jul 28 21:41:12 2003 UTC revision 1372 by jsorg71, Mon Jan 8 04:47:06 2007 UTC
# Line 1  Line 1 
1  /*  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     RDP licensing negotiation     RDP licensing negotiation
4     Copyright (C) Matthew Chapman 1999-2002     Copyright (C) Matthew Chapman 1999-2007
5      
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
# Line 12  Line 12 
12     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.     GNU General Public License for more details.
15      
16     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */  */
20    
21  #include "rdesktop.h"  #include "rdesktop.h"
   
 #ifdef WITH_OPENSSL  
22  #include <openssl/rc4.h>  #include <openssl/rc4.h>
 #else  
 #include "crypto/rc4.h"  
 #endif  
23    
24  extern char g_username[16];  extern char g_username[64];
25  extern char hostname[16];  extern char g_hostname[16];
26    
27  static uint8 g_licence_key[16];  static uint8 g_licence_key[16];
28  static uint8 g_licence_sign_key[16];  static uint8 g_licence_sign_key[16];
29    
30  BOOL g_licence_issued = False;  RD_BOOL g_licence_issued = False;
31    
32  /* Generate a session key and RC4 keys, given client and server randoms */  /* Generate a session key and RC4 keys, given client and server randoms */
33  static void  static void
34  licence_generate_keys(uint8 * client_key, uint8 * server_key, uint8 * client_rsa)  licence_generate_keys(uint8 * client_random, uint8 * server_random, uint8 * pre_master_secret)
35  {  {
36          uint8 session_key[48];          uint8 master_secret[48];
37          uint8 temp_hash[48];          uint8 key_block[48];
38    
39          /* Generate session key - two rounds of sec_hash_48 */          /* Generate master secret and then key material */
40          sec_hash_48(temp_hash, client_rsa, client_key, server_key, 65);          sec_hash_48(master_secret, pre_master_secret, client_random, server_random, 'A');
41          sec_hash_48(session_key, temp_hash, server_key, client_key, 65);          sec_hash_48(key_block, master_secret, server_random, client_random, 'A');
42    
43          /* Store first 16 bytes of session key, for generating signatures */          /* Store first 16 bytes of session key as MAC secret */
44          memcpy(g_licence_sign_key, session_key, 16);          memcpy(g_licence_sign_key, key_block, 16);
45    
46          /* Generate RC4 key */          /* Generate RC4 key from next 16 bytes */
47          sec_hash_16(g_licence_key, &session_key[16], client_key, server_key);          sec_hash_16(g_licence_key, &key_block[16], client_random, server_random);
48  }  }
49    
50  static void  static void
51  licence_generate_hwid(uint8 * hwid)  licence_generate_hwid(uint8 * hwid)
52  {  {
53          buf_out_uint32(hwid, 2);          buf_out_uint32(hwid, 2);
54          strncpy((char *) (hwid + 4), hostname, LICENCE_HWID_SIZE - 4);          strncpy((char *) (hwid + 4), g_hostname, LICENCE_HWID_SIZE - 4);
55  }  }
56    
57  /* Present an existing licence to the server */  /* Present an existing licence to the server */
# Line 174  licence_process_demand(STREAM s) Line 169  licence_process_demand(STREAM s)
169                  return;                  return;
170          }          }
171    
172          licence_send_request(null_data, null_data, g_username, hostname);          licence_send_request(null_data, null_data, g_username, g_hostname);
173  }  }
174    
175  /* Send an authentication response packet */  /* Send an authentication response packet */
# Line 206  licence_send_authresp(uint8 * token, uin Line 201  licence_send_authresp(uint8 * token, uin
201  }  }
202    
203  /* Parse an authentication request packet */  /* Parse an authentication request packet */
204  static BOOL  static RD_BOOL
205  licence_parse_authreq(STREAM s, uint8 ** token, uint8 ** signature)  licence_parse_authreq(STREAM s, uint8 ** token, uint8 ** signature)
206  {  {
207          uint16 tokenlen;          uint16 tokenlen;
# Line 230  licence_parse_authreq(STREAM s, uint8 ** Line 225  licence_parse_authreq(STREAM s, uint8 **
225  static void  static void
226  licence_process_authreq(STREAM s)  licence_process_authreq(STREAM s)
227  {  {
228          uint8 *in_token, *in_sig;          uint8 *in_token = NULL, *in_sig;
229          uint8 out_token[LICENCE_TOKEN_SIZE], decrypt_token[LICENCE_TOKEN_SIZE];          uint8 out_token[LICENCE_TOKEN_SIZE], decrypt_token[LICENCE_TOKEN_SIZE];
230          uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE];          uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE];
231          uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];          uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];

Legend:
Removed from v.437  
changed lines
  Added in v.1372

  ViewVC Help
Powered by ViewVC 1.1.26