/[rdesktop]/jpeg/rdesktop/trunk/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 /jpeg/rdesktop/trunk/licence.c

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

revision 855 by stargo, Sun Mar 13 13:18:48 2005 UTC revision 1374 by jsorg71, Tue Jan 9 07:24:44 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-2005     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"
22  #include <openssl/rc4.h>  #include "ssl.h"
23    
24  extern char g_username[64];  extern char g_username[64];
25  extern char g_hostname[16];  extern char g_hostname[16];
# Line 27  extern char g_hostname[16]; Line 27  extern char g_hostname[16];
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
# Line 143  licence_process_demand(STREAM s) Line 143  licence_process_demand(STREAM s)
143          uint8 hwid[LICENCE_HWID_SIZE];          uint8 hwid[LICENCE_HWID_SIZE];
144          uint8 *licence_data;          uint8 *licence_data;
145          int licence_size;          int licence_size;
146          RC4_KEY crypt_key;          SSL_RC4 crypt_key;
147    
148          /* Retrieve the server random from the incoming packet */          /* Retrieve the server random from the incoming packet */
149          in_uint8p(s, server_random, SEC_RANDOM_SIZE);          in_uint8p(s, server_random, SEC_RANDOM_SIZE);
# Line 161  licence_process_demand(STREAM s) Line 161  licence_process_demand(STREAM s)
161                  sec_sign(signature, 16, g_licence_sign_key, 16, hwid, sizeof(hwid));                  sec_sign(signature, 16, g_licence_sign_key, 16, hwid, sizeof(hwid));
162    
163                  /* Now encrypt the HWID */                  /* Now encrypt the HWID */
164                  RC4_set_key(&crypt_key, 16, g_licence_key);                  ssl_rc4_set_key(&crypt_key, g_licence_key, 16);
165                  RC4(&crypt_key, sizeof(hwid), hwid, hwid);                  ssl_rc4_crypt(&crypt_key, hwid, hwid, sizeof(hwid));
166    
167                  licence_present(null_data, null_data, licence_data, licence_size, hwid, signature);                  licence_present(null_data, null_data, licence_data, licence_size, hwid, signature);
168                  xfree(licence_data);                  xfree(licence_data);
# Line 201  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 225  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];
232          uint8 out_sig[LICENCE_SIGNATURE_SIZE];          uint8 out_sig[LICENCE_SIGNATURE_SIZE];
233          RC4_KEY crypt_key;          SSL_RC4 crypt_key;
234    
235          /* Parse incoming packet and save the encrypted token */          /* Parse incoming packet and save the encrypted token */
236          licence_parse_authreq(s, &in_token, &in_sig);          licence_parse_authreq(s, &in_token, &in_sig);
237          memcpy(out_token, in_token, LICENCE_TOKEN_SIZE);          memcpy(out_token, in_token, LICENCE_TOKEN_SIZE);
238    
239          /* Decrypt the token. It should read TEST in Unicode. */          /* Decrypt the token. It should read TEST in Unicode. */
240          RC4_set_key(&crypt_key, 16, g_licence_key);          ssl_rc4_set_key(&crypt_key, g_licence_key, 16);
241          RC4(&crypt_key, LICENCE_TOKEN_SIZE, in_token, decrypt_token);          ssl_rc4_crypt(&crypt_key, in_token, decrypt_token, LICENCE_TOKEN_SIZE);
242    
243          /* Generate a signature for a buffer of token and HWID */          /* Generate a signature for a buffer of token and HWID */
244          licence_generate_hwid(hwid);          licence_generate_hwid(hwid);
# Line 247  licence_process_authreq(STREAM s) Line 247  licence_process_authreq(STREAM s)
247          sec_sign(out_sig, 16, g_licence_sign_key, 16, sealed_buffer, sizeof(sealed_buffer));          sec_sign(out_sig, 16, g_licence_sign_key, 16, sealed_buffer, sizeof(sealed_buffer));
248    
249          /* Now encrypt the HWID */          /* Now encrypt the HWID */
250          RC4_set_key(&crypt_key, 16, g_licence_key);          ssl_rc4_set_key(&crypt_key, g_licence_key, 16);
251          RC4(&crypt_key, LICENCE_HWID_SIZE, hwid, crypt_hwid);          ssl_rc4_crypt(&crypt_key, hwid, crypt_hwid, LICENCE_HWID_SIZE);
252    
253          licence_send_authresp(out_token, crypt_hwid, out_sig);          licence_send_authresp(out_token, crypt_hwid, out_sig);
254  }  }
# Line 257  licence_process_authreq(STREAM s) Line 257  licence_process_authreq(STREAM s)
257  static void  static void
258  licence_process_issue(STREAM s)  licence_process_issue(STREAM s)
259  {  {
260          RC4_KEY crypt_key;          SSL_RC4 crypt_key;
261          uint32 length;          uint32 length;
262          uint16 check;          uint16 check;
263          int i;          int i;
# Line 267  licence_process_issue(STREAM s) Line 267  licence_process_issue(STREAM s)
267          if (!s_check_rem(s, length))          if (!s_check_rem(s, length))
268                  return;                  return;
269    
270          RC4_set_key(&crypt_key, 16, g_licence_key);          ssl_rc4_set_key(&crypt_key, g_licence_key, 16);
271          RC4(&crypt_key, length, s->p, s->p);          ssl_rc4_crypt(&crypt_key, s->p, s->p, length);
272    
273          in_uint16(s, check);          in_uint16(s, check);
274          if (check != 0)          if (check != 0)

Legend:
Removed from v.855  
changed lines
  Added in v.1374

  ViewVC Help
Powered by ViewVC 1.1.26