/[rdesktop]/sourceforge.net/trunk/rdesktop/secure.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/secure.c

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

revision 24 by matty, Sat Jan 6 03:12:10 2001 UTC revision 61 by matthewc, Sun Jul 14 12:06:03 2002 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - RDP encryption and licensing     Protocol services - RDP encryption and licensing
4     Copyright (C) Matthew Chapman 1999-2000     Copyright (C) Matthew Chapman 1999-2001
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
# Line 19  Line 19 
19  */  */
20    
21  #include "rdesktop.h"  #include "rdesktop.h"
22    
23    #ifdef WITH_OPENSSL
24    #include <openssl/rc4.h>
25    #include <openssl/md5.h>
26    #include <openssl/sha.h>
27    #include <openssl/bn.h>
28    #else
29  #include "crypto/rc4.h"  #include "crypto/rc4.h"
30  #include "crypto/md5.h"  #include "crypto/md5.h"
31  #include "crypto/sha.h"  #include "crypto/sha.h"
32  #include "crypto/arith.h"  #include "crypto/bn.h"
33    #endif
34    
35  extern char hostname[16];  extern char hostname[16];
36  extern int width;  extern int width;
37  extern int height;  extern int height;
38  extern int keylayout;  extern int keylayout;
39    extern BOOL encryption;
40    extern BOOL licence_issued;
41    
42  static int rc4_key_len;  static int rc4_key_len;
43  static RC4_KEY rc4_decrypt_key;  static RC4_KEY rc4_decrypt_key;
44  static RC4_KEY rc4_encrypt_key;  static RC4_KEY rc4_encrypt_key;
45    
46  static uint8 sec_sign_key[8];  static uint8 sec_sign_key[16];
47  static uint8 sec_decrypt_key[16];  static uint8 sec_decrypt_key[16];
48  static uint8 sec_encrypt_key[16];  static uint8 sec_encrypt_key[16];
49  static uint8 sec_decrypt_update_key[8];  static uint8 sec_decrypt_update_key[16];
50  static uint8 sec_encrypt_update_key[8];  static uint8 sec_encrypt_update_key[16];
51  static uint8 sec_crypted_random[64];  static uint8 sec_crypted_random[SEC_MODULUS_SIZE];
52    
53  /*  /*
54   * General purpose 48-byte transformation, using two 32-byte salts (generally,   * General purpose 48-byte transformation, using two 32-byte salts (generally,
55   * a client and server salt) and a global salt value used for padding.   * a client and server salt) and a global salt value used for padding.
56   * Both SHA1 and MD5 algorithms are used.   * Both SHA1 and MD5 algorithms are used.
57   */   */
58  void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2,  void
59                   uint8 salt)  sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt)
60  {  {
61          uint8 shasig[20];          uint8 shasig[20];
62          uint8 pad[4];          uint8 pad[4];
# Line 76  void sec_hash_48(uint8 *out, uint8 *in, Line 86  void sec_hash_48(uint8 *out, uint8 *in,
86   * Weaker 16-byte transformation, also using two 32-byte salts, but   * Weaker 16-byte transformation, also using two 32-byte salts, but
87   * only using a single round of MD5.   * only using a single round of MD5.
88   */   */
89  void sec_hash_16(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2)  void
90    sec_hash_16(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2)
91  {  {
92          MD5_CTX md5;          MD5_CTX md5;
93    
# Line 88  void sec_hash_16(uint8 *out, uint8 *in, Line 99  void sec_hash_16(uint8 *out, uint8 *in,
99  }  }
100    
101  /* Reduce key entropy from 64 to 40 bits */  /* Reduce key entropy from 64 to 40 bits */
102  static void sec_make_40bit(uint8 *key)  static void
103    sec_make_40bit(uint8 *key)
104  {  {
105          key[0] = 0xd1;          key[0] = 0xd1;
106          key[1] = 0x26;          key[1] = 0x26;
# Line 96  static void sec_make_40bit(uint8 *key) Line 108  static void sec_make_40bit(uint8 *key)
108  }  }
109    
110  /* Generate a session key and RC4 keys, given client and server randoms */  /* Generate a session key and RC4 keys, given client and server randoms */
111  static void sec_generate_keys(uint8 *client_key, uint8 *server_key,  static void
112                                int rc4_key_size)  sec_generate_keys(uint8 *client_key, uint8 *server_key, int rc4_key_size)
113  {  {
114          uint8 session_key[48];          uint8 session_key[48];
115          uint8 temp_hash[48];          uint8 temp_hash[48];
# Line 111  static void sec_generate_keys(uint8 *cli Line 123  static void sec_generate_keys(uint8 *cli
123          sec_hash_48(temp_hash, input, client_key, server_key, 65);          sec_hash_48(temp_hash, input, client_key, server_key, 65);
124          sec_hash_48(session_key, temp_hash, client_key, server_key, 88);          sec_hash_48(session_key, temp_hash, client_key, server_key, 88);
125    
126          /* Store first 8 bytes of session key, for generating signatures */          /* Store first 16 bytes of session key, for generating signatures */
127          memcpy(sec_sign_key, session_key, 8);          memcpy(sec_sign_key, session_key, 16);
128    
129          /* Generate RC4 keys */          /* Generate RC4 keys */
130          sec_hash_16(sec_decrypt_key, &session_key[16], client_key,          sec_hash_16(sec_decrypt_key, &session_key[16], client_key,
# Line 122  static void sec_generate_keys(uint8 *cli Line 134  static void sec_generate_keys(uint8 *cli
134    
135          if (rc4_key_size == 1)          if (rc4_key_size == 1)
136          {          {
137                  DEBUG("40-bit encryption enabled\n");                  DEBUG(("40-bit encryption enabled\n"));
138                  sec_make_40bit(sec_sign_key);                  sec_make_40bit(sec_sign_key);
139                  sec_make_40bit(sec_decrypt_key);                  sec_make_40bit(sec_decrypt_key);
140                  sec_make_40bit(sec_encrypt_key);                  sec_make_40bit(sec_encrypt_key);
# Line 130  static void sec_generate_keys(uint8 *cli Line 142  static void sec_generate_keys(uint8 *cli
142          }          }
143          else          else
144          {          {
145                  DEBUG("128-bit encryption enabled\n");                  DEBUG(("128-bit encryption enabled\n"));
146                  rc4_key_len = 16;                  rc4_key_len = 16;
147          }          }
148    
149          /* Store first 8 bytes of RC4 keys as update keys */          /* Save initial RC4 keys as update keys */
150          memcpy(sec_decrypt_update_key, sec_decrypt_key, 8);          memcpy(sec_decrypt_update_key, sec_decrypt_key, 16);
151          memcpy(sec_encrypt_update_key, sec_encrypt_key, 8);          memcpy(sec_encrypt_update_key, sec_encrypt_key, 16);
152    
153          /* Initialise RC4 state arrays */          /* Initialise RC4 state arrays */
154          RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key);          RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key);
# Line 145  static void sec_generate_keys(uint8 *cli Line 157  static void sec_generate_keys(uint8 *cli
157    
158  static uint8 pad_54[40] = {  static uint8 pad_54[40] = {
159          54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,          54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
160                  54, 54, 54,          54, 54, 54,
161          54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,          54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
162                  54, 54, 54          54, 54, 54
163  };  };
164    
165  static uint8 pad_92[48] = {  static uint8 pad_92[48] = {
166          92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,          92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
167                  92, 92, 92, 92, 92, 92, 92,          92, 92, 92, 92, 92, 92, 92,
168          92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,          92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
169                  92, 92, 92, 92, 92, 92, 92          92, 92, 92, 92, 92, 92, 92
170  };  };
171    
172  /* Output a uint32 into a buffer (little-endian) */  /* Output a uint32 into a buffer (little-endian) */
173  void buf_out_uint32(uint8 *buffer, uint32 value)  void
174    buf_out_uint32(uint8 *buffer, uint32 value)
175  {  {
176          buffer[0] = (value) & 0xff;          buffer[0] = (value) & 0xff;
177          buffer[1] = (value >> 8) & 0xff;          buffer[1] = (value >> 8) & 0xff;
# Line 167  void buf_out_uint32(uint8 *buffer, uint3 Line 180  void buf_out_uint32(uint8 *buffer, uint3
180  }  }
181    
182  /* Generate a signature hash, using a combination of SHA1 and MD5 */  /* Generate a signature hash, using a combination of SHA1 and MD5 */
183  void sec_sign(uint8 *signature, uint8 *session_key, int length,  void
184                uint8 *data, int datalen)  sec_sign(uint8 *signature, int siglen, uint8 *session_key, int keylen,
185             uint8 *data, int datalen)
186  {  {
187          uint8 shasig[20];          uint8 shasig[20];
188          uint8 md5sig[16];          uint8 md5sig[16];
# Line 179  void sec_sign(uint8 *signature, uint8 *s Line 193  void sec_sign(uint8 *signature, uint8 *s
193          buf_out_uint32(lenhdr, datalen);          buf_out_uint32(lenhdr, datalen);
194    
195          SHA1_Init(&sha);          SHA1_Init(&sha);
196          SHA1_Update(&sha, session_key, length);          SHA1_Update(&sha, session_key, keylen);
197          SHA1_Update(&sha, pad_54, 40);          SHA1_Update(&sha, pad_54, 40);
198          SHA1_Update(&sha, lenhdr, 4);          SHA1_Update(&sha, lenhdr, 4);
199          SHA1_Update(&sha, data, datalen);          SHA1_Update(&sha, data, datalen);
200          SHA1_Final(shasig, &sha);          SHA1_Final(shasig, &sha);
201    
202          MD5_Init(&md5);          MD5_Init(&md5);
203          MD5_Update(&md5, session_key, length);          MD5_Update(&md5, session_key, keylen);
204          MD5_Update(&md5, pad_92, 48);          MD5_Update(&md5, pad_92, 48);
205          MD5_Update(&md5, shasig, 20);          MD5_Update(&md5, shasig, 20);
206          MD5_Final(md5sig, &md5);          MD5_Final(md5sig, &md5);
207    
208          memcpy(signature, md5sig, length);          memcpy(signature, md5sig, siglen);
209  }  }
210    
211  /* Update an encryption key - similar to the signing process */  /* Update an encryption key - similar to the signing process */
212  static void sec_update(uint8 *key, uint8 *update_key)  static void
213    sec_update(uint8 *key, uint8 *update_key)
214  {  {
215          uint8 shasig[20];          uint8 shasig[20];
216          SHA_CTX sha;          SHA_CTX sha;
# Line 203  static void sec_update(uint8 *key, uint8 Line 218  static void sec_update(uint8 *key, uint8
218          RC4_KEY update;          RC4_KEY update;
219    
220          SHA1_Init(&sha);          SHA1_Init(&sha);
221          SHA1_Update(&sha, update_key, 8);          SHA1_Update(&sha, update_key, rc4_key_len);
222          SHA1_Update(&sha, pad_54, 40);          SHA1_Update(&sha, pad_54, 40);
223          SHA1_Update(&sha, key, 8);          SHA1_Update(&sha, key, rc4_key_len);
224          SHA1_Final(shasig, &sha);          SHA1_Final(shasig, &sha);
225    
226          MD5_Init(&md5);          MD5_Init(&md5);
227          MD5_Update(&md5, update_key, 8);          MD5_Update(&md5, update_key, rc4_key_len);
228          MD5_Update(&md5, pad_92, 48);          MD5_Update(&md5, pad_92, 48);
229          MD5_Update(&md5, shasig, 20);          MD5_Update(&md5, shasig, 20);
230          MD5_Final(key, &md5);          MD5_Final(key, &md5);
# Line 222  static void sec_update(uint8 *key, uint8 Line 237  static void sec_update(uint8 *key, uint8
237  }  }
238    
239  /* Encrypt data using RC4 */  /* Encrypt data using RC4 */
240  static void sec_encrypt(uint8 *data, int length)  static void
241    sec_encrypt(uint8 *data, int length)
242  {  {
243          static int use_count;          static int use_count;
244    
# Line 238  static void sec_encrypt(uint8 *data, int Line 254  static void sec_encrypt(uint8 *data, int
254  }  }
255    
256  /* Decrypt data using RC4 */  /* Decrypt data using RC4 */
257  static void sec_decrypt(uint8 *data, int length)  static void
258    sec_decrypt(uint8 *data, int length)
259  {  {
260          static int use_count;          static int use_count;
261    
# Line 253  static void sec_decrypt(uint8 *data, int Line 270  static void sec_decrypt(uint8 *data, int
270          use_count++;          use_count++;
271  }  }
272    
273  /* Read in a NUMBER from a buffer */  static void
274  static void sec_read_number(NUMBER * num, uint8 *buffer, int len)  reverse(uint8 *p, int len)
 {  
         INT *data = num->n_part;  
         int i, j;  
   
         for (i = 0, j = 0; j < len; i++, j += 2)  
                 data[i] = buffer[j] | (buffer[j + 1] << 8);  
   
         num->n_len = i;  
 }  
   
 /* Write a NUMBER to a buffer */  
 static void sec_write_number(NUMBER * num, uint8 *buffer, int len)  
275  {  {
         INT *data = num->n_part;  
276          int i, j;          int i, j;
277            uint8 temp;
278    
279          for (i = 0, j = 0; j < len; i++, j += 2)          for (i = 0, j = len-1; i < j; i++, j--)
280          {          {
281                  buffer[j] = data[i] & 0xff;                  temp = p[i];
282                  buffer[j + 1] = data[i] >> 8;                  p[i] = p[j];
283                    p[j] = temp;
284          }          }
285  }  }
286    
287  /* Perform an RSA public key encryption operation */  /* Perform an RSA public key encryption operation */
288  static void sec_rsa_encrypt(uint8 *out, uint8 *in, int len,  static void
289                              uint8 *modulus, uint8 *exponent)  sec_rsa_encrypt(uint8 *out, uint8 *in, int len,
290  {                  uint8 *modulus, uint8 *exponent)
291          NUMBER data, key;  {
292            BN_CTX ctx;
293          /* Set modulus for arithmetic */          BIGNUM mod, exp, x, y;
294          sec_read_number(&key, modulus, SEC_MODULUS_SIZE);          uint8 inr[SEC_MODULUS_SIZE];
295          m_init(&key, NULL);          int outlen;
296    
297          /* Exponentiate */          reverse(modulus, SEC_MODULUS_SIZE);
298          sec_read_number(&data, in, len);          reverse(exponent, SEC_EXPONENT_SIZE);
299          sec_read_number(&key, exponent, SEC_EXPONENT_SIZE);          memcpy(inr, in, len);
300          m_exp(&data, &key, &data);          reverse(inr, len);
301          sec_write_number(&data, out, SEC_MODULUS_SIZE);  
302            BN_CTX_init(&ctx);
303            BN_init(&mod);
304            BN_init(&exp);
305            BN_init(&x);
306            BN_init(&y);
307    
308            BN_bin2bn(modulus, SEC_MODULUS_SIZE, &mod);
309            BN_bin2bn(exponent, SEC_EXPONENT_SIZE, &exp);
310            BN_bin2bn(inr, len, &x);
311            BN_mod_exp(&y, &x, &exp, &mod, &ctx);
312            outlen = BN_bn2bin(&y, out);
313            reverse(out, outlen);
314            if (outlen < SEC_MODULUS_SIZE)
315                    memset(out+outlen, 0, SEC_MODULUS_SIZE-outlen);
316    
317            BN_free(&y);
318            BN_clear_free(&x);
319            BN_free(&exp);
320            BN_free(&mod);
321            BN_CTX_free(&ctx);
322  }  }
323    
324  /* Initialise secure transport packet */  /* Initialise secure transport packet */
325  STREAM sec_init(uint32 flags, int maxlen)  STREAM
326    sec_init(uint32 flags, int maxlen)
327  {  {
328          int hdrlen;          int hdrlen;
329          STREAM s;          STREAM s;
330    
331          hdrlen = (flags & SEC_ENCRYPT) ? 12 : 4;          if (!licence_issued)
332                    hdrlen = (flags & SEC_ENCRYPT) ? 12 : 4;
333            else
334                    hdrlen = (flags & SEC_ENCRYPT) ? 12 : 0;
335          s = mcs_init(maxlen + hdrlen);          s = mcs_init(maxlen + hdrlen);
336          s_push_layer(s, sec_hdr, hdrlen);          s_push_layer(s, sec_hdr, hdrlen);
337    
# Line 309  STREAM sec_init(uint32 flags, int maxlen Line 339  STREAM sec_init(uint32 flags, int maxlen
339  }  }
340    
341  /* Transmit secure transport packet */  /* Transmit secure transport packet */
342  void sec_send(STREAM s, uint32 flags)  void
343    sec_send(STREAM s, uint32 flags)
344  {  {
345          int datalen;          int datalen;
346    
347          s_pop_layer(s, sec_hdr);          s_pop_layer(s, sec_hdr);
348          out_uint32_le(s, flags);          if (!licence_issued || (flags & SEC_ENCRYPT))
349                    out_uint32_le(s, flags);
350    
351          if (flags & SEC_ENCRYPT)          if (flags & SEC_ENCRYPT)
352          {          {
353                  flags &= ~SEC_ENCRYPT;                  flags &= ~SEC_ENCRYPT;
354                  datalen = s->end - s->p - 8;                  datalen = s->end - s->p - 8;
355    
356  #if RDP_DEBUG  #if WITH_DEBUG
357                  DEBUG("Sending encrypted packet:\n");                  DEBUG(("Sending encrypted packet:\n"));
358                  hexdump(s->p + 8, datalen);                  hexdump(s->p + 8, datalen);
359  #endif  #endif
360    
361                  sec_sign(s->p, sec_sign_key, 8, s->p + 8, datalen);                  sec_sign(s->p, 8, sec_sign_key, rc4_key_len, s->p + 8, datalen);
362                  sec_encrypt(s->p + 8, datalen);                  sec_encrypt(s->p + 8, datalen);
363          }          }
364    
# Line 334  void sec_send(STREAM s, uint32 flags) Line 366  void sec_send(STREAM s, uint32 flags)
366  }  }
367    
368  /* Transfer the client random to the server */  /* Transfer the client random to the server */
369  static void sec_establish_key()  static void
370    sec_establish_key()
371  {  {
372          uint32 length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE;          uint32 length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE;
373          uint32 flags = SEC_CLIENT_RANDOM;          uint32 flags = SEC_CLIENT_RANDOM;
# Line 351  static void sec_establish_key() Line 384  static void sec_establish_key()
384  }  }
385    
386  /* Output connect initial data blob */  /* Output connect initial data blob */
387  static void sec_out_mcs_data(STREAM s)  static void
388    sec_out_mcs_data(STREAM s)
389  {  {
390          int hostlen = 2 * strlen(hostname);          int hostlen = 2 * strlen(hostname);
391    
# Line 398  static void sec_out_mcs_data(STREAM s) Line 432  static void sec_out_mcs_data(STREAM s)
432          /* Client encryption settings */          /* Client encryption settings */
433          out_uint16_le(s, SEC_TAG_CLI_CRYPT);          out_uint16_le(s, SEC_TAG_CLI_CRYPT);
434          out_uint16(s, 8);       /* length */          out_uint16(s, 8);       /* length */
435          out_uint32_le(s, 1);    /* encryption enabled */          out_uint32_le(s, encryption ? 0x3 : 0); /* encryption supported, 128-bit supported */
436          s_mark_end(s);          s_mark_end(s);
437  }  }
438    
439  /* Parse a public key structure */  /* Parse a public key structure */
440  static BOOL sec_parse_public_key(STREAM s, uint8 **modulus, uint8 **exponent)  static BOOL
441    sec_parse_public_key(STREAM s, uint8 **modulus, uint8 **exponent)
442  {  {
443          uint32 magic, modulus_len;          uint32 magic, modulus_len;
444    
445          in_uint32_le(s, magic);          in_uint32_le(s, magic);
446          if (magic != SEC_RSA_MAGIC)          if (magic != SEC_RSA_MAGIC)
447          {          {
448                  ERROR("RSA magic 0x%x\n", magic);                  error("RSA magic 0x%x\n", magic);
449                  return False;                  return False;
450          }          }
451    
452          in_uint32_le(s, modulus_len);          in_uint32_le(s, modulus_len);
453          if (modulus_len != SEC_MODULUS_SIZE + SEC_PADDING_SIZE)          if (modulus_len != SEC_MODULUS_SIZE + SEC_PADDING_SIZE)
454          {          {
455                  ERROR("modulus len 0x%x\n", modulus_len);                  error("modulus len 0x%x\n", modulus_len);
456                  return False;                  return False;
457          }          }
458    
# Line 430  static BOOL sec_parse_public_key(STREAM Line 465  static BOOL sec_parse_public_key(STREAM
465  }  }
466    
467  /* Parse a crypto information structure */  /* Parse a crypto information structure */
468  static BOOL sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size,  static BOOL
469                                   uint8 **server_random, uint8 **modulus,  sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size,
470                                   uint8 **exponent)                       uint8 **server_random, uint8 **modulus, uint8 **exponent)
471  {  {
472          uint32 crypt_level, random_len, rsa_info_len;          uint32 crypt_level, random_len, rsa_info_len;
473          uint16 tag, length;          uint16 tag, length;
# Line 445  static BOOL sec_parse_crypt_info(STREAM Line 480  static BOOL sec_parse_crypt_info(STREAM
480    
481          if (random_len != SEC_RANDOM_SIZE)          if (random_len != SEC_RANDOM_SIZE)
482          {          {
483                  ERROR("random len %d\n", random_len);                  error("random len %d\n", random_len);
484                  return False;                  return False;
485          }          }
486    
# Line 480  static BOOL sec_parse_crypt_info(STREAM Line 515  static BOOL sec_parse_crypt_info(STREAM
515                                  break;                                  break;
516    
517                          default:                          default:
518                                  NOTIMP("crypt tag 0x%x\n", tag);                                  unimpl("crypt tag 0x%x\n", tag);
519                  }                  }
520    
521                  s->p = next_tag;                  s->p = next_tag;
# Line 490  static BOOL sec_parse_crypt_info(STREAM Line 525  static BOOL sec_parse_crypt_info(STREAM
525  }  }
526    
527  /* Process crypto information blob */  /* Process crypto information blob */
528  static void sec_process_crypt_info(STREAM s)  static void
529    sec_process_crypt_info(STREAM s)
530  {  {
531          uint8 *server_random, *modulus, *exponent;          uint8 *server_random, *modulus, *exponent;
532          uint8 client_random[SEC_RANDOM_SIZE];          uint8 client_random[SEC_RANDOM_SIZE];
# Line 508  static void sec_process_crypt_info(STREA Line 544  static void sec_process_crypt_info(STREA
544  }  }
545    
546  /* Process connect response data blob */  /* Process connect response data blob */
547  static void sec_process_mcs_data(STREAM s)  static void
548    sec_process_mcs_data(STREAM s)
549  {  {
550          uint16 tag, length;          uint16 tag, length;
551          uint8 *next_tag;          uint8 *next_tag;
# Line 536  static void sec_process_mcs_data(STREAM Line 573  static void sec_process_mcs_data(STREAM
573                                  break;                                  break;
574    
575                          default:                          default:
576                                  NOTIMP("response tag 0x%x\n", tag);                                  unimpl("response tag 0x%x\n", tag);
577                  }                  }
578    
579                  s->p = next_tag;                  s->p = next_tag;
# Line 544  static void sec_process_mcs_data(STREAM Line 581  static void sec_process_mcs_data(STREAM
581  }  }
582    
583  /* Receive secure transport packet */  /* Receive secure transport packet */
584  STREAM sec_recv()  STREAM
585    sec_recv()
586  {  {
587          uint32 sec_flags;          uint32 sec_flags;
588          STREAM s;          STREAM s;
589    
590          while ((s = mcs_recv()) != NULL)          while ((s = mcs_recv()) != NULL)
591          {          {
592                  in_uint32_le(s, sec_flags);                  if (encryption || !licence_issued)
   
                 if (sec_flags & SEC_LICENCE_NEG)  
593                  {                  {
594                          licence_process(s);                          in_uint32_le(s, sec_flags);
                         continue;  
                 }  
595    
596                  if (sec_flags & SEC_ENCRYPT)                          if (sec_flags & SEC_LICENCE_NEG)
597                  {                          {
598                          in_uint8s(s, 8);        /* signature */                                  licence_process(s);
599                          sec_decrypt(s->p, s->end - s->p);                                  continue;
600                            }
601    
602                            if (sec_flags & SEC_ENCRYPT)
603                            {
604                                    in_uint8s(s, 8);        /* signature */
605                                    sec_decrypt(s->p, s->end - s->p);
606                            }
607                  }                  }
608    
609                  return s;                  return s;
# Line 572  STREAM sec_recv() Line 613  STREAM sec_recv()
613  }  }
614    
615  /* Establish a secure connection */  /* Establish a secure connection */
616  BOOL sec_connect(char *server)  BOOL
617    sec_connect(char *server)
618  {  {
619          struct stream mcs_data;          struct stream mcs_data;
620    
# Line 585  BOOL sec_connect(char *server) Line 627  BOOL sec_connect(char *server)
627                  return False;                  return False;
628    
629          sec_process_mcs_data(&mcs_data);          sec_process_mcs_data(&mcs_data);
630          sec_establish_key();          if (encryption)
631                    sec_establish_key();
632          return True;          return True;
633  }  }
634    
635  /* Disconnect a connection */  /* Disconnect a connection */
636  void sec_disconnect()  void
637    sec_disconnect()
638  {  {
639          mcs_disconnect();          mcs_disconnect();
640  }  }

Legend:
Removed from v.24  
changed lines
  Added in v.61

  ViewVC Help
Powered by ViewVC 1.1.26