home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / Registration / Encoder.m < prev    next >
Encoding:
Text File  |  1992-12-19  |  4.2 KB  |  174 lines

  1. /*
  2.  * (C) 1992 Simson Garfinkel and Associates, Inc.
  3.  *
  4.  * NeXTSTEP developers may freely use and redistribute this software as long
  5.  * as credit is given to Simson Garfinkel and Associates.
  6.  *
  7.  * EXPORT RESTRICTIONS:
  8.  *
  9.  * You may not ship the source-code module des.c outside of the US or canada.
  10.  *
  11.  * You may ship a program which uses the des.o compiled module outside of the
  12.  * United States to any type T or type V country as long as you do not provide
  13.  * cryptographic services to the user in your program and you clearly
  14.  * declare "commodity control number 5D11A" on your export declaration.
  15.  *
  16.  * Type T countries include all countries in the Western Hemisphere except Cuba.
  17.  * Type V countries include all countries in the Eastern Hemisphere except
  18.  * the previous communist block countries and the People's Republic of China,
  19.  * Vietnam, Cambodia, and Laos.
  20.  *
  21.  * For further information, contact the Office of Export Control:
  22.  *
  23.  *    Bureau of Export Administration
  24.  *    P.O. Box 273
  25.  *    Washington, DC 20044
  26.  *    202-377-2694
  27.  */
  28.  
  29.  
  30.  
  31.  
  32. #import <netdb.h>
  33. #import <pwd.h>
  34. #import <appkit/appkit.h>
  35. #import <NXCType.h>
  36. #import "Encoder.h"
  37. #import "Registration.h"
  38.  
  39. static    int month(const char *m)
  40. {
  41.       if(!strcmp("January",m)) return 1;
  42.       if(!strcmp("February",m)) return 2;
  43.       if(!strcmp("March",m)) return 3;
  44.       if(!strcmp("April",m)) return 4;
  45.       if(!strcmp("May",m)) return 5;
  46.       if(!strcmp("June",m)) return 6;
  47.       if(!strcmp("July",m)) return 7;
  48.       if(!strcmp("August",m)) return 8;
  49.       if(!strcmp("September",m)) return 9;
  50.       if(!strcmp("October",m)) return 10;
  51.       if(!strcmp("November",m)) return 11;
  52.       if(!strcmp("December",m)) return 12;
  53.       return 0;
  54. }
  55.  
  56. char    *calc_license_string(struct licenseString *lsIn,
  57.                  const char *companyKey,
  58.                  char *buf)
  59. {
  60.     struct    licenseString ls = *lsIn;
  61.     unsigned char *cc = (unsigned char *)&ls;
  62.     int    i;
  63.     unsigned char counter;
  64.     char    key[9];
  65.     char     ks[16][8];
  66.  
  67.     buf[0]    = '\000';
  68.     
  69.     /* calculate the checksum */
  70.     counter     = 0;
  71.     ls.checksum    = 0;
  72.     for(i=0;i<sizeof(struct licenseString);i++){
  73.         counter += cc[i];
  74.     }
  75.     ls.checksum    = 256-counter;
  76.  
  77.     /* Now verify that it checksums to 0 */
  78.     counter        = 0;
  79.     for(i=0;i<sizeof(struct licenseString);i++){
  80.         counter += cc[i];
  81.     }
  82.     if(counter!=0){
  83.         NXRunAlertPanel(0,"Internal error in encryption",0,0,0);
  84.         return 0;
  85.     }
  86.  
  87.     asciiToKey(companyKey,key);
  88.     desinit(0);
  89.     dessetkey(ks,key);
  90.     endes(ks,cc);
  91.     endes(ks,cc+2);
  92.  
  93.     return binary_to_hex(&ls,sizeof(ls),buf);
  94. }
  95.  
  96. @implementation Encoder
  97.  
  98. - nextLicense:sender
  99. {
  100.     [accessionNumberCell    setIntValue:[accessionNumberCell intValue]+1];
  101.     [self    calcLicense:self];
  102.     return self;
  103. }
  104.  
  105. - calcLicense:sender
  106. {
  107.     BOOL    end = [endSwitch intValue];
  108.     BOOL    start = [startSwitch intValue];
  109.     char    buf[256];
  110.     struct    licenseString ls;
  111.  
  112.     [startYearCover    setEnabled:start];
  113.     [startMonthCover setEnabled:start];
  114.     [endYearCover     setEnabled:end];
  115.     [endMonthCover    setEnabled:end];
  116.     [simUsersCell    setEnabled:!strcmp([licenseTypeCover title],"Network")];
  117.     if(![simUsersCell isEnabled]){
  118.         [simUsersCell    setIntValue:1];
  119.     }
  120.  
  121.     memset(&ls,0,sizeof(ls));
  122.     ls.product    = [productCodeCell intValue];
  123.     ls.num[0]    = ([accessionNumberCell intValue] >> 16) & 0xff;
  124.     ls.num[1]    = ([accessionNumberCell intValue] >>  8) & 0xff;
  125.     ls.num[2]    = ([accessionNumberCell intValue] >>  0) & 0xff;
  126.     if(start){
  127.         ls.start= (month([startMonthCover title]) << 4) +
  128.                       (atoi([startYearCover title]) - 1992);
  129.         ls.flag |= REG_START;
  130.     }
  131.     if(end){
  132.         ls.end=    (month([endMonthCover title]) << 4) +
  133.                       (atoi([endYearCover title]) - 1992);
  134.         ls.flag |= REG_END;
  135.     }
  136.  
  137.     ls.maxMachines[0]    = ([simUsersCell intValue] >> 8) & 0xff;
  138.     ls.maxMachines[1]    = ([simUsersCell intValue] >> 0) & 0xff;
  139.     
  140.     if(!strcmp([licenseTypeCover title],"Single user")){
  141.         ls.flag |= REG_SINGLEUSER;
  142.     }
  143.  
  144.     if(!strcmp([licenseTypeCover title],"Demo")){
  145.         ls.flag |= REG_DEMO;
  146.     }
  147.  
  148.     if(!strcmp([companyKeyCell stringValue],"")){
  149.         [licenseStringCell setStringValue:"Specify company key"];
  150.         return self;
  151.     }
  152.  
  153.     [licenseStringCell setStringValue:
  154.      calc_license_string(&ls,[companyKeyCell stringValue],buf)];
  155.  
  156.     return     self;
  157. }
  158.  
  159.  
  160. - delayedCalcLicense:sender
  161. {
  162.     [self    perform:@selector(calcLicense:) with:nil afterDelay:(int)10
  163.                cancelPrevious:NO];
  164.     return self;
  165.  
  166. }
  167.  
  168.  
  169. @end
  170.  
  171. #import "RegSupport.m"
  172. #import "des.c"
  173.   
  174.