MagickCore 7.0.10
keyring.c
Go to the documentation of this file.
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% K K EEEEE Y Y RRRR IIIII N N GGGG %
6% K K E Y Y R R I NN N G %
7% KKK EEE Y RRRR I N N N G GGG %
8% K K E Y R R I N NN G G %
9% K K EEEEE Y R R IIIII N N GGGG %
10% %
11% %
12% Wizard's Toolkit Keyring Methods %
13% %
14% Software Design %
15% Cristy %
16% March 2003 %
17% %
18% %
19% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
20% dedicated to making software imaging solutions freely available. %
21% %
22% You may not use this file except in compliance with the License. You may %
23% obtain a copy of the License at %
24% %
25% https://imagemagick.org/script/license.php %
26% %
27% Unless required by applicable law or agreed to in writing, software %
28% distributed under the License is distributed on an "AS IS" BASIS, %
29% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30% See the License for the specific language governing permissions and %
31% limitations under the License. %
32% %
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
42#include "wizard/studio.h"
43#include "wizard/blob-private.h"
44#include "wizard/exception.h"
46#include "wizard/file.h"
47#include "wizard/keyring.h"
48#include "wizard/magick.h"
49#include "wizard/memory_.h"
50#include "wizard/nt-base.h"
51#include "wizard/utility.h"
52#include "wizard/xml-tree.h"
53
54/*
55 Define declarations.
56*/
57#define KeyringFilename "keyring.xdm"
58#define KeyringFiletype "keyring"
59#define KeyringProtocolMajorVersion 1
60#define KeyringProtocolMinorVersion 1
61
62/*
63 Typedef declarations.
64*/
66{
67 char
69
74
75 unsigned short
78
79 time_t
81
82 size_t
84};
85
86/*
87%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88% %
89% %
90% %
91% A c q u i r e K e y r i n g I n f o %
92% %
93% %
94% %
95%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96%
97% AcquireKeyringInfo() allocates the KeyringInfo structure.
98%
99% The format of the AcquireKeyringInfo method is:
100%
101% KeyringInfo *AcquireKeyringInfo(const char *path)
102%
103% A description of each parameter follows:
104%
105% o path: The keyring path.
106%
107*/
109{
111 *keyring_info;
112
113 keyring_info=(KeyringInfo *) AcquireWizardMemory(sizeof(*keyring_info));
114 if (keyring_info == (KeyringInfo *) NULL)
116 (void) memset(keyring_info,0,sizeof(*keyring_info));
117 keyring_info->path=(char *) NULL;
118 if (path != (char *) NULL)
119 keyring_info->path=ConstantString(path);
120 keyring_info->id=(StringInfo *) NULL;
121 keyring_info->key=(StringInfo *) NULL;
122 keyring_info->nonce=(StringInfo *) NULL;
125 keyring_info->timestamp=time((time_t *) NULL);
126 keyring_info->signature=WizardSignature;
127 return(keyring_info);
128}
129
130/*
131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132% %
133% %
134% %
135% D e s t r o y K e y r i n g I n f o %
136% %
137% %
138% %
139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140%
141% DestroyKeyringInfo() zeros memory associated with the KeyringInfo structure.
142%
143% The format of the DestroyKeyringInfo method is:
144%
145% KeyringInfo *DestroyKeyringInfo(KeyringInfo *keyring_info)
146%
147% A description of each parameter follows:
148%
149% o keyring_info: The ring info.
150%
151*/
153{
155 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL);
157 if (keyring_info->nonce != (StringInfo *) NULL)
158 keyring_info->nonce=DestroyStringInfo(keyring_info->nonce);
159 if (keyring_info->key != (StringInfo *) NULL)
160 keyring_info->key=DestroyStringInfo(keyring_info->key);
161 if (keyring_info->id != (StringInfo *) NULL)
162 keyring_info->id=DestroyStringInfo(keyring_info->id);
163 if (keyring_info->path != (char *) NULL)
164 keyring_info->path=DestroyString(keyring_info->path);
165 keyring_info->signature=(~WizardSignature);
166 keyring_info=(KeyringInfo *) RelinquishWizardMemory(keyring_info);
167 return(keyring_info);
168}
169
170/*
171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172% %
173% %
174% %
175% E x p o r t K e y r i n g K e y %
176% %
177% %
178% %
179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180%
181% ExportKeyringKey() exports a key from the keyring.
182%
183% The format of the ExportKeyringKey method is:
184%
185% WizardBooleanType ExportKeyringKey(KeyringInfo *keyring_info,
186% ExceptionInfo *exception)
187%
188% A description of each parameter follows:
189%
190% o keyring_info: The ring info.
191%
192% o exception: Return any errors or warnings in this structure.
193%
194*/
196 ExceptionInfo *exception)
197{
199 *file_info;
200
202 status;
203
205 *filetype,
206 *id,
207 *key,
208 *magick,
209 *nonce,
210 *target;
211
212 size_t
213 length,
214 signature;
215
217 timestamp;
218
220 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL);
222 WizardAssert(KeymapDomain,exception != (ExceptionInfo *) NULL);
223 file_info=AcquireFileInfo(keyring_info->path,KeyringFilename,ReadFileMode,
224 exception);
225 if (file_info == (FileInfo *) NULL)
226 return(WizardFalse);
228 target=CloneStringInfo(magick);
229 status=ReadFileChunk(file_info,GetStringInfoDatum(target),
230 GetStringInfoLength(target));
231 if ((status == WizardFalse) || (CompareStringInfo(target,magick) != 0))
232 {
233 file_info=DestroyFileInfo(file_info,exception);
235 "corrupt key ring file `%s'",GetFilePath(file_info));
236 return(WizardFalse);
237 }
238 magick=DestroyStringInfo(magick);
239 target=DestroyStringInfo(target);
240 filetype=GetWizardMagick((unsigned char *) KeyringFiletype,
241 strlen(KeyringFiletype));
242 target=CloneStringInfo(filetype);
243 status&=ReadFileChunk(file_info,GetStringInfoDatum(target),
244 GetStringInfoLength(target));
245 if ((status == WizardFalse) || (CompareStringInfo(target,filetype) != 0))
246 {
247 file_info=DestroyFileInfo(file_info,exception);
249 "corrupt key ring file `%s'",GetFilePath(file_info));
250 return(WizardFalse);
251 }
252 filetype=DestroyStringInfo(filetype);
253 target=DestroyStringInfo(target);
254 signature=0;
255 length=0;
256 while (ReadFile32Bits(file_info,&signature) != 0)
257 {
258 if (signature != WizardSignature)
259 {
260 file_info=DestroyFileInfo(file_info,exception);
262 "corrupt key ring file `%s'",GetFilePath(file_info));
263 return(WizardFalse);
264 }
265 keyring_info->signature=signature;
266 status&=ReadFile32Bits(file_info,&length);
267 status&=ReadFile16Bits(file_info,&keyring_info->protocol_major);
268 status&=ReadFile16Bits(file_info,&keyring_info->protocol_minor);
269 if ((keyring_info->protocol_major == 1) &&
270 (keyring_info->protocol_minor == 0))
271 timestamp=(time_t) length;
272 else
273 status&=ReadFile64Bits(file_info,&timestamp);
274 keyring_info->timestamp=(time_t) timestamp;
275 status&=ReadFile32Bits(file_info,&length);
276 if (status == WizardFalse)
277 {
278 file_info=DestroyFileInfo(file_info,exception);
280 "corrupt key ring file `%s'",GetFilePath(file_info));
281 return(WizardFalse);
282 }
283 id=AcquireStringInfo(length);
284 status&=ReadFileChunk(file_info,GetStringInfoDatum(id),
286 status&=ReadFile32Bits(file_info,&length);
287 if (status == WizardFalse)
288 {
289 file_info=DestroyFileInfo(file_info,exception);
291 "corrupt key ring file `%s'",GetFilePath(file_info));
292 return(WizardFalse);
293 }
294 key=AcquireStringInfo(length);
295 status&=ReadFileChunk(file_info,GetStringInfoDatum(key),
297 status&=ReadFile32Bits(file_info,&length);
298 if (status == WizardFalse)
299 {
300 file_info=DestroyFileInfo(file_info,exception);
302 "corrupt key ring file `%s'",GetFilePath(file_info));
303 return(WizardFalse);
304 }
305 nonce=AcquireStringInfo(length);
306 status&=ReadFileChunk(file_info,GetStringInfoDatum(nonce),
307 GetStringInfoLength(nonce));
308 if (CompareStringInfo(keyring_info->id,id) == 0)
309 {
310 SetKeyringKey(keyring_info,key);
311 SetKeyringNonce(keyring_info,nonce);
312 nonce=DestroyStringInfo(nonce);
313 key=DestroyStringInfo(key);
314 id=DestroyStringInfo(id);
315 file_info=DestroyFileInfo(file_info,exception);
316 return(WizardTrue);
317 }
318 nonce=DestroyStringInfo(nonce);
319 key=DestroyStringInfo(key);
320 id=DestroyStringInfo(id);
321 if (status == WizardFalse)
322 {
323 file_info=DestroyFileInfo(file_info,exception);
325 "corrupt key ring file `%s'",GetFilePath(file_info));
326 return(WizardFalse);
327 }
328 }
329 file_info=DestroyFileInfo(file_info,exception);
330 return(WizardFalse);
331}
332
333/*
334%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335% %
336% %
337% %
338% G e t K e y r i n g K e y %
339% %
340% %
341% %
342%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343%
344% GetKeyringKey() returns the keyring key.
345%
346% The format of the GetKeyringKey method is:
347%
348% const StringInfo *GetKeyringKey(const KeyringInfo *keyring_info)
349%
350% A description of each parameter follows:
351%
352% o keyring_info: The keyring info.
353%
354*/
356{
358 WizardAssert(KeyringDomain,keyring_info != (KeyringInfo *) NULL);
360 return(keyring_info->key);
361}
362
363/*
364%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365% %
366% %
367% %
368% G e t K e y r i n g N o n c e %
369% %
370% %
371% %
372%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373%
374% GetKeyringNonce() returns the keyring nonce.
375%
376% The format of the GetKeyringNonce method is:
377%
378% const StringInfo *GetKeyringNonce(const KeyringInfo *keyring_info)
379%
380% A description of each parameter follows:
381%
382% o keyring_info: The keyring info.
383%
384*/
386{
388 WizardAssert(KeyringDomain,keyring_info != (KeyringInfo *) NULL);
390 return(keyring_info->nonce);
391}
392
393/*
394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395% %
396% %
397% %
398% I m p o r t K e y r i n g K e y %
399% %
400% %
401% %
402%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403%
404% ImportKeyringKey() imports a key to the keyring.
405%
406% The format of the ImportKeyringKey method is:
407%
408% WizardBooleanType ImportKeyringKey(KeyringInfo *keyring_info,
409% ExceptionInfo *exception)
410%
411% A description of each parameter follows:
412%
413% o keyring_info: The ring info.
414%
415% o exception: Return any errors or warnings in this structure.
416%
417*/
419 ExceptionInfo *exception)
420{
422 *file_info;
423
425 *import_info;
426
428 status;
429
430 size_t
431 length;
432
434 *filetype,
435 *magick;
436
438 offset;
439
441 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL);
443 WizardAssert(KeymapDomain,exception != (ExceptionInfo *) NULL);
444 import_info=AcquireKeyringInfo(keyring_info->path);
445 SetKeyringId(import_info,keyring_info->id);
446 if (ExportKeyringKey(import_info,exception) != WizardFalse)
447 {
448 char
449 *id;
450
451 /*
452 Duplicate keys are not allowed in the keyring.
453 */
454 id=StringInfoToHexString(keyring_info->id);
456 "unable to import key `%s' (its already in the keyring): %s",id,
457 keyring_info->path);
458 id=DestroyString(id);
459 import_info=DestroyKeyringInfo(import_info);
460 return(WizardFalse);
461 }
462 import_info=DestroyKeyringInfo(import_info);
463 file_info=AcquireFileInfo(keyring_info->path,KeyringFilename,WriteFileMode,
464 exception);
465 if (file_info == (FileInfo *) NULL)
466 return(WizardFalse);
468 status=WriteFileChunk(file_info,GetStringInfoDatum(magick),
469 GetStringInfoLength(magick));
470 magick=DestroyStringInfo(magick);
471 filetype=GetWizardMagick((unsigned char *) KeyringFiletype,
472 strlen(KeyringFiletype));
473 status&=WriteFileChunk(file_info,GetStringInfoDatum(filetype),
474 GetStringInfoLength(filetype));
475 filetype=DestroyStringInfo(filetype);
476 offset=lseek(GetFileDescriptor(file_info),0,SEEK_END);
477 if (offset == -1)
478 {
479 file_info=DestroyFileInfo(file_info,exception);
481 "unable to seek keyring `%s': %s",GetFilePath(file_info),
482 strerror(errno));
483 return(WizardFalse);
484 }
485 status&=WriteFile32Bits(file_info,keyring_info->signature);
486 status&=WriteFile32Bits(file_info,0U);
487 status&=WriteFile16Bits(file_info,keyring_info->protocol_major);
488 status&=WriteFile16Bits(file_info,keyring_info->protocol_minor);
489 status&=WriteFile64Bits(file_info,(WizardSizeType) keyring_info->timestamp);
490 length=GetStringInfoLength(keyring_info->id);
491 status&=WriteFile32Bits(file_info,(size_t) length);
492 status&=WriteFileChunk(file_info,GetStringInfoDatum(keyring_info->id),length);
493 length=GetStringInfoLength(keyring_info->key);
494 status&=WriteFile32Bits(file_info,(size_t) length);
495 status&=WriteFileChunk(file_info,GetStringInfoDatum(keyring_info->key),
496 length);
497 length=GetStringInfoLength(keyring_info->nonce);
498 status&=WriteFile32Bits(file_info,(size_t) length);
499 status&=WriteFileChunk(file_info,GetStringInfoDatum(keyring_info->nonce),
500 length);
501 if (status == WizardFalse)
503 "unable to write keyring `%s': %s",GetFilePath(file_info),
504 strerror(errno));
505 file_info=DestroyFileInfo(file_info,exception);
506 return(WizardTrue);
507}
508
509/*
510%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
511% %
512% %
513% %
514% P r i n t K e y r i n g P r o p e r t i e s %
515% %
516% %
517% %
518%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
519%
520% PrintKeyringProperties() prints properties associated with each key in the
521% keyring.
522%
523% The format of the PrintKeyringProperties method is:
524%
525% WizardBooleanType PrintKeyringProperties(const char *path,
526% BlobInfo *keyring_blob,ExceptionInfo *exception)
527%
528% A description of each parameter follows:
529%
530% o path: the keyring path.
531%
532% o blob_ibfo: list the key properties to this blob.
533%
534% o exception: Return any errors or warnings in this structure.
535%
536*/
538 BlobInfo *keyring_blob,ExceptionInfo *exception)
539{
540 char
541 *canonical_path,
542 *hex,
543 *keyring_rdf,
544 message[WizardPathExtent];
545
546 const struct stat
547 *properties;
548
550 *file_info;
551
553 keyring_info;
554
555 ssize_t
556 count;
557
559 *filetype,
560 *id,
561 *key,
562 *magick,
563 *nonce,
564 *target;
565
566 size_t
567 length;
568
570 timestamp;
571
573 status;
574
576 WizardAssert(KeymapDomain,exception != (ExceptionInfo *) NULL);
577 file_info=AcquireFileInfo(path,KeyringFilename,ReadFileMode,exception);
578 if (file_info == (FileInfo *) NULL)
579 return(WizardTrue);
580 keyring_rdf=AcquireString(" <keyring:Keyring rdf:about=\"");
581 canonical_path=CanonicalXMLContent(GetFilePath(file_info),WizardFalse);
582 (void) ConcatenateString(&keyring_rdf,canonical_path);
583 (void) ConcatenateString(&keyring_rdf,"\">\n");
584 properties=GetFileProperties(file_info);
585 (void) ConcatenateString(&keyring_rdf," <keyring:modify-date>");
586 (void) FormatWizardTime(properties->st_mtime,WizardPathExtent,message);
587 (void) ConcatenateString(&keyring_rdf,message);
588 (void) ConcatenateString(&keyring_rdf,"</keyring:modify-date>\n");
589 (void) ConcatenateString(&keyring_rdf," <keyring:create-date>");
590 (void) FormatWizardTime(properties->st_mtime,WizardPathExtent,message);
591 (void) ConcatenateString(&keyring_rdf,message);
592 (void) ConcatenateString(&keyring_rdf,"</keyring:create-date>\n");
593 (void) ConcatenateString(&keyring_rdf," <keyring:timestamp>");
594 (void) FormatWizardTime(time((time_t *) NULL),WizardPathExtent,message);
595 (void) ConcatenateString(&keyring_rdf,message);
596 (void) ConcatenateString(&keyring_rdf,"</keyring:timestamp>\n");
597 (void) ConcatenateString(&keyring_rdf," </keyring:Keyring>\n");
598 length=strlen(keyring_rdf);
599 count=WriteBlob(keyring_blob,length,(unsigned char *) keyring_rdf);
600 keyring_rdf=DestroyString(keyring_rdf);
601 if (count != (ssize_t) length)
602 ThrowFileException(exception,FileError,GetFilePath(file_info));
604 target=CloneStringInfo(magick);
605 status=ReadFileChunk(file_info,GetStringInfoDatum(target),
606 GetStringInfoLength(target));
607 if ((status == WizardFalse) || (CompareStringInfo(target,magick) != 0))
608 {
609 file_info=DestroyFileInfo(file_info,exception);
611 "corrupt key ring file `%s'",GetFilePath(file_info));
612 return(WizardFalse);
613 }
614 magick=DestroyStringInfo(magick);
615 target=DestroyStringInfo(target);
616 filetype=GetWizardMagick((unsigned char *) KeyringFiletype,
617 strlen(KeyringFiletype));
618 target=CloneStringInfo(filetype);
619 status&=ReadFileChunk(file_info,GetStringInfoDatum(target),
620 GetStringInfoLength(target));
621 if ((status == WizardFalse) || (CompareStringInfo(target,filetype) != 0))
622 {
623 file_info=DestroyFileInfo(file_info,exception);
625 "corrupt key ring file `%s'",GetFilePath(file_info));
626 return(WizardFalse);
627 }
628 filetype=DestroyStringInfo(filetype);
629 target=DestroyStringInfo(target);
630 length=0;
631 (void) memset(&keyring_info,0,sizeof(keyring_info));
632 while (ReadFile32Bits(file_info,&keyring_info.signature) != 0)
633 {
634 if (keyring_info.signature != WizardSignature)
635 {
636 file_info=DestroyFileInfo(file_info,exception);
638 "corrupt key ring file `%s'",GetFilePath(file_info));
639 return(WizardFalse);
640 }
641 status&=ReadFile32Bits(file_info,&length);
642 status&=ReadFile16Bits(file_info,&keyring_info.protocol_major);
643 status&=ReadFile16Bits(file_info,&keyring_info.protocol_minor);
644 if ((keyring_info.protocol_major == 1) &&
645 (keyring_info.protocol_minor == 0))
646 timestamp=(time_t) length;
647 else
648 status&=ReadFile64Bits(file_info,&timestamp);
649 keyring_info.timestamp=(time_t) timestamp;
650 status&=ReadFile32Bits(file_info,&length);
651 if (status == WizardFalse)
652 {
653 file_info=DestroyFileInfo(file_info,exception);
655 "corrupt key ring file `%s'",GetFilePath(file_info));
656 return(WizardFalse);
657 }
658 id=AcquireStringInfo(length);
659 status&=ReadFileChunk(file_info,GetStringInfoDatum(id),
661 status&=ReadFile32Bits(file_info,&length);
662 if (status == WizardFalse)
663 {
664 file_info=DestroyFileInfo(file_info,exception);
666 "corrupt key ring file `%s'",GetFilePath(file_info));
667 return(WizardFalse);
668 }
669 key=AcquireStringInfo(length);
670 status&=ReadFileChunk(file_info,GetStringInfoDatum(key),
672 status&=ReadFile32Bits(file_info,&length);
673 if (status == WizardFalse)
674 {
675 file_info=DestroyFileInfo(file_info,exception);
677 "corrupt key ring file `%s'",GetFilePath(file_info));
678 return(WizardFalse);
679 }
680 nonce=AcquireStringInfo(length);
681 status&=ReadFileChunk(file_info,GetStringInfoDatum(nonce),
682 GetStringInfoLength(nonce));
683 keyring_rdf=AcquireString(" <keyring:Key rdf:about=\"");
684 hex=StringInfoToHexString(id);
685 (void) ConcatenateString(&keyring_rdf,hex);
686 hex=DestroyString(hex);
687 (void) ConcatenateString(&keyring_rdf,"\">\n");
688 (void) ConcatenateString(&keyring_rdf," <keyring:memberOf "
689 "rdf:resource=\"");
690 (void) ConcatenateString(&keyring_rdf,canonical_path);
691 (void) ConcatenateString(&keyring_rdf,"\"/>\n");
692 (void) ConcatenateString(&keyring_rdf," <keyring:nonce>");
693 hex=StringInfoToHexString(nonce);
694 (void) ConcatenateString(&keyring_rdf,hex);
695 hex=DestroyString(hex);
696 (void) ConcatenateString(&keyring_rdf,"</keyring:nonce>\n");
697 (void) ConcatenateString(&keyring_rdf," <keyring:timestamp>");
698 (void) FormatWizardTime(keyring_info.timestamp,WizardPathExtent,message);
699 (void) ConcatenateString(&keyring_rdf,message);
700 (void) ConcatenateString(&keyring_rdf,"</keyring:timestamp>\n");
701 (void) ConcatenateString(&keyring_rdf," <keyring:protocol>");
702 (void) FormatLocaleString(message,WizardPathExtent,"%u.%u",
703 keyring_info.protocol_major,(unsigned int) keyring_info.protocol_minor);
704 (void) ConcatenateString(&keyring_rdf,message);
705 (void) ConcatenateString(&keyring_rdf,"</keyring:protocol>\n");
706 (void) ConcatenateString(&keyring_rdf," </keyring:Key>\n");
707 length=strlen(keyring_rdf);
708 count=WriteBlob(keyring_blob,length,(unsigned char *) keyring_rdf);
709 keyring_rdf=DestroyString(keyring_rdf);
710 if (count != (ssize_t) length)
711 ThrowFileException(exception,FileError,GetFilePath(file_info));
712 nonce=DestroyStringInfo(nonce);
713 key=DestroyStringInfo(key);
714 id=DestroyStringInfo(id);
715 if (status == WizardFalse)
716 {
717 file_info=DestroyFileInfo(file_info,exception);
719 "corrupt key ring file `%s'",GetFilePath(file_info));
720 return(WizardFalse);
721 }
722 }
723 canonical_path=DestroyString(canonical_path);
724 file_info=DestroyFileInfo(file_info,exception);
725 return(WizardTrue);
726}
727
728/*
729%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
730% %
731% %
732% %
733% S e t K e y r i n g I d %
734% %
735% %
736% %
737%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
738%
739% SetKeyringId() sets the keyring id.
740%
741% The format of the SetKeyringId method is:
742%
743% void SetKeyringId(KeyringInfo *keyring_info,const StringInfo *id)
744%
745% A description of each parameter follows:
746%
747% o keyring_info: The keyring info.
748%
749% o id: The id.
750%
751*/
752WizardExport void SetKeyringId(KeyringInfo *keyring_info,const StringInfo *id)
753{
754 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL);
756 if (keyring_info->id != (StringInfo *) NULL)
757 keyring_info->id=DestroyStringInfo(keyring_info->id);
758 keyring_info->id=CloneStringInfo(id);
759}
760
761/*
762%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
763% %
764% %
765% %
766% S e t K e y r i n g K e y %
767% %
768% %
769% %
770%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
771%
772% SetKeyringKey() sets the keyring key.
773%
774% The format of the SetKeyringKey method is:
775%
776% void SetKeyringKey(KeyringInfo *keyring_info,const StringInfo *key)
777%
778% A description of each parameter follows:
779%
780% o keyring_info: The keyring info.
781%
782% o key: The key.
783%
784*/
785WizardExport void SetKeyringKey(KeyringInfo *keyring_info,const StringInfo *key)
786{
787 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL);
789 if (keyring_info->key != (StringInfo *) NULL)
790 keyring_info->key=DestroyStringInfo(keyring_info->key);
791 keyring_info->key=CloneStringInfo(key);
792}
793
794/*
795%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796% %
797% %
798% %
799% S e t K e y r i n g N o n c e %
800% %
801% %
802% %
803%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
804%
805% SetKeyringNonce() sets the keyring nonce.
806%
807% The format of the SetKeyringNonce method is:
808%
809% void SetKeyringNonce(KeyringInfo *keyring_info,const StringInfo *nonce)
810%
811% A description of each parameter follows:
812%
813% o keyring_info: The keyring info.
814%
815% o nonce: The nonce.
816%
817*/
819 const StringInfo *nonce)
820{
821 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL);
823 if (keyring_info->nonce != (StringInfo *) NULL)
824 keyring_info->nonce=DestroyStringInfo(keyring_info->nonce);
825 keyring_info->nonce=CloneStringInfo(nonce);
826}
827
828/*
829%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
830% %
831% %
832% %
833% S e t K e y r i n g P a t h %
834% %
835% %
836% %
837%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838%
839% SetKeyringPath() sets the keyring path.
840%
841% The format of the SetKeyringPath method is:
842%
843% void SetKeyringPath(KeyringInfo *keyring_info,const char *path)
844%
845% A description of each parameter follows:
846%
847% o keyring_info: The keyring info.
848%
849% o path: The keyring path.
850%
851*/
852WizardExport void SetKeyringPath(KeyringInfo *keyring_info,const char *path)
853{
854 WizardAssert(KeymapDomain,keyring_info != (KeyringInfo *) NULL);
856 (void) CloneString(&keyring_info->path,path);
857}
WizardExport ssize_t WriteBlob(BlobInfo *, const size_t, const void *)
#define WizardAssert(domain, predicate)
#define ThrowFileException(exception, severity, context)
#define ThrowWizardFatalError(domain, error)
WizardExport WizardBooleanType ThrowWizardException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *format,...)
Definition exception.c:1029
@ KeyringDomain
Definition exception.h:37
@ KeymapDomain
Definition exception.h:35
@ FileError
Definition exception.h:99
@ KeyringError
Definition exception.h:92
@ MemoryError
Definition exception.h:49
WizardExport WizardBooleanType ReadFile64Bits(FileInfo *file_info, WizardSizeType *value)
Definition file.c:754
WizardExport const char * GetFilePath(const FileInfo *file_info)
Definition file.c:505
WizardExport FileInfo * AcquireFileInfo(const char *path, const char *relative_path, const FileMode mode, ExceptionInfo *exception)
Definition file.c:257
WizardExport WizardBooleanType WriteFile32Bits(FileInfo *file_info, const size_t value)
Definition file.c:943
WizardExport WizardBooleanType WriteFile64Bits(FileInfo *file_info, const WizardSizeType value)
Definition file.c:984
WizardExport WizardBooleanType WriteFile16Bits(FileInfo *file_info, const unsigned short value)
Definition file.c:904
WizardExport const struct stat * GetFileProperties(const FileInfo *file_info)
Definition file.c:535
WizardExport WizardBooleanType ReadFileChunk(FileInfo *file_info, void *data, const size_t length)
Definition file.c:606
WizardExport int GetFileDescriptor(const FileInfo *file_info)
Definition file.c:475
WizardExport WizardBooleanType WriteFileChunk(FileInfo *file_info, const void *data, const size_t length)
Definition file.c:851
WizardExport WizardBooleanType ReadFile32Bits(FileInfo *file_info, size_t *value)
Definition file.c:706
WizardExport FileInfo * DestroyFileInfo(FileInfo *file_info, ExceptionInfo *exception)
Definition file.c:431
WizardExport WizardBooleanType ReadFile16Bits(FileInfo *file_info, unsigned short *value)
Definition file.c:660
@ WriteFileMode
Definition file.h:30
@ ReadFileMode
Definition file.h:29
WizardExport WizardBooleanType ImportKeyringKey(KeyringInfo *keyring_info, ExceptionInfo *exception)
Definition keyring.c:418
WizardExport const StringInfo * GetKeyringKey(const KeyringInfo *keyring_info)
Definition keyring.c:355
#define KeyringFilename
Definition keyring.c:57
WizardExport WizardBooleanType PrintKeyringProperties(const char *path, BlobInfo *keyring_blob, ExceptionInfo *exception)
Definition keyring.c:537
WizardExport void SetKeyringId(KeyringInfo *keyring_info, const StringInfo *id)
Definition keyring.c:752
WizardExport const StringInfo * GetKeyringNonce(const KeyringInfo *keyring_info)
Definition keyring.c:385
#define KeyringProtocolMinorVersion
Definition keyring.c:60
#define KeyringProtocolMajorVersion
Definition keyring.c:59
WizardExport WizardBooleanType ExportKeyringKey(KeyringInfo *keyring_info, ExceptionInfo *exception)
Definition keyring.c:195
WizardExport void SetKeyringKey(KeyringInfo *keyring_info, const StringInfo *key)
Definition keyring.c:785
WizardExport void SetKeyringNonce(KeyringInfo *keyring_info, const StringInfo *nonce)
Definition keyring.c:818
WizardExport KeyringInfo * DestroyKeyringInfo(KeyringInfo *keyring_info)
Definition keyring.c:152
WizardExport KeyringInfo * AcquireKeyringInfo(const char *path)
Definition keyring.c:108
WizardExport void SetKeyringPath(KeyringInfo *keyring_info, const char *path)
Definition keyring.c:852
#define KeyringFiletype
Definition keyring.c:58
WizardExport ssize_t FormatLocaleString(char *string, const size_t length, const char *format,...)
Definition locale.c:465
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition log.c:1390
@ TraceEvent
Definition log.h:39
#define GetWizardModule()
Definition log.h:30
WizardExport StringInfo * GetWizardMagick(const unsigned char *signature, const size_t length)
Definition magick.c:88
unsigned char WizardMagick[4]
Definition magick.c:56
WizardExport void * AcquireWizardMemory(const size_t size)
Definition memory.c:586
WizardExport void * RelinquishWizardMemory(void *memory)
Definition memory.c:1039
#define WizardExport
#define WizardPathExtent
#define WizardSignature
WizardExport char * CloneString(char **destination, const char *source)
Definition string.c:280
WizardExport char * DestroyString(char *string)
Definition string.c:830
WizardExport char * StringInfoToHexString(const StringInfo *string_info)
Definition string.c:1977
WizardExport char * ConstantString(const char *source)
Definition string.c:655
WizardExport size_t GetStringInfoLength(const StringInfo *string_info)
Definition string.c:1280
WizardExport StringInfo * AcquireStringInfo(const size_t length)
Definition string.c:179
WizardExport int CompareStringInfo(const StringInfo *target, const StringInfo *source)
Definition string.c:372
WizardExport StringInfo * CloneStringInfo(const StringInfo *string_info)
Definition string.c:332
WizardExport char * AcquireString(const char *source)
Definition string.c:133
WizardExport WizardBooleanType ConcatenateString(char **destination, const char *source)
Definition string.c:417
WizardExport ssize_t FormatWizardTime(const time_t time, const size_t length, char *timestamp)
Definition string.c:1105
WizardExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
Definition string.c:1251
WizardExport StringInfo * DestroyStringInfo(StringInfo *string_info)
Definition string.c:857
StringInfo * key
Definition keyring.c:72
size_t signature
Definition keyring.c:83
StringInfo * id
Definition keyring.c:71
unsigned short protocol_major
Definition keyring.c:76
unsigned short protocol_minor
Definition keyring.c:77
char * path
Definition keyring.c:68
time_t timestamp
Definition keyring.c:80
StringInfo * nonce
Definition keyring.c:73
size_t WizardSizeType
Definition wizard-type.h:51
ssize_t WizardOffsetType
Definition wizard-type.h:50
WizardBooleanType
Definition wizard-type.h:26
@ WizardTrue
Definition wizard-type.h:28
@ WizardFalse
Definition wizard-type.h:27
unsigned int WizardStatusType
Definition wizard-type.h:42
WizardExport char * CanonicalXMLContent(const char *content, const WizardBooleanType pedantic)
Definition xml-tree.c:337