/[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 357 by forsberg, Fri Mar 28 12:55:25 2003 UTC revision 380 by jsorg71, Fri May 30 21:44:06 2003 UTC
# Line 38  extern int width; Line 38  extern int width;
38  extern int height;  extern int height;
39  extern int keylayout;  extern int keylayout;
40  extern BOOL encryption;  extern BOOL encryption;
41  extern BOOL licence_issued;  extern BOOL g_licence_issued;
42  extern BOOL use_rdp5;  extern BOOL use_rdp5;
43  extern int server_bpp;  extern int server_bpp;
44    
# Line 330  sec_init(uint32 flags, int maxlen) Line 330  sec_init(uint32 flags, int maxlen)
330          int hdrlen;          int hdrlen;
331          STREAM s;          STREAM s;
332    
333          if (!licence_issued)          if (!g_licence_issued)
334                  hdrlen = (flags & SEC_ENCRYPT) ? 12 : 4;                  hdrlen = (flags & SEC_ENCRYPT) ? 12 : 4;
335          else          else
336                  hdrlen = (flags & SEC_ENCRYPT) ? 12 : 0;                  hdrlen = (flags & SEC_ENCRYPT) ? 12 : 0;
# Line 347  sec_send(STREAM s, uint32 flags) Line 347  sec_send(STREAM s, uint32 flags)
347          int datalen;          int datalen;
348    
349          s_pop_layer(s, sec_hdr);          s_pop_layer(s, sec_hdr);
350          if (!licence_issued || (flags & SEC_ENCRYPT))          if (!g_licence_issued || (flags & SEC_ENCRYPT))
351                  out_uint32_le(s, flags);                  out_uint32_le(s, flags);
352    
353          if (flags & SEC_ENCRYPT)          if (flags & SEC_ENCRYPT)
# Line 447  sec_out_mcs_data(STREAM s) Line 447  sec_out_mcs_data(STREAM s)
447                          out_uint16_le(s, 0xca04);                          out_uint16_le(s, 0xca04);
448                          break;                          break;
449          }          }
450          out_uint16(s, 1);          out_uint16_le(s, 1);
451    
452          out_uint32(s, 0);          out_uint32(s, 0);
453          out_uint8(s, server_bpp);          out_uint8(s, server_bpp);
# Line 459  sec_out_mcs_data(STREAM s) Line 459  sec_out_mcs_data(STREAM s)
459          out_uint16_le(s, SEC_TAG_CLI_4);          out_uint16_le(s, SEC_TAG_CLI_4);
460          out_uint16_le(s, 12);          out_uint16_le(s, 12);
461          out_uint32_le(s, 9);          out_uint32_le(s, 9);
462          out_uint32_le(s, 0);          out_uint32(s, 0);
463    
464          /* Client encryption settings */          /* Client encryption settings */
465          out_uint16_le(s, SEC_TAG_CLI_CRYPT);          out_uint16_le(s, SEC_TAG_CLI_CRYPT);
466          out_uint16_le(s, 12);   /* length */          out_uint16_le(s, 12);   /* length */
467          out_uint32_le(s, encryption ? 0x3 : 0); /* encryption supported, 128-bit supported */          out_uint32_le(s, encryption ? 0x3 : 0); /* encryption supported, 128-bit supported */
468          out_uint32_le(s, 0);    /* Unknown */          out_uint32(s, 0);       /* Unknown */
469    
470          out_uint16_le(s, SEC_TAG_CLI_CHANNELS);          out_uint16_le(s, SEC_TAG_CLI_CHANNELS);
471          out_uint16_le(s, 20);   /* length */          out_uint16_le(s, 20);   /* length */
# Line 538  sec_parse_crypt_info(STREAM s, uint32 * Line 538  sec_parse_crypt_info(STREAM s, uint32 *
538                       uint8 ** server_random, uint8 ** modulus, uint8 ** exponent)                       uint8 ** server_random, uint8 ** modulus, uint8 ** exponent)
539  {  {
540          uint32 crypt_level, random_len, rsa_info_len;          uint32 crypt_level, random_len, rsa_info_len;
541          uint32 cacert_len, cert_len;          uint32 cacert_len, cert_len, flags;
542          X509 *cacert, *server_cert;          X509 *cacert, *server_cert;
543          uint16 tag, length;          uint16 tag, length;
544          uint8 *next_tag, *end;          uint8 *next_tag, *end;
# Line 563  sec_parse_crypt_info(STREAM s, uint32 * Line 563  sec_parse_crypt_info(STREAM s, uint32 *
563          if (end > s->end)          if (end > s->end)
564                  return False;                  return False;
565    
566          if (!use_rdp5 || 1 == server_rdp_version)          in_uint32_le(s, flags); /* 1 = RDP4-style, 0x80000002 = X.509 */
567            if (flags & 1)
568          {          {
569                  DEBUG_RDP5(("We're going for the RDP4-style encryption\n"));                  DEBUG_RDP5(("We're going for the RDP4-style encryption\n"));
570                  in_uint8s(s, 12);       /* unknown */                  in_uint8s(s, 8);        /* unknown */
571    
572                  while (s->p < end)                  while (s->p < end)
573                  {                  {
# Line 598  sec_parse_crypt_info(STREAM s, uint32 * Line 599  sec_parse_crypt_info(STREAM s, uint32 *
599                          s->p = next_tag;                          s->p = next_tag;
600                  }                  }
601          }          }
602          else if (4 == server_rdp_version)          else
603          {          {
604                  DEBUG_RDP5(("We're going for the RDP5-style encryption\n"));                  DEBUG_RDP5(("We're going for the RDP5-style encryption\n"));
605                  in_uint8s(s, 8);        /* Unknown */                  in_uint8s(s, 4);        /* Number of certificates */
606    
607                  /* Do da funky X.509 stuffy                  /* Do da funky X.509 stuffy
608    
# Line 653  sec_parse_crypt_info(STREAM s, uint32 * Line 654  sec_parse_crypt_info(STREAM s, uint32 *
654                  }                  }
655                  return True;    /* There's some garbage here we don't care about */                  return True;    /* There's some garbage here we don't care about */
656          }          }
         else  
         {  
                 error("Unknown Server RDP version %d", server_rdp_version);  
                 return False;  
         }  
657          return s_check_end(s);          return s_check_end(s);
658  }  }
659    
# Line 677  sec_process_crypt_info(STREAM s) Line 673  sec_process_crypt_info(STREAM s)
673          }          }
674    
675          DEBUG(("Generating client random\n"));          DEBUG(("Generating client random\n"));
         /* Generate a client random, and hence determine encryption keys */  
         generate_random(inr);  
