|
WizardsToolkit
1.0.7
|
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % K K EEEEE Y Y RRRR IIIII N N GGGG % 00006 % K K E Y Y R R I NN N G % 00007 % KKK EEE Y RRRR I N N N G GGG % 00008 % K K E Y R R I N NN G G % 00009 % K K EEEEE Y R R IIIII N N GGGG % 00010 % % 00011 % % 00012 % Wizard's Toolkit Keyring Methods % 00013 % % 00014 % Software Design % 00015 % John Cristy % 00016 % March 2003 % 00017 % % 00018 % % 00019 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % 00020 % dedicated to making software imaging solutions freely available. % 00021 % % 00022 % You may not use this file except in compliance with the License. You may % 00023 % obtain a copy of the License at % 00024 % % 00025 % http://www.wizards-toolkit.org/script/license.php % 00026 % % 00027 % Unless required by applicable law or agreed to in writing, software % 00028 % distributed under the License is distributed on an "AS IS" BASIS, % 00029 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00030 % See the License for the specific language governing permissions and % 00031 % limitations under the License. % 00032 % % 00033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00034 % 00035 % 00036 % 00037 */ 00038 00039 /* 00040 Include declarations. 00041 */ 00042 #include "wizard/studio.h" 00043 #include "wizard/blob-private.h" 00044 #include "wizard/exception.h" 00045 #include "wizard/exception-private.h" 00046 #include "wizard/file.h" 00047 #include "wizard/keyring.h" 00048 #include "wizard/magick.h" 00049 #include "wizard/memory_.h" 00050 #include "wizard/utility.h" 00051 #include "wizard/xml-tree.h" 00052 00053 /* 00054 Define declarations. 00055 */ 00056 #define KeyringFilename "keyring.xdm" 00057 #define KeyringFiletype "keyring" 00058 #define KeyringProtocolMajorVersion 1 00059 #define KeyringProtocolMinorVersion 1 00060 00061 /* 00062 Typedef declarations. 00063 */ 00064 struct _KeyringInfo 00065 { 00066 char 00067 *path; 00068 00069 StringInfo 00070 *id, 00071 *key, 00072 *nonce; 00073 00074 unsigned short 00075 protocol_major, 00076 protocol_minor; 00077 00078 time_t 00079 timestamp; 00080 00081 size_t 00082 signature; 00083 }; 00084 00085 /* 00086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00087 % % 00088 % % 00089 % % 00090 % A c q u i r e K e y r i n g I n f o % 00091 % % 00092 % % 00093 % % 00094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00095 % 00096 % AcquireKeyringInfo() allocates the KeyringInfo structure. 00097 % 00098 % The format of the AcquireKeyringInfo method is: 00099 % 00100 % KeyringInfo *AcquireKeyringInfo(const char *path) 00101 % 00102 % A description of each parameter follows: 00103 % 00104 % o path: The keyring path. 00105 % 00106 */ 00107 WizardExport KeyringInfo *AcquireKeyringInfo(const char *path) 00108 { 00109 KeyringInfo 00110 *keyring_info; 00111 00112 keyring_info=(KeyringInfo *) AcquireWizardMemory(sizeof(*keyring_info)); 00113 if (keyring_info == (KeyringInfo *) NULL) 00114 ThrowWizardFatalError(KeyringDomain,MemoryError); 00115 (void) ResetWizardMemory(keyring_info,0,sizeof(*keyring_info)); 00116 keyring_info->path=(char *) NULL; 00117 if (path != (char *) NULL) 00118 keyring_info->path=ConstantString(path); 00119 keyring_info->id=(StringInfo *) NULL; 00120 keyring_info->key=(StringInfo *) NULL; 00121 keyring_info->nonce=(StringInfo *) NULL; 00122 keyring_info->protocol_major=KeyringProtocolMajorVersion; 00123 keyring_info->protocol_minor=KeyringProtocolMinorVersion; 00124 keyring_info->timestamp=time((time_t *) NULL); 00125 keyring_info->signature=WizardSignature; 00126 return(keyring_info); 00127 } 00128 00129 /* 00130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00131 % % 00132 % % 00133 % % 00134 % D e s t r o y K e y r i n g I n f o % 00135 % % 00136 % % 00137 % % 00138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00139 % 00140 % DestroyKeyringInfo() zeros memory associated with the KeyringInfo structure. 00141 % 00142 % The format of the DestroyKeyringInfo method is: 00143 % 00144 % KeyringInfo *DestroyKeyringInfo(KeyringInfo *keyring_info) 00145 % 00146 % A description of each parameter follows: 00147 % 00148 % o keyring_info: The ring info. 00149 % 00150 */ 00151 WizardExport KeyringInfo *DestroyKeyringInfo(KeyringInfo *keyring_info) 00152 { 00153 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); 00154 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL); 00155 WizardAssert(KeymapDomain,keyring_info->signature == WizardSignature); 00156 if (keyring_info->nonce != (StringInfo *) NULL) 00157 keyring_info->nonce=DestroyStringInfo(keyring_info->nonce); 00158 if (keyring_info->key != (StringInfo *) NULL) 00159 keyring_info->key=DestroyStringInfo(keyring_info->key); 00160 if (keyring_info->id != (StringInfo *) NULL) 00161 keyring_info->id=DestroyStringInfo(keyring_info->id); 00162 if (keyring_info->path != (char *) NULL) 00163 keyring_info->path=DestroyString(keyring_info->path); 00164 keyring_info->signature=(~WizardSignature); 00165 keyring_info=(KeyringInfo *) RelinquishWizardMemory(keyring_info); 00166 return(keyring_info); 00167 } 00168 00169 /* 00170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00171 % % 00172 % % 00173 % % 00174 % E x p o r t K e y r i n g K e y % 00175 % % 00176 % % 00177 % % 00178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00179 % 00180 % ExportKeyringKey() exports a key from the keyring. 00181 % 00182 % The format of the ExportKeyringKey method is: 00183 % 00184 % WizardBooleanType ExportKeyringKey(KeyringInfo *keyring_info, 00185 % ExceptionInfo *exception) 00186 % 00187 % A description of each parameter follows: 00188 % 00189 % o keyring_info: The ring info. 00190 % 00191 % o exception: Return any errors or warnings in this structure. 00192 % 00193 */ 00194 WizardExport WizardBooleanType ExportKeyringKey(KeyringInfo *keyring_info, 00195 ExceptionInfo *exception) 00196 { 00197 FileInfo 00198 *file_info; 00199 00200 WizardStatusType 00201 status; 00202 00203 StringInfo 00204 *filetype, 00205 *id, 00206 *key, 00207 *magick, 00208 *nonce, 00209 *target; 00210 00211 size_t 00212 length, 00213 signature; 00214 00215 WizardSizeType 00216 timestamp; 00217 00218 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); 00219 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL); 00220 WizardAssert(KeymapDomain,keyring_info->signature == WizardSignature); 00221 WizardAssert(KeymapDomain,exception != (ExceptionInfo *) NULL); 00222 file_info=AcquireFileInfo(keyring_info->path,KeyringFilename,ReadFileMode, 00223 exception); 00224 if (file_info == (FileInfo *) NULL) 00225 return(WizardFalse); 00226 magick=GetWizardMagick(WizardMagick,sizeof(WizardMagick)); 00227 target=CloneStringInfo(magick); 00228 status=ReadFileChunk(file_info,GetStringInfoDatum(target), 00229 GetStringInfoLength(target)); 00230 if ((status == WizardFalse) || (CompareStringInfo(target,magick) != 0)) 00231 { 00232 file_info=DestroyFileInfo(file_info,exception); 00233 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00234 "corrupt key ring file `%s'",GetFilePath(file_info)); 00235 return(WizardFalse); 00236 } 00237 magick=DestroyStringInfo(magick); 00238 target=DestroyStringInfo(target); 00239 filetype=GetWizardMagick((unsigned char *) KeyringFiletype, 00240 strlen(KeyringFiletype)); 00241 target=CloneStringInfo(filetype); 00242 status|=ReadFileChunk(file_info,GetStringInfoDatum(target), 00243 GetStringInfoLength(target)); 00244 if ((status == WizardFalse) || (CompareStringInfo(target,filetype) != 0)) 00245 { 00246 file_info=DestroyFileInfo(file_info,exception); 00247 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00248 "corrupt key ring file `%s'",GetFilePath(file_info)); 00249 return(WizardFalse); 00250 } 00251 filetype=DestroyStringInfo(filetype); 00252 target=DestroyStringInfo(target); 00253 signature=0; 00254 length=0; 00255 while (ReadFile32Bits(file_info,&signature) != 0) 00256 { 00257 if (signature != WizardSignature) 00258 { 00259 file_info=DestroyFileInfo(file_info,exception); 00260 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00261 "corrupt key ring file `%s'",GetFilePath(file_info)); 00262 return(WizardFalse); 00263 } 00264 keyring_info->signature=signature; 00265 status|=ReadFile32Bits(file_info,&length); 00266 status|=ReadFile16Bits(file_info,&keyring_info->protocol_major); 00267 status|=ReadFile16Bits(file_info,&keyring_info->protocol_minor); 00268 if ((keyring_info->protocol_major == 1) && 00269 (keyring_info->protocol_minor == 0)) 00270 timestamp=(time_t) length; 00271 else 00272 status|=ReadFile64Bits(file_info,×tamp); 00273 keyring_info->timestamp=(time_t) timestamp; 00274 status|=ReadFile32Bits(file_info,&length); 00275 if (status == WizardFalse) 00276 { 00277 file_info=DestroyFileInfo(file_info,exception); 00278 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00279 "corrupt key ring file `%s'",GetFilePath(file_info)); 00280 return(WizardFalse); 00281 } 00282 id=AcquireStringInfo(length); 00283 status|=ReadFileChunk(file_info,GetStringInfoDatum(id), 00284 GetStringInfoLength(id)); 00285 status|=ReadFile32Bits(file_info,&length); 00286 if (status == WizardFalse) 00287 { 00288 file_info=DestroyFileInfo(file_info,exception); 00289 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00290 "corrupt key ring file `%s'",GetFilePath(file_info)); 00291 return(WizardFalse); 00292 } 00293 key=AcquireStringInfo(length); 00294 status|=ReadFileChunk(file_info,GetStringInfoDatum(key), 00295 GetStringInfoLength(key)); 00296 status|=ReadFile32Bits(file_info,&length); 00297 if (status == WizardFalse) 00298 { 00299 file_info=DestroyFileInfo(file_info,exception); 00300 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00301 "corrupt key ring file `%s'",GetFilePath(file_info)); 00302 return(WizardFalse); 00303 } 00304 nonce=AcquireStringInfo(length); 00305 status|=ReadFileChunk(file_info,GetStringInfoDatum(nonce), 00306 GetStringInfoLength(nonce)); 00307 if (CompareStringInfo(keyring_info->id,id) == 0) 00308 { 00309 SetKeyringKey(keyring_info,key); 00310 SetKeyringNonce(keyring_info,nonce); 00311 nonce=DestroyStringInfo(nonce); 00312 key=DestroyStringInfo(key); 00313 id=DestroyStringInfo(id); 00314 file_info=DestroyFileInfo(file_info,exception); 00315 return(WizardTrue); 00316 } 00317 nonce=DestroyStringInfo(nonce); 00318 key=DestroyStringInfo(key); 00319 id=DestroyStringInfo(id); 00320 if (status == WizardFalse) 00321 { 00322 file_info=DestroyFileInfo(file_info,exception); 00323 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00324 "corrupt key ring file `%s'",GetFilePath(file_info)); 00325 return(WizardFalse); 00326 } 00327 } 00328 file_info=DestroyFileInfo(file_info,exception); 00329 return(WizardFalse); 00330 } 00331 00332 /* 00333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00334 % % 00335 % % 00336 % % 00337 % G e t K e y r i n g K e y % 00338 % % 00339 % % 00340 % % 00341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00342 % 00343 % GetKeyringKey() returns the keyring key. 00344 % 00345 % The format of the GetKeyringKey method is: 00346 % 00347 % const StringInfo *GetKeyringKey(const KeyringInfo *keyring_info) 00348 % 00349 % A description of each parameter follows: 00350 % 00351 % o keyring_info: The keyring info. 00352 % 00353 */ 00354 WizardExport const StringInfo *GetKeyringKey(const KeyringInfo *keyring_info) 00355 { 00356 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); 00357 WizardAssert(KeyringDomain,keyring_info != (KeyringInfo *) NULL); 00358 WizardAssert(KeyringDomain,keyring_info->signature == WizardSignature); 00359 return(keyring_info->key); 00360 } 00361 00362 /* 00363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00364 % % 00365 % % 00366 % % 00367 % G e t K e y r i n g N o n c e % 00368 % % 00369 % % 00370 % % 00371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00372 % 00373 % GetKeyringNonce() returns the keyring nonce. 00374 % 00375 % The format of the GetKeyringNonce method is: 00376 % 00377 % const StringInfo *GetKeyringNonce(const KeyringInfo *keyring_info) 00378 % 00379 % A description of each parameter follows: 00380 % 00381 % o keyring_info: The keyring info. 00382 % 00383 */ 00384 WizardExport const StringInfo *GetKeyringNonce(const KeyringInfo *keyring_info) 00385 { 00386 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); 00387 WizardAssert(KeyringDomain,keyring_info != (KeyringInfo *) NULL); 00388 WizardAssert(KeyringDomain,keyring_info->signature == WizardSignature); 00389 return(keyring_info->nonce); 00390 } 00391 00392 /* 00393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00394 % % 00395 % % 00396 % % 00397 % I m p o r t K e y r i n g K e y % 00398 % % 00399 % % 00400 % % 00401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00402 % 00403 % ImportKeyringKey() imports a key to the keyring. 00404 % 00405 % The format of the ImportKeyringKey method is: 00406 % 00407 % WizardBooleanType ImportKeyringKey(KeyringInfo *keyring_info, 00408 % ExceptionInfo *exception) 00409 % 00410 % A description of each parameter follows: 00411 % 00412 % o keyring_info: The ring info. 00413 % 00414 % o exception: Return any errors or warnings in this structure. 00415 % 00416 */ 00417 WizardExport WizardBooleanType ImportKeyringKey(KeyringInfo *keyring_info, 00418 ExceptionInfo *exception) 00419 { 00420 FileInfo 00421 *file_info; 00422 00423 KeyringInfo 00424 *import_info; 00425 00426 WizardStatusType 00427 status; 00428 00429 size_t 00430 length; 00431 00432 StringInfo 00433 *filetype, 00434 *magick; 00435 00436 WizardOffsetType 00437 offset; 00438 00439 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); 00440 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL); 00441 WizardAssert(KeymapDomain,keyring_info->signature == WizardSignature); 00442 WizardAssert(KeymapDomain,exception != (ExceptionInfo *) NULL); 00443 import_info=AcquireKeyringInfo(keyring_info->path); 00444 SetKeyringId(import_info,keyring_info->id); 00445 if (ExportKeyringKey(import_info,exception) != WizardFalse) 00446 { 00447 char 00448 *id; 00449 00450 /* 00451 Duplicate keys are not allowed in the keyring. 00452 */ 00453 id=StringInfoToHexString(keyring_info->id); 00454 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00455 "unable to import key `%s' (its already in the keyring): %s",id, 00456 keyring_info->path); 00457 id=DestroyString(id); 00458 import_info=DestroyKeyringInfo(import_info); 00459 return(WizardFalse); 00460 } 00461 import_info=DestroyKeyringInfo(import_info); 00462 file_info=AcquireFileInfo(keyring_info->path,KeyringFilename,WriteFileMode, 00463 exception); 00464 if (file_info == (FileInfo *) NULL) 00465 return(WizardFalse); 00466 magick=GetWizardMagick(WizardMagick,sizeof(WizardMagick)); 00467 status=WriteFileChunk(file_info,GetStringInfoDatum(magick), 00468 GetStringInfoLength(magick)); 00469 magick=DestroyStringInfo(magick); 00470 filetype=GetWizardMagick((unsigned char *) KeyringFiletype, 00471 strlen(KeyringFiletype)); 00472 status|=WriteFileChunk(file_info,GetStringInfoDatum(filetype), 00473 GetStringInfoLength(filetype)); 00474 filetype=DestroyStringInfo(filetype); 00475 offset=lseek(GetFileDescriptor(file_info),0,SEEK_END); 00476 if (offset == -1) 00477 { 00478 file_info=DestroyFileInfo(file_info,exception); 00479 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00480 "unable to seek keyring `%s': %s",GetFilePath(file_info), 00481 strerror(errno)); 00482 return(WizardFalse); 00483 } 00484 status|=WriteFile32Bits(file_info,keyring_info->signature); 00485 status|=WriteFile32Bits(file_info,0U); 00486 status|=WriteFile16Bits(file_info,keyring_info->protocol_major); 00487 status|=WriteFile16Bits(file_info,keyring_info->protocol_minor); 00488 status|=WriteFile64Bits(file_info,(WizardSizeType) keyring_info->timestamp); 00489 length=GetStringInfoLength(keyring_info->id); 00490 status|=WriteFile32Bits(file_info,(size_t) length); 00491 status|=WriteFileChunk(file_info,GetStringInfoDatum(keyring_info->id),length); 00492 length=GetStringInfoLength(keyring_info->key); 00493 status|=WriteFile32Bits(file_info,(size_t) length); 00494 status|=WriteFileChunk(file_info,GetStringInfoDatum(keyring_info->key), 00495 length); 00496 length=GetStringInfoLength(keyring_info->nonce); 00497 status|=WriteFile32Bits(file_info,(size_t) length); 00498 status|=WriteFileChunk(file_info,GetStringInfoDatum(keyring_info->nonce), 00499 length); 00500 if (status == WizardFalse) 00501 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00502 "unable to write keyring `%s': %s",GetFilePath(file_info), 00503 strerror(errno)); 00504 file_info=DestroyFileInfo(file_info,exception); 00505 return(WizardTrue); 00506 } 00507 00508 /* 00509 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00510 % % 00511 % % 00512 % % 00513 % P r i n t K e y r i n g P r o p e r t i e s % 00514 % % 00515 % % 00516 % % 00517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00518 % 00519 % PrintKeyringProperties() prints properties associated with each key in the 00520 % keyring. 00521 % 00522 % The format of the PrintKeyringProperties method is: 00523 % 00524 % WizardBooleanType PrintKeyringProperties(const char *path, 00525 % BlobInfo *keyring_blob,ExceptionInfo *exception) 00526 % 00527 % A description of each parameter follows: 00528 % 00529 % o path: the keyring path. 00530 % 00531 % o blob_ibfo: list the key properties to this blob. 00532 % 00533 % o exception: Return any errors or warnings in this structure. 00534 % 00535 */ 00536 WizardExport WizardBooleanType PrintKeyringProperties(const char *path, 00537 BlobInfo *keyring_blob,ExceptionInfo *exception) 00538 { 00539 char 00540 *canonical_path, 00541 *hex, 00542 *keyring_rdf, 00543 message[MaxTextExtent]; 00544 00545 const struct stat 00546 *properties; 00547 00548 FileInfo 00549 *file_info; 00550 00551 KeyringInfo 00552 keyring_info; 00553 00554 ssize_t 00555 count; 00556 00557 StringInfo 00558 *filetype, 00559 *id, 00560 *key, 00561 *magick, 00562 *nonce, 00563 *target; 00564 00565 size_t 00566 length; 00567 00568 WizardSizeType 00569 timestamp; 00570 00571 WizardStatusType 00572 status; 00573 00574 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); 00575 WizardAssert(KeymapDomain,exception != (ExceptionInfo *) NULL); 00576 file_info=AcquireFileInfo(path,KeyringFilename,ReadFileMode,exception); 00577 if (file_info == (FileInfo *) NULL) 00578 return(WizardTrue); 00579 keyring_rdf=AcquireString(" <keyring:Keyring rdf:about=\""); 00580 canonical_path=CanonicalXMLContent(GetFilePath(file_info),WizardFalse); 00581 (void) ConcatenateString(&keyring_rdf,canonical_path); 00582 (void) ConcatenateString(&keyring_rdf,"\">\n"); 00583 properties=GetFileProperties(file_info); 00584 (void) ConcatenateString(&keyring_rdf," <keyring:modify-date>"); 00585 (void) FormatWizardTime(properties->st_mtime,MaxTextExtent,message); 00586 (void) ConcatenateString(&keyring_rdf,message); 00587 (void) ConcatenateString(&keyring_rdf,"</keyring:modify-date>\n"); 00588 (void) ConcatenateString(&keyring_rdf," <keyring:create-date>"); 00589 (void) FormatWizardTime(properties->st_mtime,MaxTextExtent,message); 00590 (void) ConcatenateString(&keyring_rdf,message); 00591 (void) ConcatenateString(&keyring_rdf,"</keyring:create-date>\n"); 00592 (void) ConcatenateString(&keyring_rdf," <keyring:timestamp>"); 00593 (void) FormatWizardTime(time((time_t *) NULL),MaxTextExtent,message); 00594 (void) ConcatenateString(&keyring_rdf,message); 00595 (void) ConcatenateString(&keyring_rdf,"</keyring:timestamp>\n"); 00596 (void) ConcatenateString(&keyring_rdf," </keyring:Keyring>\n"); 00597 length=strlen(keyring_rdf); 00598 count=WriteBlob(keyring_blob,length,(unsigned char *) keyring_rdf); 00599 keyring_rdf=DestroyString(keyring_rdf); 00600 if (count != (ssize_t) length) 00601 ThrowFileException(exception,FileError,GetFilePath(file_info)); 00602 magick=GetWizardMagick(WizardMagick,sizeof(WizardMagick)); 00603 target=CloneStringInfo(magick); 00604 status=ReadFileChunk(file_info,GetStringInfoDatum(target), 00605 GetStringInfoLength(target)); 00606 if ((status == WizardFalse) || (CompareStringInfo(target,magick) != 0)) 00607 { 00608 file_info=DestroyFileInfo(file_info,exception); 00609 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00610 "corrupt key ring file `%s'",GetFilePath(file_info)); 00611 return(WizardFalse); 00612 } 00613 magick=DestroyStringInfo(magick); 00614 target=DestroyStringInfo(target); 00615 filetype=GetWizardMagick((unsigned char *) KeyringFiletype, 00616 strlen(KeyringFiletype)); 00617 target=CloneStringInfo(filetype); 00618 status|=ReadFileChunk(file_info,GetStringInfoDatum(target), 00619 GetStringInfoLength(target)); 00620 if ((status == WizardFalse) || (CompareStringInfo(target,filetype) != 0)) 00621 { 00622 file_info=DestroyFileInfo(file_info,exception); 00623 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00624 "corrupt key ring file `%s'",GetFilePath(file_info)); 00625 return(WizardFalse); 00626 } 00627 filetype=DestroyStringInfo(filetype); 00628 target=DestroyStringInfo(target); 00629 length=0; 00630 (void) ResetWizardMemory(&keyring_info,0,sizeof(keyring_info)); 00631 while (ReadFile32Bits(file_info,&keyring_info.signature) != 0) 00632 { 00633 if (keyring_info.signature != WizardSignature) 00634 { 00635 file_info=DestroyFileInfo(file_info,exception); 00636 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00637 "corrupt key ring file `%s'",GetFilePath(file_info)); 00638 return(WizardFalse); 00639 } 00640 status|=ReadFile32Bits(file_info,&length); 00641 status|=ReadFile16Bits(file_info,&keyring_info.protocol_major); 00642 status|=ReadFile16Bits(file_info,&keyring_info.protocol_minor); 00643 if ((keyring_info.protocol_major == 1) && 00644 (keyring_info.protocol_minor == 0)) 00645 timestamp=(time_t) length; 00646 else 00647 status|=ReadFile64Bits(file_info,×tamp); 00648 keyring_info.timestamp=(time_t) timestamp; 00649 status|=ReadFile32Bits(file_info,&length); 00650 if (status == WizardFalse) 00651 { 00652 file_info=DestroyFileInfo(file_info,exception); 00653 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00654 "corrupt key ring file `%s'",GetFilePath(file_info)); 00655 return(WizardFalse); 00656 } 00657 id=AcquireStringInfo(length); 00658 status|=ReadFileChunk(file_info,GetStringInfoDatum(id), 00659 GetStringInfoLength(id)); 00660 status|=ReadFile32Bits(file_info,&length); 00661 if (status == WizardFalse) 00662 { 00663 file_info=DestroyFileInfo(file_info,exception); 00664 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00665 "corrupt key ring file `%s'",GetFilePath(file_info)); 00666 return(WizardFalse); 00667 } 00668 key=AcquireStringInfo(length); 00669 status|=ReadFileChunk(file_info,GetStringInfoDatum(key), 00670 GetStringInfoLength(key)); 00671 status|=ReadFile32Bits(file_info,&length); 00672 if (status == WizardFalse) 00673 { 00674 file_info=DestroyFileInfo(file_info,exception); 00675 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00676 "corrupt key ring file `%s'",GetFilePath(file_info)); 00677 return(WizardFalse); 00678 } 00679 nonce=AcquireStringInfo(length); 00680 status|=ReadFileChunk(file_info,GetStringInfoDatum(nonce), 00681 GetStringInfoLength(nonce)); 00682 keyring_rdf=AcquireString(" <keyring:Key rdf:about=\""); 00683 hex=StringInfoToHexString(id); 00684 (void) ConcatenateString(&keyring_rdf,hex); 00685 hex=DestroyString(hex); 00686 (void) ConcatenateString(&keyring_rdf,"\">\n"); 00687 (void) ConcatenateString(&keyring_rdf," <keyring:memberOf " 00688 "rdf:resource=\""); 00689 (void) ConcatenateString(&keyring_rdf,canonical_path); 00690 (void) ConcatenateString(&keyring_rdf,"\"/>\n"); 00691 (void) ConcatenateString(&keyring_rdf," <keyring:nonce>"); 00692 hex=StringInfoToHexString(nonce); 00693 (void) ConcatenateString(&keyring_rdf,hex); 00694 hex=DestroyString(hex); 00695 (void) ConcatenateString(&keyring_rdf,"</keyring:nonce>\n"); 00696 (void) ConcatenateString(&keyring_rdf," <keyring:timestamp>"); 00697 (void) FormatWizardTime(keyring_info.timestamp,MaxTextExtent,message); 00698 (void) ConcatenateString(&keyring_rdf,message); 00699 (void) ConcatenateString(&keyring_rdf,"</keyring:timestamp>\n"); 00700 (void) ConcatenateString(&keyring_rdf," <keyring:protocol>"); 00701 (void) FormatLocaleString(message,MaxTextExtent,"%u.%u", 00702 keyring_info.protocol_major,(unsigned int) keyring_info.protocol_minor); 00703 (void) ConcatenateString(&keyring_rdf,message); 00704 (void) ConcatenateString(&keyring_rdf,"</keyring:protocol>\n"); 00705 (void) ConcatenateString(&keyring_rdf," </keyring:Key>\n"); 00706 length=strlen(keyring_rdf); 00707 count=WriteBlob(keyring_blob,length,(unsigned char *) keyring_rdf); 00708 keyring_rdf=DestroyString(keyring_rdf); 00709 if (count != (ssize_t) length) 00710 ThrowFileException(exception,FileError,GetFilePath(file_info)); 00711 nonce=DestroyStringInfo(nonce); 00712 key=DestroyStringInfo(key); 00713 id=DestroyStringInfo(id); 00714 if (status == WizardFalse) 00715 { 00716 file_info=DestroyFileInfo(file_info,exception); 00717 (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, 00718 "corrupt key ring file `%s'",GetFilePath(file_info)); 00719 return(WizardFalse); 00720 } 00721 } 00722 canonical_path=DestroyString(canonical_path); 00723 file_info=DestroyFileInfo(file_info,exception); 00724 return(WizardTrue); 00725 } 00726 00727 /* 00728 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00729 % % 00730 % % 00731 % % 00732 % S e t K e y r i n g I d % 00733 % % 00734 % % 00735 % % 00736 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00737 % 00738 % SetKeyringId() sets the keyring id. 00739 % 00740 % The format of the SetKeyringId method is: 00741 % 00742 % void SetKeyringId(KeyringInfo *keyring_info,const StringInfo *id) 00743 % 00744 % A description of each parameter follows: 00745 % 00746 % o keyring_info: The keyring info. 00747 % 00748 % o id: The id. 00749 % 00750 */ 00751 WizardExport void SetKeyringId(KeyringInfo *keyring_info,const StringInfo *id) 00752 { 00753 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL); 00754 WizardAssert(KeymapDomain,keyring_info->signature == WizardSignature); 00755 if (keyring_info->id != (StringInfo *) NULL) 00756 keyring_info->id=DestroyStringInfo(keyring_info->id); 00757 keyring_info->id=CloneStringInfo(id); 00758 } 00759 00760 /* 00761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00762 % % 00763 % % 00764 % % 00765 % S e t K e y r i n g K e y % 00766 % % 00767 % % 00768 % % 00769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00770 % 00771 % SetKeyringKey() sets the keyring key. 00772 % 00773 % The format of the SetKeyringKey method is: 00774 % 00775 % void SetKeyringKey(KeyringInfo *keyring_info,const StringInfo *key) 00776 % 00777 % A description of each parameter follows: 00778 % 00779 % o keyring_info: The keyring info. 00780 % 00781 % o key: The key. 00782 % 00783 */ 00784 WizardExport void SetKeyringKey(KeyringInfo *keyring_info,const StringInfo *key) 00785 { 00786 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL); 00787 WizardAssert(KeymapDomain,keyring_info->signature == WizardSignature); 00788 if (keyring_info->key != (StringInfo *) NULL) 00789 keyring_info->key=DestroyStringInfo(keyring_info->key); 00790 keyring_info->key=CloneStringInfo(key); 00791 } 00792 00793 /* 00794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00795 % % 00796 % % 00797 % % 00798 % S e t K e y r i n g N o n c e % 00799 % % 00800 % % 00801 % % 00802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00803 % 00804 % SetKeyringNonce() sets the keyring nonce. 00805 % 00806 % The format of the SetKeyringNonce method is: 00807 % 00808 % void SetKeyringNonce(KeyringInfo *keyring_info,const StringInfo *nonce) 00809 % 00810 % A description of each parameter follows: 00811 % 00812 % o keyring_info: The keyring info. 00813 % 00814 % o nonce: The nonce. 00815 % 00816 */ 00817 WizardExport void SetKeyringNonce(KeyringInfo *keyring_info, 00818 const StringInfo *nonce) 00819 { 00820 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL); 00821 WizardAssert(KeymapDomain,keyring_info->signature == WizardSignature); 00822 if (keyring_info->nonce != (StringInfo *) NULL) 00823 keyring_info->nonce=DestroyStringInfo(keyring_info->nonce); 00824 keyring_info->nonce=CloneStringInfo(nonce); 00825 } 00826 00827 /* 00828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00829 % % 00830 % % 00831 % % 00832 % S e t K e y r i n g P a t h % 00833 % % 00834 % % 00835 % % 00836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00837 % 00838 % SetKeyringPath() sets the keyring path. 00839 % 00840 % The format of the SetKeyringPath method is: 00841 % 00842 % void SetKeyringPath(KeyringInfo *keyring_info,const char *path) 00843 % 00844 % A description of each parameter follows: 00845 % 00846 % o keyring_info: The keyring info. 00847 % 00848 % o path: The keyring path. 00849 % 00850 */ 00851 WizardExport void SetKeyringPath(KeyringInfo *keyring_info,const char *path) 00852 { 00853 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL); 00854 WizardAssert(KeymapDomain,keyring_info->signature == WizardSignature); 00855 (void) CloneString(&keyring_info->path,path); 00856 }