Rizin
unix-like reverse engineering framework and cli tools
pkcs7.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2017-2018 deroad <wargio@libero.it>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <stdlib.h>
5 #include <string.h>
6 #include <rz_util.h>
7 #include "./x509.h"
8 
9 extern void rz_x509_name_json(PJ *pj, RX509Name *name);
11 extern void rz_x509_crlentry_dump(RX509CRLEntry *crle, const char *pad, RzStrBuf *sb);
12 static bool rz_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object);
13 
15  if (!ci || !object || object->list.length < 1 || !object->list.objects[0]) {
16  return false;
17  }
18  ci->contentType = rz_asn1_stringify_oid(object->list.objects[0]->sector, object->list.objects[0]->length);
19  if (object->list.length > 1) {
20  RASN1Object *obj1 = object->list.objects[1];
21  if (obj1) {
22  ci->content = rz_asn1_create_binary(obj1->sector, obj1->length);
23  }
24  }
25  return true;
26 }
27 
29  ut32 i;
30  if (!crls || !object) {
31  return false;
32  }
33  if (object->list.length > 0) {
35  if (!crls->elements) {
36  return false;
37  }
38  crls->length = object->list.length;
39  for (i = 0; i < crls->length; i++) {
40  crls->elements[i] = rz_x509_parse_crl(object->list.objects[i]);
41  }
42  }
43  return true;
44 }
45 
47  ut32 i;
48  if (crls) {
49  for (i = 0; i < crls->length; i++) {
50  rz_x509_free_crl(crls->elements[i]);
51  crls->elements[i] = NULL;
52  }
53  RZ_FREE(crls->elements);
54  // Used internally pkcs #7, so it shouldn't free crls.
55  }
56 }
57 
59  ut32 i;
60  if (!ecac || !object) {
61  return false;
62  }
63  if (object->list.length > 0) {
64  ecac->elements = (RX509Certificate **)calloc(object->list.length, sizeof(RX509Certificate *));
65  if (!ecac->elements) {
66  return false;
67  }
68  ecac->length = object->list.length;
69  for (i = 0; i < ecac->length; i++) {
70  ecac->elements[i] = rz_x509_parse_certificate(object->list.objects[i]);
71  object->list.objects[i] = NULL;
72  }
73  }
74  return true;
75 }
76 
78  ut32 i;
79  if (ecac) {
80  for (i = 0; i < ecac->length; i++) {
82  ecac->elements[i] = NULL;
83  }
84  RZ_FREE(ecac->elements);
85  // Used internally pkcs #7, so it shouldn't free ecac.
86  }
87 }
88 
90  ut32 i;
91  if (!dai || !object) {
92  return false;
93  }
94  if (object->list.length > 0) {
96  if (!dai->elements) {
97  return false;
98  }
99  dai->length = object->list.length;
100  for (i = 0; i < dai->length; i++) {
101  // rz_x509_parse_algorithmidentifier returns bool,
102  // so i have to allocate before calling the function
104  // should i handle invalid memory? the function checks the pointer
105  // or it should return if dai->elements[i] == NULL ?
106  if (dai->elements[i]) {
107  // Memset is needed to initialize to 0 the structure and avoid garbage.
108  memset(dai->elements[i], 0, sizeof(RX509AlgorithmIdentifier));
110  }
111  }
112  }
113  return true;
114 }
115 
117  ut32 i;
118  if (dai) {
119  for (i = 0; i < dai->length; i++) {
120  if (dai->elements[i]) {
122  // rz_x509_free_algorithmidentifier doesn't free the pointer
123  // because on x509 the original use was internal.
124  RZ_FREE(dai->elements[i]);
125  }
126  }
127  RZ_FREE(dai->elements);
128  // Used internally pkcs #7, so it shouldn't free dai.
129  }
130 }
131 
133  if (ci) {
136  // Used internally pkcs #7, so it shouldn't free ci.
137  }
138 }
139 
141  if (!iasu || !object || object->list.length != 2) {
142  return false;
143  }
144  rz_x509_parse_name(&iasu->issuer, object->list.objects[0]);
145  RASN1Object *obj1 = object->list.objects[1];
146  if (obj1) {
147  iasu->serialNumber = rz_asn1_create_binary(obj1->sector, obj1->length);
148  }
149  return true;
150 }
151 
153  if (iasu) {
154  rz_x509_free_name(&iasu->issuer);
156  // Used internally pkcs #7, so it shouldn't free iasu.
157  }
158 }
159 
160 /*
161  RX509AlgorithmIdentifier digestEncryptionAlgorithm;
162  RASN1Object *encryptedDigest;
163  RASN1Object *unauthenticatedAttributes; //Optional type ??
164 } RPKCS7SignerInfo;
165  */
166 
168  RASN1Object **elems;
169  ut32 shift = 3;
170  if (!si || !object || object->list.length < 5) {
171  return false;
172  }
173  elems = object->list.objects;
174  // Following RFC
175  si->version = (ut32)elems[0]->sector[0];
176  rz_pkcs7_parse_issuerandserialnumber(&si->issuerAndSerialNumber, elems[1]);
177  rz_x509_parse_algorithmidentifier(&si->digestAlgorithm, elems[2]);
178  if (shift < object->list.length && elems[shift]->klass == CLASS_CONTEXT && elems[shift]->tag == 0) {
179  rz_pkcs7_parse_attributes(&si->authenticatedAttributes, elems[shift]);
180  shift++;
181  }
182  if (shift < object->list.length) {
183  rz_x509_parse_algorithmidentifier(&si->digestEncryptionAlgorithm, elems[shift]);
184  shift++;
185  }
186  if (shift < object->list.length) {
187  RASN1Object *obj1 = object->list.objects[shift];
188  if (obj1) {
189  si->encryptedDigest = rz_asn1_create_binary(obj1->sector, obj1->length);
190  shift++;
191  }
192  }
193  if (shift < object->list.length) {
194  RASN1Object *elem = elems[shift];
195  if (elem && elem->klass == CLASS_CONTEXT && elem->tag == 1) {
196  rz_pkcs7_parse_attributes(&si->unauthenticatedAttributes, elems[shift]);
197  }
198  }
199  return true;
200 }
201 
202 static void rz_pkcs7_free_attribute(RPKCS7Attribute *attribute) {
203  if (attribute) {
204  rz_asn1_free_binary(attribute->data);
205  rz_asn1_free_string(attribute->oid);
206  free(attribute);
207  }
208 }
209 
210 static void rz_pkcs7_free_attributes(RPKCS7Attributes *attributes) {
211  ut32 i;
212  if (attributes) {
213  for (i = 0; i < attributes->length; i++) {
214  rz_pkcs7_free_attribute(attributes->elements[i]);
215  }
216  RZ_FREE(attributes->elements);
217  // Used internally pkcs #7, so it shouldn't free attributes.
218  }
219 }
220 
222  if (si) {
223  rz_pkcs7_free_issuerandserialnumber(&si->issuerAndSerialNumber);
224  rz_x509_free_algorithmidentifier(&si->digestAlgorithm);
225  rz_pkcs7_free_attributes(&si->authenticatedAttributes);
226  rz_x509_free_algorithmidentifier(&si->digestEncryptionAlgorithm);
227  rz_asn1_free_binary(si->encryptedDigest);
228  rz_pkcs7_free_attributes(&si->unauthenticatedAttributes);
229  free(si);
230  }
231 }
232 
234  ut32 i;
235  if (!ss || !object) {
236  return false;
237  }
238  if (object->list.length > 0) {
239  ss->elements = (RPKCS7SignerInfo **)calloc(object->list.length, sizeof(RPKCS7SignerInfo *));
240  if (!ss->elements) {
241  return false;
242  }
243  ss->length = object->list.length;
244  for (i = 0; i < ss->length; i++) {
245  // rz_pkcs7_parse_signerinfo returns bool,
246  // so i have to allocate before calling the function
248  // should i handle invalid memory? the function checks the pointer
249  // or it should return if si->elements[i] == NULL ?
251  }
252  }
253  return true;
254 }
255 
257  ut32 i;
258  if (ss) {
259  for (i = 0; i < ss->length; i++) {
261  ss->elements[i] = NULL;
262  }
263  RZ_FREE(ss->elements);
264  // Used internally pkcs #7, so it shouldn't free ss.
265  }
266 }
267 
269  ut32 shift = 3;
270  if (!sd || !object || object->list.length < 4) {
271  return false;
272  }
273  memset(sd, 0, sizeof(RPKCS7SignedData));
274  RASN1Object **elems = object->list.objects;
275  // Following RFC
276  sd->version = (ut32)elems[0]->sector[0];
278  rz_pkcs7_parse_contentinfo(&sd->contentInfo, elems[2]);
279  // Optional
280  if (object->list.length > 3 && shift < object->list.length && elems[shift] &&
281  elems[shift]->klass == CLASS_CONTEXT && elems[shift]->tag == 0) {
283  shift++;
284  }
285  // Optional
286  if (object->list.length > 3 && shift < object->list.length && elems[shift] &&
287  elems[shift]->klass == CLASS_CONTEXT && elems[shift]->tag == 1) {
289  shift++;
290  }
291  if (shift < object->list.length) {
293  }
294  return true;
295 }
296 
298  if (sd) {
304  // Used internally pkcs #7, so it shouldn't free sd.
305  }
306 }
307 
309  RASN1Object *object;
310  RCMS *container;
311  if (!buffer || !length) {
312  return NULL;
313  }
314  container = RZ_NEW0(RCMS);
315  if (!container) {
316  return NULL;
317  }
319  if (!object || object->list.length < 2 || !object->list.objects ||
320  !object->list.objects[0] || !object->list.objects[1] ||
321  object->list.objects[1]->list.length < 1) {
322  rz_asn1_free_object(object);
323  free(container);
324  return NULL;
325  }
326  if (object->list.objects[0]) {
327  container->contentType = rz_asn1_stringify_oid(object->list.objects[0]->sector, object->list.objects[0]->length);
328  if (!container->contentType) {
329  rz_asn1_free_object(object);
330  free(container);
331  return NULL;
332  }
333  }
334  if (object->list.objects[1]) {
335  rz_pkcs7_parse_signeddata(&container->signedData, object->list.objects[1]->list.objects[0]);
336  }
337  rz_asn1_free_object(object);
338  return container;
339 }
340 
341 RZ_API void rz_pkcs7_free_cms(RCMS *container) {
342  if (container) {
343  rz_asn1_free_string(container->contentType);
345  free(container);
346  }
347 }
348 
350  RPKCS7Attribute *attribute;
351  if (!object || object->list.length < 1) {
352  return NULL;
353  }
354  attribute = RZ_NEW0(RPKCS7Attribute);
355  if (!attribute) {
356  return NULL;
357  }
358  if (object->list.objects[0]) {
359  attribute->oid = rz_asn1_stringify_oid(object->list.objects[0]->sector, object->list.objects[0]->length);
360  }
361  if (object->list.length == 2) {
362  RASN1Object *obj1 = object->list.objects[1];
363  if (obj1) {
364  attribute->data = rz_asn1_create_binary(obj1->sector, obj1->length);
365  }
366  }
367  return attribute;
368 }
369 
370 static bool rz_pkcs7_parse_attributes(RPKCS7Attributes *attributes, RASN1Object *object) {
371  ut32 i;
372  if (!attributes || !object || !object->list.length) {
373  return false;
374  }
375 
376  attributes->length = object->list.length;
377  if (attributes->length > 0) {
378  attributes->elements = RZ_NEWS0(RPKCS7Attribute *, attributes->length);
379  if (!attributes->elements) {
380  attributes->length = 0;
381  return false;
382  }
383  for (i = 0; i < object->list.length; i++) {
384  attributes->elements[i] = rz_pkcs7_parse_attribute(object->list.objects[i]);
385  }
386  }
387  return true;
388 }
389 
390 #if 0
391 // XXX: unused
392 static void rz_pkcs7_signerinfos_dump(RX509CertificateRevocationList *crl, const char* pad, RzStrBuf *sb) {
393  RASN1String *algo = NULL, *last = NULL, *next = NULL;
394  ut32 i;
395  char *pad2, *pad3;
396  if (!crl) {
397  return;
398  }
399  if (!pad) {
400  pad = "";
401  }
402  pad3 = rz_str_newf ("%s ", pad);
403  if (!pad3) return;
404 
405  pad2 = pad3 + 2;
406  algo = crl->signature.algorithm;
407  last = crl->lastUpdate;
408  next = crl->nextUpdate;
409  rz_strbuf_appendf (sb, "%sCRL:\n%sSignature:\n%s%s\n%sIssuer\n", pad, pad2, pad3, algo ? algo->string : "", pad2);
410  rz_x509_name_dump (&crl->issuer, pad3, sb);
411  rz_strbuf_appendf (sb, "%sLast Update: %s\n%sNext Update: %s\n%sRevoked Certificates:\n",
412  pad2, last ? last->string : "Missing",
413  pad2, next ? next->string : "Missing", pad2);
414  for (i = 0; i < crl->length; i++) {
416  }
417  free (pad3);
418 }
419 #endif
420 
422  RASN1String *s = NULL;
423  RASN1Binary *o = NULL;
424  ut32 i;
425  char *pad2, *pad3;
426  if (!si) {
427  return;
428  }
429  if (!pad) {
430  pad = "";
431  }
432  pad3 = rz_str_newf("%s ", pad);
433  if (!pad3) {
434  return;
435  }
436  pad2 = pad3 + 2;
437 
438  rz_strbuf_appendf(sb, "%sSignerInfo:\n%sVersion: v%u\n%sIssuer\n", pad, pad2, si->version + 1, pad2);
439  rz_x509_name_dump(&si->issuerAndSerialNumber.issuer, pad3, sb);
440  if ((o = si->issuerAndSerialNumber.serialNumber)) {
442  }
443  rz_strbuf_appendf(sb, "%sSerial Number:\n%s%s\n", pad2, pad3, s ? s->string : "Missing");
445 
446  s = si->digestAlgorithm.algorithm;
447  rz_strbuf_appendf(sb, "%sDigest Algorithm:\n%s%s\n%sAuthenticated Attributes:\n",
448  pad2, pad3, s ? s->string : "Missing", pad2);
449 
450  for (i = 0; i < si->authenticatedAttributes.length; i++) {
451  RPKCS7Attribute *attr = si->authenticatedAttributes.elements[i];
452  if (!attr) {
453  continue;
454  }
455  rz_strbuf_appendf(sb, "%s%s: %u bytes\n", pad3, attr->oid ? attr->oid->string : "Missing",
456  attr->data ? attr->data->length : 0);
457  }
458  s = si->digestEncryptionAlgorithm.algorithm;
459  rz_strbuf_appendf(sb, "%sDigest Encryption Algorithm\n%s%s\n", pad2, pad3, s ? s->string : "Missing");
460 
461  // if ((o = si->encryptedDigest)) s = rz_asn1_stringify_bytes (o->binary, o->length);
462  // else s = NULL;
463  // eprintf ("%sEncrypted Digest: %u bytes\n%s\n", pad2, o ? o->length : 0, s ? s->string : "Missing");
464  // rz_asn1_free_string (s);
465  rz_strbuf_appendf(sb, "%sEncrypted Digest: %u bytes\n", pad2, o ? o->length : 0);
466  rz_strbuf_appendf(sb, "%sUnauthenticated Attributes:\n", pad2);
467  for (i = 0; i < si->unauthenticatedAttributes.length; i++) {
468  RPKCS7Attribute *attr = si->unauthenticatedAttributes.elements[i];
469  if (!attr) {
470  continue;
471  }
472  o = attr->data;
473  eprintf("%s%s: %u bytes\n", pad3, attr->oid ? attr->oid->string : "Missing",
474  o ? o->length : 0);
475  }
476  free(pad3);
477 }
478 
479 RZ_API char *rz_pkcs7_cms_to_string(RCMS *container) {
480  ut32 i;
481  if (!container) {
482  return NULL;
483  }
484  RPKCS7SignedData *sd = &container->signedData;
485  RzStrBuf *sb = rz_strbuf_new("");
486  rz_strbuf_appendf(sb, "signedData\n Version: v%u\n Digest Algorithms:\n", sd->version);
487 
488  if (container->signedData.digestAlgorithms.elements) {
489  for (i = 0; i < container->signedData.digestAlgorithms.length; i++) {
490  if (container->signedData.digestAlgorithms.elements[i]) {
492  rz_strbuf_appendf(sb, " %s\n", s ? s->string : "Missing");
493  }
494  }
495  }
496 
497  rz_strbuf_appendf(sb, " Certificates: %u\n", container->signedData.certificates.length);
498 
499  for (i = 0; i < container->signedData.certificates.length; i++) {
501  }
502 
503  for (i = 0; i < container->signedData.crls.length; i++) {
504  char *res = rz_x509_crl_to_string(container->signedData.crls.elements[i], " ");
505  if (res) {
506  rz_strbuf_append(sb, res);
507  free(res);
508  }
509  }
510 
511  rz_strbuf_appendf(sb, " SignerInfos:\n");
512  if (container->signedData.signerinfos.elements) {
513  for (i = 0; i < container->signedData.signerinfos.length; i++) {
515  }
516  }
517  return rz_strbuf_drain(sb);
518 }
519 
521  ut32 i;
522  if (si) {
523  pj_o(pj);
524  pj_ki(pj, "Version", si->version + 1);
525  pj_k(pj, "Issuer");
526  pj_o(pj);
527  rz_x509_name_json(pj, &si->issuerAndSerialNumber.issuer);
528  pj_end(pj);
529  if (si->issuerAndSerialNumber.serialNumber) {
530  RASN1Binary *o = si->issuerAndSerialNumber.serialNumber;
532  if (s) {
533  pj_ks(pj, "SerialNumber", s->string);
534  }
536  }
537 
538  if (si->digestAlgorithm.algorithm) {
539  pj_ks(pj, "DigestAlgorithm", si->digestAlgorithm.algorithm->string);
540  }
541  pj_k(pj, "AuthenticatedAttributes");
542  pj_a(pj);
543  for (i = 0; i < si->authenticatedAttributes.length; i++) {
544  RPKCS7Attribute *attr = si->authenticatedAttributes.elements[i];
545  if (!attr) {
546  continue;
547  }
548  pj_o(pj);
549  if (attr->oid) {
550  pj_ks(pj, "oid", attr->oid->string);
551  }
552  if (attr->data) {
553  pj_ki(pj, "length", attr->data->length);
554  }
555  pj_end(pj);
556  }
557  pj_end(pj);
558  if (si->digestEncryptionAlgorithm.algorithm) {
559  pj_ks(pj, "DigestEncryptionAlgorithm", si->digestEncryptionAlgorithm.algorithm->string);
560  }
561 
562  if (si->encryptedDigest) {
563  RASN1Binary *o = si->encryptedDigest;
565  if (s) {
566  pj_ks(pj, "EncryptedDigest", s->string);
567  }
569  }
570 
571  pj_k(pj, "UnauthenticatedAttributes");
572  pj_a(pj);
573  for (i = 0; i < si->unauthenticatedAttributes.length; i++) {
574  RPKCS7Attribute *attr = si->unauthenticatedAttributes.elements[i];
575  if (!attr) {
576  continue;
577  }
578  pj_o(pj);
579  if (attr->oid) {
580  pj_ks(pj, "oid", attr->oid->string);
581  }
582  if (attr->data) {
583  pj_ki(pj, "length", attr->data->length);
584  }
585  pj_end(pj);
586  }
587  pj_end(pj);
588  pj_end(pj);
589  }
590 }
591 
593  PJ *pj = NULL;
594  if (container) {
595  ut32 i;
596 
597  pj = pj_new();
598 
599  pj_o(pj);
600  pj_kn(pj, "Version", container->signedData.version);
601 
602  if (container->signedData.digestAlgorithms.elements) {
603  pj_k(pj, "DigestAlgorithms");
604  pj_a(pj);
605  for (i = 0; i < container->signedData.digestAlgorithms.length; i++) {
606  if (container->signedData.digestAlgorithms.elements[i]) {
608  if (s) {
609  pj_s(pj, s->string);
610  }
611  }
612  }
613  pj_end(pj);
614  }
615 
616  pj_k(pj, "Certificates");
617  pj_a(pj);
618  for (i = 0; i < container->signedData.certificates.length; i++) {
620  }
621  pj_end(pj);
622 
623  pj_k(pj, "CRL");
624  pj_a(pj);
625  for (i = 0; i < container->signedData.crls.length; i++) {
626  rz_x509_crl_json(pj, container->signedData.crls.elements[i]);
627  }
628  pj_end(pj);
629 
630  pj_k(pj, "SignerInfos");
631  pj_a(pj);
632  if (container->signedData.signerinfos.elements) {
633  for (i = 0; i < container->signedData.signerinfos.length; i++) {
635  }
636  }
637  pj_end(pj);
638  pj_end(pj);
639  }
640  return pj;
641 }
642 
644  if (!data || !object || object->list.length < 1 ||
645  !object->list.objects[0]) {
646  return false;
647  }
648  data->type = rz_asn1_stringify_oid(object->list.objects[0]->sector, object->list.objects[0]->length);
649  if (!data->type) {
650  return false;
651  }
652  RASN1Object *obj1 = object->list.objects[1];
653  if (object->list.length > 1) {
654  if (obj1) {
655  data->data = rz_asn1_create_binary(obj1->sector, obj1->length);
656  }
657  }
658  return true;
659 }
660 
661 static bool rz_pkcs7_parse_spcmessagedigest(SpcDigestInfo *messageDigest, RASN1Object *object) {
662  if (!messageDigest || !object || object->list.length < 2 ||
663  !object->list.objects[0] || !object->list.objects[1]) {
664  return false;
665  }
666  if (!rz_x509_parse_algorithmidentifier(&messageDigest->digestAlgorithm, object->list.objects[0])) {
667  return false;
668  }
669  RASN1Object *obj1 = object->list.objects[1];
670  messageDigest->digest = rz_asn1_create_binary(obj1->sector, obj1->length);
671  return true;
672 }
673 
676 
678  if (type && strcmp(type->string, "spcIndirectDataContext")) {
679  return NULL;
680  }
681 
683  if (!spcinfo) {
684  return NULL;
685  }
686 
687  RASN1Binary *content = cms->signedData.contentInfo.content;
688  if (!content) {
689  free(spcinfo);
690  return NULL;
691  }
692  RASN1Object *object = rz_asn1_create_object(content->binary, content->length, content->binary);
693  if (!object || object->list.length < 2 || !object->list.objects ||
694  !object->list.objects[0] || !object->list.objects[1]) {
695  RZ_FREE(spcinfo);
696  goto beach;
697  }
698  if (object->list.objects[0]) {
699  if (!rz_pkcs7_parse_spcdata(&spcinfo->data, object->list.objects[0])) {
700  RZ_FREE(spcinfo);
701  goto beach;
702  }
703  }
704  if (object->list.objects[1]) {
705  if (!rz_pkcs7_parse_spcmessagedigest(&spcinfo->messageDigest, object->list.objects[1])) {
706  RZ_FREE(spcinfo);
707  goto beach;
708  }
709  }
710 beach:
711  rz_asn1_free_object(object);
712  return spcinfo;
713 }
714 
716  if (data) {
717  rz_asn1_free_string(data->type);
718  rz_asn1_free_binary(data->data);
719  }
720 }
721 
722 static void rz_pkcs7_free_spcmessagedigest(SpcDigestInfo *messageDigest) {
723  if (messageDigest) {
724  rz_asn1_free_binary(messageDigest->digest);
726  }
727 }
728 
730  if (spcinfo) {
731  rz_pkcs7_free_spcdata(&spcinfo->data);
733  }
734 }
si
lzma_index ** i
Definition: index.h:629
static RZ_NULLABLE RzILOpBitVector * shift(RzILOpBitVector *val, RZ_NULLABLE RzILOpBool **carry_out, arm_shifter type, RZ_OWN RzILOpBitVector *dist)
Definition: arm_il32.c:190
static SblHeader sb
Definition: bin_mbn.c:26
#define RZ_API
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
static void list(RzEgg *egg)
Definition: rz-gg.c:52
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
int type
Definition: mipsasm.c:17
static void rz_pkcs7_free_spcdata(SpcAttributeTypeAndOptionalValue *data)
Definition: pkcs7.c:715
void rz_x509_crlentry_dump(RX509CRLEntry *crle, const char *pad, RzStrBuf *sb)
Definition: x509.c:573
static void rz_pkcs7_free_attributes(RPKCS7Attributes *attributes)
Definition: pkcs7.c:210
static void rz_pkcs7_free_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu)
Definition: pkcs7.c:152
static bool rz_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object)
Definition: pkcs7.c:370
static void rz_pkcs7_free_signerinfos(RPKCS7SignerInfos *ss)
Definition: pkcs7.c:256
static RPKCS7Attribute * rz_pkcs7_parse_attribute(RASN1Object *object)
Definition: pkcs7.c:349
void rz_x509_name_json(PJ *pj, RX509Name *name)
Definition: x509.c:638
RZ_API RCMS * rz_pkcs7_parse_cms(const ut8 *buffer, ut32 length)
Definition: pkcs7.c:308
static void rz_pkcs7_free_spcmessagedigest(SpcDigestInfo *messageDigest)
Definition: pkcs7.c:722
static bool rz_pkcs7_parse_signeddata(RPKCS7SignedData *sd, RASN1Object *object)
Definition: pkcs7.c:268
RZ_API void rz_pkcs7_free_cms(RCMS *container)
Definition: pkcs7.c:341
static bool rz_pkcs7_parse_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu, RASN1Object *object)
Definition: pkcs7.c:140
static void rz_x509_signedinfo_dump(RPKCS7SignerInfo *si, const char *pad, RzStrBuf *sb)
Definition: pkcs7.c:421
static bool rz_pkcs7_parse_contentinfo(RPKCS7ContentInfo *ci, RASN1Object *object)
Definition: pkcs7.c:14
RZ_API void rz_x509_signedinfo_json(PJ *pj, RPKCS7SignerInfo *si)
Definition: pkcs7.c:520
static bool rz_pkcs7_parse_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai, RASN1Object *object)
Definition: pkcs7.c:89
RZ_API void rz_pkcs7_free_spcinfo(SpcIndirectDataContent *spcinfo)
Definition: pkcs7.c:729
static bool rz_pkcs7_parse_signerinfos(RPKCS7SignerInfos *ss, RASN1Object *object)
Definition: pkcs7.c:233
static void rz_pkcs7_free_signeddata(RPKCS7SignedData *sd)
Definition: pkcs7.c:297
static bool rz_pkcs7_parse_signerinfo(RPKCS7SignerInfo *si, RASN1Object *object)
Definition: pkcs7.c:167
static void rz_pkcs7_free_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac)
Definition: pkcs7.c:77
RZ_API char * rz_pkcs7_cms_to_string(RCMS *container)
Definition: pkcs7.c:479
static bool rz_pkcs7_parse_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac, RASN1Object *object)
Definition: pkcs7.c:58
static void rz_pkcs7_free_contentinfo(RPKCS7ContentInfo *ci)
Definition: pkcs7.c:132
static void rz_pkcs7_free_attribute(RPKCS7Attribute *attribute)
Definition: pkcs7.c:202
static void rz_pkcs7_free_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai)
Definition: pkcs7.c:116
static bool rz_pkcs7_parse_spcdata(SpcAttributeTypeAndOptionalValue *data, RASN1Object *object)
Definition: pkcs7.c:643
RZ_API SpcIndirectDataContent * rz_pkcs7_parse_spcinfo(RCMS *cms)
Definition: pkcs7.c:674
static void rz_pkcs7_free_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls)
Definition: pkcs7.c:46
static bool rz_pkcs7_parse_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls, RASN1Object *object)
Definition: pkcs7.c:28
void rz_x509_free_crl(RX509CertificateRevocationList *crl)
Definition: x509.c:404
static bool rz_pkcs7_parse_spcmessagedigest(SpcDigestInfo *messageDigest, RASN1Object *object)
Definition: pkcs7.c:661
RZ_API PJ * rz_pkcs7_cms_json(RCMS *container)
Definition: pkcs7.c:592
static void rz_pkcs7_free_signerinfo(RPKCS7SignerInfo *si)
Definition: pkcs7.c:221
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
#define eprintf(x, y...)
Definition: rlcc.c:7
static RzSocket * s
Definition: rtr.c:28
RZ_API void rz_asn1_free_object(RASN1Object *object)
Definition: asn1.c:445
RZ_API void rz_asn1_free_string(RASN1String *string)
Definition: astr.c:313
RZ_API void rz_asn1_free_binary(RASN1Binary *string)
Definition: asn1.c:463
RZ_API RASN1Binary * rz_asn1_create_binary(const ut8 *buffer, ut32 length)
Definition: asn1.c:152
RZ_API RASN1String * rz_asn1_stringify_integer(const ut8 *buffer, ut32 length)
Definition: astr.c:185
RZ_API RASN1Object * rz_asn1_create_object(const ut8 *buffer, ut32 length, const ut8 *start_pointer)
Definition: asn1.c:120
RZ_API RASN1String * rz_asn1_stringify_oid(const ut8 *buffer, ut32 length)
Definition: astr.c:249
#define CLASS_CONTEXT
Definition: rz_asn1.h:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_s(PJ *j, const char *k)
Definition: pj.c:197
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
#define RZ_FREE(x)
Definition: rz_types.h:369
RZ_API void rz_x509_crl_json(PJ *pj, RX509CertificateRevocationList *crl)
Definition: x509.c:719
RZ_API void rz_x509_free_certificate(RX509Certificate *certificate)
Definition: x509.c:387
RZ_API RX509CertificateRevocationList * rz_x509_parse_crl(RASN1Object *object)
Definition: x509.c:275
RZ_API RX509Certificate * rz_x509_parse_certificate(RASN1Object *object)
Definition: x509.c:217
RZ_API void rz_x509_certificate_dump(RX509Certificate *cert, const char *pad, RzStrBuf *sb)
Definition: x509.c:546
RZ_API char * rz_x509_crl_to_string(RX509CertificateRevocationList *crl, const char *pad)
Definition: x509.c:592
RZ_API void rz_x509_certificate_json(PJ *pj, RX509Certificate *certificate)
Definition: x509.c:790
RASN1Binary * digest
Definition: rz_pkcs7.h:81
RX509AlgorithmIdentifier digestAlgorithm
Definition: rz_pkcs7.h:80
SpcAttributeTypeAndOptionalValue data
Definition: rz_pkcs7.h:85
SpcDigestInfo messageDigest
Definition: rz_pkcs7.h:86
Definition: buffer.h:15
Definition: z80asm.h:102
Definition: rz_pj.h:12
ut32 length
Definition: rz_asn1.h:75
ut8 * binary
Definition: rz_asn1.h:76
ut32 length
Definition: rz_asn1.h:70
struct rz_asn1_object_t ** objects
Definition: rz_asn1.h:71
ASN1List list
Definition: rz_asn1.h:86
const ut8 * sector
Definition: rz_asn1.h:83
const char * string
Definition: rz_asn1.h:65
RASN1Binary * data
Definition: rz_pkcs7.h:37
RASN1String * oid
Definition: rz_pkcs7.h:36
RPKCS7Attribute ** elements
Definition: rz_pkcs7.h:42
RX509CertificateRevocationList ** elements
Definition: rz_pkcs7.h:12
RPKCS7SignedData signedData
Definition: rz_pkcs7.h:71
RASN1String * contentType
Definition: rz_pkcs7.h:70
RASN1Binary * content
Definition: rz_pkcs7.h:27
RASN1String * contentType
Definition: rz_pkcs7.h:26
RX509AlgorithmIdentifier ** elements
Definition: rz_pkcs7.h:22
RPKCS7DigestAlgorithmIdentifiers digestAlgorithms
Definition: rz_pkcs7.h:62
RPKCS7ExtendedCertificatesAndCertificates certificates
Definition: rz_pkcs7.h:64
RPKCS7CertificateRevocationLists crls
Definition: rz_pkcs7.h:65
RPKCS7SignerInfos signerinfos
Definition: rz_pkcs7.h:66
RPKCS7ContentInfo contentInfo
Definition: rz_pkcs7.h:63
RPKCS7SignerInfo ** elements
Definition: rz_pkcs7.h:57
RASN1String * algorithm
Definition: rz_x509.h:27
RX509AlgorithmIdentifier signature
Definition: rz_x509.h:101
RX509CRLEntry ** revokedCertificates
Definition: rz_x509.h:106
RZ_API void rz_x509_name_dump(RX509Name *name, const char *pad, RzStrBuf *sb)
Definition: x509.c:434
RZ_API void rz_x509_free_algorithmidentifier(RX509AlgorithmIdentifier *ai)
Definition: x509.c:306
RZ_API void rz_x509_free_name(RX509Name *name)
Definition: x509.c:322
RZ_API bool rz_x509_parse_name(RX509Name *name, RASN1Object *object)
Definition: x509.c:79
RZ_API bool rz_x509_parse_algorithmidentifier(RX509AlgorithmIdentifier *ai, RASN1Object *object)
Definition: x509.c:44