676          // This is what the MS client do:          // This is what the MS client do:
677          //      memset(inr, 0, SEC_RANDOM_SIZE);          memset(inr, 0, SEC_RANDOM_SIZE);
678          // *ARIGL!*          /*  *ARIGL!* Plaintext attack, anyone?
679                I tried doing:
680                generate_random(inr);
681                ..but that generates connection errors now and then (yes,
682                "now and then". Something like 0 to 3 attempts needed before a
683                successful connection. Nice. Not!
684            */
685    
686          generate_random(client_random);          generate_random(client_random);
687          if (NULL != server_public_key)          if (NULL != server_public_key)
688          {                       /* Which means we should use          {                       /* Which means we should use
# Line 768  sec_recv(void) Line 769  sec_recv(void)
769    
770          while ((s = mcs_recv(&channel)) != NULL)          while ((s = mcs_recv(&channel)) != NULL)
771          {          {
772                  if (encryption || !licence_issued)                  if (encryption || !g_licence_issued)
773                  {                  {
774                          in_uint32_le(s, sec_flags);                          in_uint32_le(s, sec_flags);
775    
# Line 776  sec_recv(void) Line 777  sec_recv(void)
777                          {                          {
778                                  if (sec_flags & SEC_ENCRYPT) {                                  if (sec_flags & SEC_ENCRYPT) {
779                                          DEBUG_RDP5(("Encrypted license detected\n"));                                          DEBUG_RDP5(("Encrypted license detected\n"));
780                                  }                                  }
781                                  licence_process(s);                                  licence_process(s);
782                                  continue;                                  continue;
783                          }                          }
# Line 808  sec_connect(char *server, char *username Line 809  sec_connect(char *server, char *username
809    
810          /* We exchange some RDP data during the MCS-Connect */          /* We exchange some RDP data during the MCS-Connect */
811          mcs_data.size = 512;          mcs_data.size = 512;
812          mcs_data.p = mcs_data.data = xmalloc(mcs_data.size);          mcs_data.p = mcs_data.data = (uint8*)xmalloc(mcs_data.size);
813          sec_out_mcs_data(&mcs_data);          sec_out_mcs_data(&mcs_data);
814    
815          if (!mcs_connect(server, &mcs_data, username))          if (!mcs_connect(server, &mcs_data, username))

Legend:
Removed from v.357  
changed lines
  Added in v.380

  ViewVC Help
Powered by ViewVC 1.1.26