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
00042
00043 #include "wizard/studio.h"
00044 #include "wizard/authenticate.h"
00045 #include "wizard/exception.h"
00046 #include "wizard/exception-private.h"
00047 #include "wizard/memory_.h"
00048 #include "wizard/secret.h"
00049
00050
00051
00052
00053 #define SecretKeyLength 1024
00054
00055
00056
00057
00058 struct _AuthenticateInfo
00059 {
00060 AuthenticateMethod
00061 method;
00062
00063 void
00064 *handle;
00065
00066 time_t
00067 timestamp;
00068
00069 size_t
00070 signature;
00071 };
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 WizardExport AuthenticateInfo *AcquireAuthenticateInfo(
00101 const AuthenticateMethod method,const char *path,const HashType hash)
00102 {
00103 AuthenticateInfo
00104 *authenticate_info;
00105
00106 authenticate_info=(AuthenticateInfo *) AcquireWizardMemory(
00107 sizeof(*authenticate_info));
00108 if (authenticate_info == (AuthenticateInfo *) NULL)
00109 ThrowWizardFatalError(AuthenticateDomain,MemoryError);
00110 (void) ResetWizardMemory(authenticate_info,0,sizeof(*authenticate_info));
00111 authenticate_info->method=method;
00112 switch (method)
00113 {
00114 case SecretAuthenticateMethod:
00115 {
00116 authenticate_info->handle=(AuthenticateInfo *) AcquireSecretInfo(path,
00117 hash,SecretKeyLength);
00118 break;
00119 }
00120 default:
00121 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00122 }
00123 authenticate_info->timestamp=time((time_t *) NULL);
00124 authenticate_info->signature=WizardSignature;
00125 return(authenticate_info);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 WizardExport WizardBooleanType AuthenticateKey(
00154 AuthenticateInfo *authenticate_info,ExceptionInfo *exception)
00155 {
00156 WizardBooleanType
00157 status;
00158
00159 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00160 WizardAssert(AuthenticateDomain,
00161 authenticate_info != (AuthenticateInfo *) NULL);
00162 WizardAssert(AuthenticateDomain,
00163 authenticate_info->signature == WizardSignature);
00164 WizardAssert(AuthenticateDomain,
00165 authenticate_info->handle != (AuthenticateInfo *) NULL);
00166 status=WizardFalse;
00167 switch (authenticate_info->method)
00168 {
00169 case SecretAuthenticateMethod:
00170 {
00171 SecretInfo
00172 *secret_info;
00173
00174 secret_info=(SecretInfo *) authenticate_info->handle;
00175 status=AuthenticateSecretKey(secret_info,exception);
00176 break;
00177 }
00178 default:
00179 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00180 }
00181 return(status);
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 WizardExport AuthenticateInfo *DestroyAuthenticateInfo(
00209 AuthenticateInfo *authenticate_info)
00210 {
00211 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00212 WizardAssert(AuthenticateDomain,
00213 authenticate_info != (AuthenticateInfo *) NULL);
00214 WizardAssert(AuthenticateDomain,
00215 authenticate_info->signature == WizardSignature);
00216 if (authenticate_info->handle != (AuthenticateInfo *) NULL)
00217 switch (authenticate_info->method)
00218 {
00219 case SecretAuthenticateMethod:
00220 {
00221 authenticate_info->handle=DestroySecretInfo((SecretInfo *)
00222 authenticate_info->handle);
00223 break;
00224 }
00225 default:
00226 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00227 }
00228 authenticate_info->signature=(~WizardSignature);
00229 authenticate_info=(AuthenticateInfo *)
00230 RelinquishWizardMemory(authenticate_info);
00231 return(authenticate_info);
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 WizardExport WizardBooleanType GenerateAuthenticateKey(
00261 AuthenticateInfo *authenticate_info,ExceptionInfo *exception)
00262 {
00263 WizardBooleanType
00264 status;
00265
00266 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00267 WizardAssert(AuthenticateDomain,
00268 authenticate_info != (AuthenticateInfo *) NULL);
00269 WizardAssert(AuthenticateDomain,
00270 authenticate_info->signature == WizardSignature);
00271 WizardAssert(AuthenticateDomain,
00272 authenticate_info->handle != (AuthenticateInfo *) NULL);
00273 WizardAssert(AuthenticateDomain,exception != (ExceptionInfo *) NULL);
00274 status=WizardFalse;
00275 switch (authenticate_info->method)
00276 {
00277 case SecretAuthenticateMethod:
00278 {
00279 SecretInfo
00280 *secret_info;
00281
00282 secret_info=(SecretInfo *) authenticate_info->handle;
00283 status=GenerateSecretKey(secret_info,exception);
00284 if (status == WizardFalse)
00285 break;
00286 break;
00287 }
00288 default:
00289 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00290 }
00291 return(status);
00292 }
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 WizardExport const StringInfo *GetAuthenticateId(
00318 const AuthenticateInfo *authenticate_info)
00319 {
00320 const StringInfo
00321 *id;
00322
00323 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00324 WizardAssert(AuthenticateDomain,
00325 authenticate_info != (AuthenticateInfo *) NULL);
00326 WizardAssert(AuthenticateDomain,
00327 authenticate_info->signature == WizardSignature);
00328 switch (authenticate_info->method)
00329 {
00330 case SecretAuthenticateMethod:
00331 {
00332 SecretInfo
00333 *secret_info;
00334
00335 secret_info=(SecretInfo *) authenticate_info->handle;
00336 id=GetSecretId(secret_info);
00337 break;
00338 }
00339 default:
00340 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00341 }
00342 return(id);
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 WizardExport const StringInfo *GetAuthenticateKey(
00369 const AuthenticateInfo *authenticate_info)
00370 {
00371 const StringInfo
00372 *key;
00373
00374 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00375 WizardAssert(AuthenticateDomain,
00376 authenticate_info != (AuthenticateInfo *) NULL);
00377 WizardAssert(AuthenticateDomain,
00378 authenticate_info->signature == WizardSignature);
00379 switch (authenticate_info->method)
00380 {
00381 case SecretAuthenticateMethod:
00382 {
00383 SecretInfo
00384 *secret_info;
00385
00386 secret_info=(SecretInfo *) authenticate_info->handle;
00387 key=GetSecretKey(secret_info);
00388 break;
00389 }
00390 default:
00391 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00392 }
00393 return(key);
00394 }
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 WizardExport size_t GetAuthenticateKeyLength(
00420 const AuthenticateInfo *authenticate_info)
00421 {
00422 size_t
00423 key_length;
00424
00425 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00426 WizardAssert(AuthenticateDomain,
00427 authenticate_info != (AuthenticateInfo *) NULL);
00428 WizardAssert(AuthenticateDomain,
00429 authenticate_info->signature == WizardSignature);
00430 switch (authenticate_info->method)
00431 {
00432 case SecretAuthenticateMethod:
00433 {
00434 SecretInfo
00435 *secret_info;
00436
00437 secret_info=(SecretInfo *) authenticate_info->handle;
00438 key_length=GetSecretKeyLength(secret_info);
00439 break;
00440 }
00441 default:
00442 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00443 }
00444 return(key_length);
00445 }
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 WizardExport const char *GetAuthenticatePassphrase(
00471 const AuthenticateInfo *authenticate_info)
00472 {
00473 const char
00474 *passphrase;
00475
00476 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00477 WizardAssert(AuthenticateDomain,
00478 authenticate_info != (AuthenticateInfo *) NULL);
00479 WizardAssert(AuthenticateDomain,
00480 authenticate_info->signature == WizardSignature);
00481 switch (authenticate_info->method)
00482 {
00483 case SecretAuthenticateMethod:
00484 {
00485 SecretInfo
00486 *secret_info;
00487
00488 secret_info=(SecretInfo *) authenticate_info->handle;
00489 passphrase=GetSecretPassphrase(secret_info);
00490 break;
00491 }
00492 default:
00493 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00494 }
00495 return(passphrase);
00496 }
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 WizardExport void SetAuthenticateId(AuthenticateInfo *authenticate_info,
00524 const StringInfo *id)
00525 {
00526 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00527 WizardAssert(AuthenticateDomain,
00528 authenticate_info != (AuthenticateInfo *) NULL);
00529 WizardAssert(AuthenticateDomain,
00530 authenticate_info->signature == WizardSignature);
00531 WizardAssert(AuthenticateDomain,
00532 authenticate_info->handle != (AuthenticateInfo *) NULL);
00533 switch (authenticate_info->method)
00534 {
00535 case SecretAuthenticateMethod:
00536 {
00537 SecretInfo
00538 *secret_info;
00539
00540 secret_info=(SecretInfo *) authenticate_info->handle;
00541 SetSecretId(secret_info,id);
00542 break;
00543 }
00544 default:
00545 ThrowWizardFatalError(AuthenticateDomain,EnumerateError);
00546 }
00547 }
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574 WizardExport void SetAuthenticateKeyLength(AuthenticateInfo *authenticate_info,
00575 const size_t key_length)
00576 {
00577 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00578 WizardAssert(AuthenticateDomain,
00579 authenticate_info != (AuthenticateInfo *) NULL);
00580 WizardAssert(AuthenticateDomain,
00581 authenticate_info->signature == WizardSignature);
00582 WizardAssert(AuthenticateDomain,
00583 authenticate_info->handle != (AuthenticateInfo *) NULL);
00584 switch (authenticate_info->method)
00585 {
00586 case SecretAuthenticateMethod:
00587 {
00588 SecretInfo
00589 *secret_info;
00590
00591 secret_info=(SecretInfo *) authenticate_info->handle;
00592 SetSecretKeyLength(secret_info,key_length);
00593 break;
00594 }
00595 default:
00596 break;
00597 }
00598 }
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625 WizardExport void SetAuthenticatePassphrase(AuthenticateInfo *authenticate_info,
00626 const char *passphrase)
00627 {
00628 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00629 WizardAssert(AuthenticateDomain,
00630 authenticate_info != (AuthenticateInfo *) NULL);
00631 WizardAssert(AuthenticateDomain,
00632 authenticate_info->signature == WizardSignature);
00633 WizardAssert(AuthenticateDomain,
00634 authenticate_info->handle != (AuthenticateInfo *) NULL);
00635 switch (authenticate_info->method)
00636 {
00637 case SecretAuthenticateMethod:
00638 {
00639 SecretInfo
00640 *secret_info;
00641
00642 secret_info=(SecretInfo *) authenticate_info->handle;
00643 SetSecretPassphrase(secret_info,passphrase);
00644 break;
00645 }
00646 default:
00647 break;
00648 }
00649 }