00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "wizard/studio.h"
00042 #include "wizard/authenticate.h"
00043 #include "wizard/cipher.h"
00044 #include "wizard/entropy.h"
00045 #include "wizard/exception-private.h"
00046 #include "wizard/memory_.h"
00047 #include "wizard/mime.h"
00048 #include "wizard/mime-private.h"
00049 #include "wizard/option.h"
00050 #include "wizard/resource_.h"
00051 #include "wizard/string_.h"
00052 #include "wizard/token.h"
00053
00054
00055
00056
00057 static const OptionInfo
00058 AuthenticateOptions[] =
00059 {
00060 { "Undefined", (ssize_t) UndefinedAuthenticate },
00061 { "Public", (ssize_t) PublicAuthenticateMethod },
00062 { "Secret", (ssize_t) SecretAuthenticateMethod },
00063 { (char *) NULL, UndefinedAuthenticate }
00064 },
00065 CipherOptions[] =
00066 {
00067 { "Undefined", (ssize_t) UndefinedCipher },
00068 { "AES", (ssize_t) AESCipher },
00069 { "None", (ssize_t) NoCipher },
00070 { "Serpent", (ssize_t) SerpentCipher },
00071 { "Twofish", (ssize_t) TwofishCipher },
00072 { (char *) NULL, UndefinedCipher }
00073 },
00074 CommandOptions[] =
00075 {
00076 { "+authenticate", 1L },
00077 { "-authenticate", 1L },
00078 { "+chunksize", 1L },
00079 { "-chunksize", 1L },
00080 { "+decipher", 0L },
00081 { "-decipher", 0L },
00082 { "+debug", 1L },
00083 { "-debug", 1L },
00084 { "+entropy", 1L },
00085 { "-entropy", 1L },
00086 { "+hash", 1L },
00087 { "-hash", 1L },
00088 { "+help", 0L },
00089 { "-help", 0L },
00090 { "+key", 1L },
00091 { "-key", 1L },
00092 { "+key-length", 1L },
00093 { "-key-length", 1L },
00094 { "+mac", 1L },
00095 { "-mac", 1L },
00096 { "+level", 1L },
00097 { "-level", 1L },
00098 { "+list", 1L },
00099 { "-list", 1L },
00100 { "+log", 1L },
00101 { "-log", 1L },
00102 { "+mode", 1L },
00103 { "-mode", 1L },
00104 { "+properties", 1L },
00105 { "-properties", 1L },
00106 { "+random", 1L },
00107 { "-random", 1L },
00108 { "+verbose", 0L },
00109 { "-verbose", 0L },
00110 { "+version", 1L },
00111 { "-version", 1L },
00112 { (char *) NULL, 0L }
00113 },
00114 DataTypeOptions[] =
00115 {
00116 { "Undefined", (ssize_t) UndefinedData },
00117 { "Byte", (ssize_t) ByteData },
00118 { "Long", (ssize_t) LongData },
00119 { "Short", (ssize_t) ShortData },
00120 { "String", (ssize_t) StringData },
00121 { (char *) NULL, (ssize_t) UndefinedData }
00122 },
00123 EndianOptions[] =
00124 {
00125 { "Undefined", (ssize_t) UndefinedEndian },
00126 { "LSB", (ssize_t) LSBEndian },
00127 { "MSB", (ssize_t) MSBEndian },
00128 { (char *) NULL, (ssize_t) UndefinedEndian }
00129 },
00130 EntropyLevelOptions[] =
00131 {
00132 { "0", 0L },
00133 { "1", 1L },
00134 { "2", 2L },
00135 { "3", 3L },
00136 { "4", 4L },
00137 { "5", 5L },
00138 { "6", 6L },
00139 { "7", 7L },
00140 { "8", 8L },
00141 { "9", 9L },
00142 { (char *) NULL, 0L }
00143 },
00144 EntropyOptions[] =
00145 {
00146 { "Undefined", (ssize_t) UndefinedEntropy },
00147 { "None", (ssize_t) NoEntropy },
00148 { "BZip", (ssize_t) BZIPEntropy },
00149 { "Zip", (ssize_t) ZIPEntropy },
00150 { (char *) NULL, UndefinedEntropy }
00151 },
00152 KeyLengthOptions[] =
00153 {
00154 { "256", 256L },
00155 { "512", 512L },
00156 { "1024", 1024L },
00157 { "2048", 2048L },
00158 { (char *) NULL, 0L }
00159 },
00160 HashOptions[] =
00161 {
00162 { "Undefined", (ssize_t) UndefinedHash },
00163 { "CRC64", (ssize_t) CRC64Hash },
00164 { "MD5", (ssize_t) MD5Hash },
00165 { "None", (ssize_t) NoHash },
00166 { "SHA1", (ssize_t) SHA1Hash },
00167 { "SHA224", (ssize_t) SHA224Hash },
00168 { "SHA256", (ssize_t) SHA256Hash },
00169 { "SHA384", (ssize_t) SHA384Hash },
00170 { "SHA512", (ssize_t) SHA512Hash },
00171 { (char *) NULL, UndefinedHash }
00172 },
00173 ListOptions[] =
00174 {
00175 { "Authenticate", (ssize_t) WizardAuthenticateOptions },
00176 { "Cipher", (ssize_t) WizardCipherOptions },
00177 { "Command", (ssize_t) WizardCommandOptions },
00178 { "DataType", (ssize_t) WizardDataTypeOptions },
00179 { "Debug", (ssize_t) WizardDebugOptions },
00180 { "Endian", (ssize_t) WizardEndianOptions },
00181 { "Entropy", (ssize_t) WizardEntropyOptions },
00182 { "EntropyLevel", (ssize_t) WizardEntropyLevelOptions },
00183 { "Hash", (ssize_t) WizardHashOptions },
00184 { "KeyLength", (ssize_t) WizardKeyLengthOptions },
00185 { "List", (ssize_t) WizardListOptions },
00186 { "Mode", (ssize_t) WizardModeOptions },
00187 { (char *) NULL, (ssize_t) WizardUndefinedOptions }
00188 },
00189 LogWizardEventOptions[] =
00190 {
00191 { "All", (ssize_t) (AllEvents &~ TraceEvent) },
00192 { "Blob", (ssize_t) BlobEvent },
00193 { "Deprecate", (ssize_t) DeprecateEvent },
00194 { "Configure", (ssize_t) ConfigureEvent },
00195 { "Exception", (ssize_t) ExceptionEvent },
00196 { "Locale", (ssize_t) LocaleEvent },
00197 { "None", (ssize_t) NoEvents },
00198 { "Resource", (ssize_t) ResourceEvent },
00199 { "Trace", (ssize_t) TraceEvent },
00200 { "User", (ssize_t) UserEvent },
00201 { "Warning", (ssize_t) WarningEvent },
00202 { (char *) NULL, UndefinedEvents }
00203 },
00204 ModeOptions[] =
00205 {
00206 { "Undefined", (ssize_t) UndefinedMode },
00207 { "CBC", (ssize_t) CBCMode },
00208 { "CFB", (ssize_t) CFBMode },
00209 { "CTR", (ssize_t) CTRMode },
00210 { "ECB", (ssize_t) ECBMode },
00211 { "OFB", (ssize_t) OFBMode },
00212 { (char *) NULL, UndefinedMode }
00213 },
00214 ResourceOptions[] =
00215 {
00216 { "Undefined", (ssize_t) UndefinedResource },
00217 { "Area", (ssize_t) AreaResource },
00218 { "Disk", (ssize_t) DiskResource },
00219 { "File", (ssize_t) FileResource },
00220 { "Map", (ssize_t) MapResource },
00221 { "Memory", (ssize_t) MemoryResource },
00222 { (char *) NULL, (ssize_t) UndefinedResource }
00223 };
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 static const OptionInfo *GetOptionInfo(const WizardOption option)
00249 {
00250 switch (option)
00251 {
00252 case WizardAuthenticateOptions: return(AuthenticateOptions);
00253 case WizardCipherOptions: return(CipherOptions);
00254 case WizardCommandOptions: return(CommandOptions);
00255 case WizardDataTypeOptions: return(DataTypeOptions);
00256 case WizardDebugOptions: return(LogWizardEventOptions);
00257 case WizardEndianOptions: return(EndianOptions);
00258 case WizardEntropyOptions: return(EntropyOptions);
00259 case WizardEntropyLevelOptions: return(EntropyLevelOptions);
00260 case WizardKeyLengthOptions: return(KeyLengthOptions);
00261 case WizardHashOptions: return(HashOptions);
00262 case WizardListOptions: return(ListOptions);
00263 case WizardLogEventOptions: return(LogWizardEventOptions);
00264 case WizardModeOptions: return(ModeOptions);
00265 case WizardResourceOptions: return(ResourceOptions);
00266 default: break;
00267 }
00268 return((const OptionInfo *) NULL);
00269 }
00270
00271 WizardExport char **GetWizardOptions(const WizardOption option)
00272 {
00273 char
00274 **options;
00275
00276 const OptionInfo
00277 *option_info;
00278
00279 register ssize_t
00280 i;
00281
00282 option_info=GetOptionInfo(option);
00283 if (option_info == (const OptionInfo *) NULL)
00284 return((char **) NULL);
00285 for (i=0; option_info[i].mnemonic != (const char *) NULL; i++) ;
00286 options=(char **) AcquireQuantumMemory((size_t) i+1UL,sizeof(*options));
00287 if (options == (char **) NULL)
00288 ThrowFatalException(ResourceFatalError,"unable to acquire string `%s'");
00289 for (i=0; option_info[i].mnemonic != (const char *) NULL; i++)
00290 options[i]=AcquireString(option_info[i].mnemonic);
00291 options[i]=(char *) NULL;
00292 return(options);
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 WizardExport WizardBooleanType IsWizardOption(const char *option)
00319 {
00320 assert(option != (const char *) NULL);
00321 if ((*option != '-') && (*option != '+'))
00322 return(WizardFalse);
00323 if (strlen(option) == 1)
00324 return(WizardFalse);
00325 option++;
00326 if (isalpha((int) ((unsigned char) *option)) == 0)
00327 return(WizardFalse);
00328 return(WizardTrue);
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 WizardExport WizardBooleanType ListWizardOptions(FILE *file,
00359 const WizardOption option,ExceptionInfo *wizard_unused(exception))
00360 {
00361 const OptionInfo
00362 *option_info;
00363
00364 register ssize_t
00365 i;
00366
00367 if (file == (FILE *) NULL)
00368 file=stdout;
00369 option_info=GetOptionInfo(option);
00370 if (option_info == (const OptionInfo *) NULL)
00371 return(WizardFalse);
00372 for (i=0; option_info[i].mnemonic != (char *) NULL; i++)
00373 {
00374 if ((i == 0) && (strcmp(option_info[i].mnemonic,"Undefined") == 0))
00375 continue;
00376 (void) fprintf(file,"%s\n",option_info[i].mnemonic);
00377 }
00378 return(WizardTrue);
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 WizardExport ssize_t ParseWizardOption(const WizardOption option,
00411 const WizardBooleanType list,const char *options)
00412 {
00413 char
00414 token[MaxTextExtent];
00415
00416 const OptionInfo
00417 *option_info;
00418
00419 ssize_t
00420 option_types;
00421
00422 register char
00423 *q;
00424
00425 register const char
00426 *p;
00427
00428 register ssize_t
00429 i;
00430
00431 WizardBooleanType
00432 negate;
00433
00434 option_info=GetOptionInfo(option);
00435 if (option_info == (const OptionInfo *) NULL)
00436 return(-1);
00437 option_types=0;
00438 for (p=options; p != (char *) NULL; p=strchr(p,','))
00439 {
00440 while (((isspace((int) ((unsigned char) *p)) != 0) || (*p == ',')) &&
00441 (*p != '\0'))
00442 p++;
00443 if ((*p == '-') || (*p == '+'))
00444 p++;
00445 negate=(*p == '!') ? WizardTrue : WizardFalse;
00446 if (negate != WizardFalse)
00447 p++;
00448 q=token;
00449 while (((isspace((int) ((unsigned char) *p)) == 0) && (*p != ',')) &&
00450 (*p != '\0'))
00451 {
00452 if ((q-token) >= MaxTextExtent)
00453 break;
00454 *q++=(*p++);
00455 }
00456 *q='\0';
00457 for (i=0; option_info[i].mnemonic != (char *) NULL; i++)
00458 {
00459 if (LocaleCompare(token,option_info[i].mnemonic) == 0)
00460 {
00461 if (*token == '!')
00462 option_types=option_types &~ option_info[i].type;
00463 else
00464 option_types=option_types | option_info[i].type;
00465 break;
00466 }
00467 }
00468 if ((option_info[i].mnemonic == (char *) NULL) &&
00469 ((strchr(token+1,'-') != (char *) NULL) ||
00470 (strchr(token+1,'_') != (char *) NULL)))
00471 {
00472 while ((q=strchr(token+1,'-')) != (char *) NULL)
00473 (void) CopyWizardString(q,q+1,MaxTextExtent-strlen(q));
00474 while ((q=strchr(token+1,'_')) != (char *) NULL)
00475 (void) CopyWizardString(q,q+1,MaxTextExtent-strlen(q));
00476 for (i=0; option_info[i].mnemonic != (char *) NULL; i++)
00477 if (LocaleCompare(token,option_info[i].mnemonic) == 0)
00478 {
00479 if (*token == '!')
00480 option_types=option_types &~ option_info[i].type;
00481 else
00482 option_types=option_types | option_info[i].type;
00483 break;
00484 }
00485 }
00486 if (option_info[i].mnemonic == (char *) NULL)
00487 return(-1);
00488 if (list == WizardFalse)
00489 break;
00490 }
00491 return(option_types);
00492 }
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 WizardExport const char *WizardOptionToMnemonic(const WizardOption option,
00520 const ssize_t type)
00521 {
00522 const OptionInfo
00523 *option_info;
00524
00525 register ssize_t
00526 i;
00527
00528 option_info=GetOptionInfo(option);
00529 if (option_info == (const OptionInfo *) NULL)
00530 return((const char *) NULL);
00531 for (i=0; option_info[i].mnemonic != (const char *) NULL; i++)
00532 if (type == option_info[i].type)
00533 break;
00534 if (option_info[i].mnemonic == (const char *) NULL)
00535 return("undefined");
00536 return(option_info[i].mnemonic);
00537 }