Rizin
unix-like reverse engineering framework and cli tools
x509.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 <rz_util.h>
5 #include <rz_cons.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include "./x509.h"
9 
10 static bool rz_x509_parse_validity(RX509Validity *validity, RASN1Object *object) {
11  RASN1Object *o;
12  if (!validity || !object || object->list.length != 2) {
13  return false;
14  }
15  if (object->klass == CLASS_UNIVERSAL &&
16  object->tag == TAG_SEQUENCE &&
17  object->form == FORM_CONSTRUCTED) {
18  o = object->list.objects[0];
19  if (o->klass == CLASS_UNIVERSAL && o->form == FORM_PRIMITIVE) {
20  if (o->tag == TAG_UTCTIME) {
22  } else if (o->tag == TAG_GENERALIZEDTIME) {
23  validity->notBefore = rz_asn1_stringify_time(o->sector, o->length);
24  }
25  }
26  o = object->list.objects[1];
27  if (o->klass == CLASS_UNIVERSAL && o->form == FORM_PRIMITIVE) {
28  if (o->tag == TAG_UTCTIME) {
29  validity->notAfter = rz_asn1_stringify_utctime(o->sector, o->length);
30  } else if (o->tag == TAG_GENERALIZEDTIME) {
31  validity->notAfter = rz_asn1_stringify_time(o->sector, o->length);
32  }
33  }
34  }
35  return true;
36 }
37 
38 static inline bool is_oid_object(RASN1Object *object) {
39  return object->list.objects[0] &&
40  object->list.objects[0]->klass == CLASS_UNIVERSAL &&
41  object->list.objects[0]->tag == TAG_OID;
42 }
43 
45  rz_return_val_if_fail(ai && object, false);
46 
47  if (object->list.length < 1 || !object->list.objects || !is_oid_object(object)) {
48  return false;
49  }
50 
51  ai->algorithm = rz_asn1_stringify_oid(object->list.objects[0]->sector, object->list.objects[0]->length);
52  ai->parameters = NULL; // TODO
53  // ai->parameters = asn1_stringify_sector (object->list.objects[1]);
54  return true;
55 }
56 
58  RASN1Object *o;
59  if (!spki || !object || object->list.length != 2) {
60  return false;
61  }
63  if (object->list.objects[1]) {
64  o = object->list.objects[1];
66  if (o->list.length == 1 && o->list.objects[0] && o->list.objects[0]->list.length == 2) {
67  o = o->list.objects[0];
68  if (o->list.objects[0]) {
70  }
71  if (o->list.objects[1]) {
73  }
74  }
75  }
76  return true;
77 }
78 
80  ut32 i;
81  if (!name || !object || !object->list.length) {
82  return false;
83  }
84  if (object->klass == CLASS_UNIVERSAL && object->tag == TAG_SEQUENCE) {
85  name->length = object->list.length;
86  name->names = (RASN1String **)calloc(name->length, sizeof(RASN1String *));
87  if (!name->names) {
88  name->length = 0;
89  return false;
90  }
91  name->oids = (RASN1String **)calloc(name->length, sizeof(RASN1String *));
92  if (!name->oids) {
93  name->length = 0;
94  RZ_FREE(name->names);
95  return false;
96  }
97  for (i = 0; i < object->list.length; i++) {
98  RASN1Object *o = object->list.objects[i];
99  if (o && o->klass == CLASS_UNIVERSAL &&
100  o->tag == TAG_SET &&
101  o->form == FORM_CONSTRUCTED &&
102  o->list.length == 1) {
103  o = o->list.objects[0];
104  if (o && o->list.length > 1 &&
105  o->klass == CLASS_UNIVERSAL &&
106  o->tag == TAG_SEQUENCE) {
107  if (o->list.objects[0]->klass == CLASS_UNIVERSAL &&
108  o->list.objects[0]->tag == TAG_OID) {
109  name->oids[i] = rz_asn1_stringify_oid(o->list.objects[0]->sector, o->list.objects[0]->length);
110  }
111  RASN1Object *obj1 = o->list.objects[1];
112  if (obj1 && obj1->klass == CLASS_UNIVERSAL) {
113  name->names[i] = rz_asn1_stringify_string(obj1->sector, obj1->length);
114  }
115  }
116  }
117  }
118  }
119  return true;
120 }
121 
123  RASN1Object *o;
124  if (!ext || !object || object->list.length < 2) {
125  return false;
126  }
127  o = object->list.objects[0];
128  if (o && o->tag == TAG_OID) {
129  ext->extnID = rz_asn1_stringify_oid(o->sector, o->length);
130  o = object->list.objects[1];
131  if (o->tag == TAG_BOOLEAN && object->list.length > 2) {
132  // This field is optional (so len must be 3)
133  ext->critical = o->sector[0] != 0;
134  o = object->list.objects[2];
135  }
136  if (o->tag == TAG_OCTETSTRING) {
137  ext->extnValue = rz_asn1_create_binary(o->sector, o->length);
138  }
139  }
140  return true;
141 }
142 
144  ut32 i;
145  if (!ext || !object || object->list.length != 1 || !object->list.objects[0]->length) {
146  return false;
147  }
148  object = object->list.objects[0];
149  ext->extensions = (RX509Extension **)calloc(object->list.length, sizeof(RX509Extension *));
150  if (!ext->extensions) {
151  return false;
152  }
153  ext->length = object->list.length;
154  for (i = 0; i < object->list.length; i++) {
155  ext->extensions[i] = RZ_NEW0(RX509Extension);
156  if (!rz_x509_parse_extension(ext->extensions[i], object->list.objects[i])) {
157  rz_x509_free_extension(ext->extensions[i]);
158  ext->extensions[i] = NULL;
159  }
160  }
161  return true;
162 }
163 
165  RASN1Object **elems;
166  ut32 i;
167  ut32 shift = 0;
168  if (!tbsc || !object || object->list.length < 6) {
169  return false;
170  }
171  elems = object->list.objects;
172  // Following RFC
173  if (elems[0]->list.length == 1 &&
174  elems[0]->klass == CLASS_CONTEXT &&
175  elems[0]->form == FORM_CONSTRUCTED &&
176  elems[0]->list.objects[0]->tag == TAG_INTEGER &&
177  elems[0]->list.objects[0]->length == 1) {
178  // Integer inside a CLASS_CONTEXT
179  tbsc->version = (ut32)elems[0]->list.objects[0]->sector[0];
180  shift = 1;
181  } else {
182  tbsc->version = 0;
183  }
184  if (shift < object->list.length && elems[shift]->klass == CLASS_UNIVERSAL && elems[shift]->tag == TAG_INTEGER) {
185  tbsc->serialNumber = rz_asn1_stringify_integer(elems[shift]->sector, elems[shift]->length);
186  }
188  rz_x509_parse_name(&tbsc->issuer, elems[shift + 2]);
189  rz_x509_parse_validity(&tbsc->validity, elems[shift + 3]);
190  rz_x509_parse_name(&tbsc->subject, elems[shift + 4]);
192  if (tbsc->version > 0) {
193  for (i = shift + 6; i < object->list.length; i++) {
194  if (!elems[i] || elems[i]->klass != CLASS_CONTEXT) {
195  continue;
196  }
197  if (elems[i]->tag == 1) {
199  }
200  if (!elems[i]) {
201  continue;
202  }
203  if (elems[i]->tag == 2) {
205  }
206  if (!elems[i]) {
207  continue;
208  }
209  if (tbsc->version == 2 && elems[i]->tag == 3 && elems[i]->form == FORM_CONSTRUCTED) {
210  rz_x509_parse_extensions(&tbsc->extensions, elems[i]);
211  }
212  }
213  }
214  return true;
215 }
216 
218  if (!object) {
219  return NULL;
220  }
222  if (!cert) {
223  goto fail;
224  }
225  if (object->klass != CLASS_UNIVERSAL || object->form != FORM_CONSTRUCTED || object->list.length != 3) {
226  RZ_FREE(cert);
227  goto fail;
228  }
229  RASN1Object *tmp = object->list.objects[2];
230  if (!tmp) {
231  RZ_FREE(cert);
232  goto fail;
233  }
234  if (tmp->klass != CLASS_UNIVERSAL || tmp->form != FORM_PRIMITIVE || tmp->tag != TAG_BITSTRING) {
235  RZ_FREE(cert);
236  goto fail;
237  }
238  cert->signature = rz_asn1_create_binary(object->list.objects[2]->sector, object->list.objects[2]->length);
240 
242  RZ_FREE(cert);
243  }
244 fail:
245  rz_asn1_free_object(object);
246  return cert;
247 }
248 
250  RX509Certificate *certificate;
251  RASN1Object *object;
252  if (!buffer || !length) {
253  return NULL;
254  }
256  certificate = rz_x509_parse_certificate(object);
257  // object freed by rz_x509_parse_certificate
258  return certificate;
259 }
260 
263  if (!object || object->list.length != 2) {
264  return NULL;
265  }
266  entry = (RX509CRLEntry *)malloc(sizeof(RX509CRLEntry));
267  if (!entry) {
268  return NULL;
269  }
270  entry->userCertificate = rz_asn1_create_binary(object->list.objects[0]->sector, object->list.objects[0]->length);
271  entry->revocationDate = rz_asn1_stringify_utctime(object->list.objects[1]->sector, object->list.objects[1]->length);
272  return entry;
273 }
274 
277  RASN1Object **elems;
278  if (!object || object->list.length < 4) {
279  return NULL;
280  }
282  if (!crl) {
283  return NULL;
284  }
285  memset(crl, 0, sizeof(RX509CertificateRevocationList));
286  elems = object->list.objects;
288  rz_x509_parse_name(&crl->issuer, elems[1]);
289  crl->lastUpdate = rz_asn1_stringify_utctime(elems[2]->sector, elems[2]->length);
290  crl->nextUpdate = rz_asn1_stringify_utctime(elems[3]->sector, elems[3]->length);
291  if (object->list.length > 4 && object->list.objects[4]) {
292  ut32 i;
293  crl->revokedCertificates = calloc(object->list.objects[4]->list.length, sizeof(RX509CRLEntry *));
294  if (!crl->revokedCertificates) {
295  free(crl);
296  return NULL;
297  }
298  crl->length = object->list.objects[4]->list.length;
299  for (i = 0; i < object->list.objects[4]->list.length; i++) {
301  }
302  }
303  return crl;
304 }
305 
307  if (ai) {
308  // no need to free ai, since this functions is used internally
311  }
312 }
313 
314 static void rz_x509_free_validity(RX509Validity *validity) {
315  if (validity) {
316  // not freeing validity since it's not allocated dinamically
317  rz_asn1_free_string(validity->notAfter);
318  rz_asn1_free_string(validity->notBefore);
319  }
320 }
321 
323  ut32 i;
324  if (!name) {
325  return;
326  }
327  if (name->names) {
328  for (i = 0; i < name->length; i++) {
329  rz_asn1_free_string(name->oids[i]);
330  rz_asn1_free_string(name->names[i]);
331  }
332  RZ_FREE(name->names);
333  RZ_FREE(name->oids);
334  }
335  // not freeing name since it's not allocated dinamically
336 }
337 
339  if (ex) {
340  rz_asn1_free_string(ex->extnID);
341  rz_asn1_free_binary(ex->extnValue);
342  // this is allocated dinamically so, i'll free
343  free(ex);
344  }
345 }
346 
348  ut32 i;
349  if (!ex) {
350  return;
351  }
352  if (ex->extensions) {
353  for (i = 0; i < ex->length; i++) {
354  rz_x509_free_extension(ex->extensions[i]);
355  }
356  free(ex->extensions);
357  }
358  // no need to free ex, since this functions is used internally
359 }
360 
362  if (spki) {
367  // No need to free spki, since it's a static variable.
368  }
369 }
370 
372  if (tbsc) {
373  // version is ut32
376  rz_x509_free_name(&tbsc->issuer);
378  rz_x509_free_name(&tbsc->subject);
383  // no need to free tbsc, since this functions is used internally
384  }
385 }
386 
388  if (certificate) {
389  rz_asn1_free_binary(certificate->signature);
392  free(certificate);
393  }
394 }
395 
397  if (entry) {
398  rz_asn1_free_binary(entry->userCertificate);
399  rz_asn1_free_string(entry->revocationDate);
400  free(entry);
401  }
402 }
403 
405  ut32 i;
406  if (crl) {
408  rz_x509_free_name(&crl->issuer);
411  if (crl->revokedCertificates) {
412  for (i = 0; i < crl->length; i++) {
414  crl->revokedCertificates[i] = NULL;
415  }
417  }
418  free(crl);
419  }
420 }
421 
422 static void rz_x509_validity_dump(RX509Validity *validity, const char *pad, RzStrBuf *sb) {
423  if (!validity) {
424  return;
425  }
426  if (!pad) {
427  pad = "";
428  }
429  const char *b = validity->notBefore ? validity->notBefore->string : "Missing";
430  const char *a = validity->notAfter ? validity->notAfter->string : "Missing";
431  rz_strbuf_appendf(sb, "%sNot Before: %s\n%sNot After: %s\n", pad, b, pad, a);
432 }
433 
435  ut32 i;
436  if (!name) {
437  return;
438  }
439  if (!pad) {
440  pad = "";
441  }
442  for (i = 0; i < name->length; i++) {
443  if (!name->oids[i] || !name->names[i]) {
444  continue;
445  }
446  rz_strbuf_appendf(sb, "%s%s: %s\n", pad, name->oids[i]->string, name->names[i]->string);
447  }
448 }
449 
451  const char *a;
452  if (!spki) {
453  return;
454  }
455  if (!pad) {
456  pad = "";
457  }
458  a = spki->algorithm.algorithm ? spki->algorithm.algorithm->string : "Missing";
459  RASN1String *m = NULL;
460  if (spki->subjectPublicKeyModule) {
462  }
463  // RASN1String* e = rz_asn1_stringify_bytes (spki->subjectPublicKeyExponent->sector, spki->subjectPublicKeyExponent->length);
464  // r = snprintf (buffer, length, "%sAlgorithm: %s\n%sModule: %s\n%sExponent: %u bytes\n%s\n", pad, a, pad, m->string,
465  // pad, spki->subjectPublicKeyExponent->length - 1, e->string);
466  rz_strbuf_appendf(sb, "%sAlgorithm: %s\n%sModule: %s\n%sExponent: %u bytes\n", pad, a, pad, m ? m->string : "Missing",
469  // rz_asn1_free_string (e);
470 }
471 
472 static void rz_x509_extensions_dump(RX509Extensions *exts, const char *pad, RzStrBuf *sb) {
473  ut32 i;
474  if (!exts) {
475  return;
476  }
477  if (!pad) {
478  pad = "";
479  }
480  for (i = 0; i < exts->length; i++) {
481  RX509Extension *e = exts->extensions[i];
482  if (!e) {
483  continue;
484  }
485  // TODO handle extensions..
486  // s = rz_asn1_stringify_bytes (e->extnValue->sector, e->extnValue->length);
487  rz_strbuf_appendf(sb, "%s%s: %s\n%s%u bytes\n", pad,
488  e->extnID ? e->extnID->string : "Missing",
489  e->critical ? "critical" : "",
490  pad, e->extnValue ? e->extnValue->length : 0);
491  // rz_asn1_free_string (s);
492  }
493 }
494 
495 static void rz_x509_tbscertificate_dump(RX509TBSCertificate *tbsc, const char *pad, RzStrBuf *sb) {
496  RASN1String *sid = NULL, *iid = NULL;
497  if (!tbsc) {
498  return;
499  }
500  if (!pad) {
501  pad = "";
502  }
503  char *pad2 = rz_str_newf("%s ", pad);
504  if (!pad2) {
505  return;
506  }
507  rz_strbuf_appendf(sb, "%sVersion: v%u\n"
508  "%sSerial Number:\n%s %s\n"
509  "%sSignature Algorithm:\n%s %s\n"
510  "%sIssuer:\n",
511  pad, tbsc->version + 1,
512  pad, pad, tbsc->serialNumber ? tbsc->serialNumber->string : "Missing",
513  pad, pad, tbsc->signature.algorithm ? tbsc->signature.algorithm->string : "Missing",
514  pad);
515  rz_x509_name_dump(&tbsc->issuer, pad2, sb);
516 
517  rz_strbuf_appendf(sb, "%sValidity:\n", pad);
518  rz_x509_validity_dump(&tbsc->validity, pad2, sb);
519 
520  rz_strbuf_appendf(sb, "%sSubject:\n", pad);
521  rz_x509_name_dump(&tbsc->subject, pad2, sb);
522 
523  rz_strbuf_appendf(sb, "%sSubject Public Key Info:\n", pad);
525 
526  if (tbsc->issuerUniqueID) {
528  if (iid) {
529  rz_strbuf_appendf(sb, "%sIssuer Unique ID:\n%s %s", pad, pad, iid->string);
530  rz_asn1_free_string(iid);
531  }
532  }
533  if (tbsc->subjectUniqueID) {
535  if (sid) {
536  rz_strbuf_appendf(sb, "%sSubject Unique ID:\n%s %s", pad, pad, sid->string);
537  rz_asn1_free_string(sid);
538  }
539  }
540 
541  rz_strbuf_appendf(sb, "%sExtensions:\n", pad);
542  rz_x509_extensions_dump(&tbsc->extensions, pad2, sb);
543  free(pad2);
544 }
545 
547  RASN1String *algo = NULL;
548  char *pad2;
549  if (!cert) {
550  return;
551  }
552  if (!pad) {
553  pad = "";
554  }
555  pad2 = rz_str_newf("%s ", pad);
556  if (!pad2) {
557  return;
558  }
559  rz_strbuf_appendf(sb, "%sTBSCertificate:\n", pad);
561 
562  algo = cert->algorithmIdentifier.algorithm;
563  // signature = rz_asn1_stringify_bytes (certificate->signature->binary, certificate->signature->length);
564  // eprintf ("%sAlgorithm:\n%s%s\n%sSignature: %u bytes\n%s\n",
565  // pad, pad2, algo ? algo->string : "",
566  // pad, certificate->signature->length, signature ? signature->string : "");
567  rz_strbuf_appendf(sb, "%sAlgorithm:\n%s%s\n%sSignature: %u bytes\n",
568  pad, pad2, algo ? algo->string : "", pad, cert->signature->length);
569  free(pad2);
570  // rz_asn1_free_string (signature);
571 }
572 
573 void rz_x509_crlentry_dump(RX509CRLEntry *crle, const char *pad, RzStrBuf *sb) {
574  RASN1String *id = NULL, *utc = NULL;
575  if (!crle) {
576  return;
577  }
578  if (!pad) {
579  pad = "";
580  }
581  utc = crle->revocationDate;
582  if (crle->userCertificate) {
584  }
585  rz_strbuf_appendf(sb, "%sUser Certificate:\n%s %s\n"
586  "%sRevocation Date:\n%s %s\n",
587  pad, pad, id ? id->string : "Missing",
588  pad, pad, utc ? utc->string : "Missing");
590 }
591 
593  RASN1String *algo = NULL, *last = NULL, *next = NULL;
594  ut32 i;
595  char *pad2, *pad3;
596  if (!crl) {
597  return NULL;
598  }
599  if (!pad) {
600  pad = "";
601  }
602  pad3 = rz_str_newf("%s ", pad);
603  if (!pad3) {
604  return NULL;
605  }
606  pad2 = pad3 + 2;
607  algo = crl->signature.algorithm;
608  last = crl->lastUpdate;
609  next = crl->nextUpdate;
610  RzStrBuf *sb = rz_strbuf_new("");
611  rz_strbuf_appendf(sb, "%sCRL:\n%sSignature:\n%s%s\n%sIssuer\n", pad, pad2, pad3,
612  algo ? algo->string : "", pad2);
613  rz_x509_name_dump(&crl->issuer, pad3, sb);
614 
615  rz_strbuf_appendf(sb, "%sLast Update: %s\n%sNext Update: %s\n%sRevoked Certificates:\n",
616  pad2, last ? last->string : "Missing",
617  pad2, next ? next->string : "Missing", pad2);
618 
619  for (i = 0; i < crl->length; i++) {
621  }
622 
623  free(pad3);
624  return rz_strbuf_drain(sb);
625 }
626 
628  if (validity) {
629  if (validity->notBefore) {
630  pj_ks(pj, "NotBefore", validity->notBefore->string);
631  }
632  if (validity->notAfter) {
633  pj_ks(pj, "NotAfter", validity->notAfter->string);
634  }
635  }
636 }
637 
639  ut32 i;
640  for (i = 0; i < name->length; i++) {
641  if (!name->oids[i] || !name->names[i]) {
642  continue;
643  }
644  pj_ks(pj, name->oids[i]->string, name->names[i]->string);
645  }
646 }
647 
649  RASN1String *m = NULL;
650  if (spki) {
651  if (spki->algorithm.algorithm) {
652  pj_ks(pj, "Algorithm", spki->algorithm.algorithm->string);
653  }
654  if (spki->subjectPublicKeyModule) {
656  if (m) {
657  pj_ks(pj, "Module", m->string);
658  }
660  }
661  if (spki->subjectPublicKeyExponent) {
663  if (m) {
664  pj_ks(pj, "Exponent", m->string);
665  }
667  }
668  }
669 }
670 
672  if (exts) {
673  RASN1String *m = NULL;
674  ut32 i;
675  pj_a(pj);
676  for (i = 0; i < exts->length; i++) {
677  RX509Extension *e = exts->extensions[i];
678  if (!e) {
679  continue;
680  }
681  pj_o(pj);
682  if (e->extnID) {
683  pj_ks(pj, "OID", e->extnID->string);
684  }
685  if (e->critical) {
686  pj_kb(pj, "Critical", e->critical);
687  }
688  // TODO handle extensions correctly..
689  if (e->extnValue) {
690  m = rz_asn1_stringify_integer(e->extnValue->binary, e->extnValue->length);
691  if (m) {
692  pj_ks(pj, "Value", m->string);
693  }
695  }
696  pj_end(pj);
697  }
698  pj_end(pj);
699  pj_end(pj);
700  }
701 }
702 
704  RASN1String *m = NULL;
705  if (crle) {
706  if (crle->userCertificate) {
708  if (m) {
709  pj_ks(pj, "UserCertificate", m->string);
710  }
712  }
713  if (crle->revocationDate) {
714  pj_ks(pj, "RevocationDate", crle->revocationDate->string);
715  }
716  }
717 }
718 
720  ut32 i;
721  if (crl) {
722  if (crl->signature.algorithm) {
723  pj_ks(pj, "Signature", crl->signature.algorithm->string);
724  }
725  pj_k(pj, "Issuer");
726  pj_o(pj);
727  rz_x509_name_json(pj, &crl->issuer);
728  pj_end(pj);
729  if (crl->lastUpdate) {
730  pj_ks(pj, "LastUpdate", crl->lastUpdate->string);
731  }
732  if (crl->nextUpdate) {
733  pj_ks(pj, "NextUpdate", crl->nextUpdate->string);
734  }
735  pj_k(pj, "RevokedCertificates");
736  pj_a(pj);
737  for (i = 0; i < crl->length; i++) {
739  }
740  pj_end(pj);
741  }
742 }
743 
745  pj_o(pj);
746  RASN1String *m = NULL;
747  if (tbsc) {
748  pj_ki(pj, "Version", tbsc->version + 1);
749  if (tbsc->serialNumber) {
750  pj_ks(pj, "SerialNumber", tbsc->serialNumber->string);
751  }
752  if (tbsc->signature.algorithm) {
753  pj_ks(pj, "SignatureAlgorithm", tbsc->signature.algorithm->string);
754  }
755  pj_k(pj, "Issuer");
756  pj_o(pj);
757  rz_x509_name_json(pj, &tbsc->issuer);
758  pj_end(pj);
759  pj_k(pj, "Validity");
760  pj_o(pj);
761  rz_x509_validity_json(pj, &tbsc->validity);
762  pj_end(pj);
763  pj_k(pj, "Subject");
764  pj_o(pj);
765  rz_x509_name_json(pj, &tbsc->subject);
766  pj_end(pj);
767  pj_k(pj, "SubjectPublicKeyInfo");
768  pj_o(pj);
770  pj_end(pj);
771  if (tbsc->issuerUniqueID) {
773  if (m) {
774  pj_ks(pj, "IssuerUniqueID", m->string);
775  }
777  }
778  if (tbsc->subjectUniqueID) {
780  if (m) {
781  pj_ks(pj, "SubjectUniqueID", m->string);
782  }
784  }
785  pj_k(pj, "Extensions");
787  }
788 }
789 
791  if (!certificate) {
792  return;
793  }
794  RASN1String *m = NULL;
795  pj_o(pj);
796  pj_k(pj, "TBSCertificate");
797  rz_x509_tbscertificate_json(pj, &certificate->tbsCertificate);
798  if (certificate->algorithmIdentifier.algorithm) {
799  pj_ks(pj, "Algorithm", certificate->algorithmIdentifier.algorithm->string);
800  }
801  if (certificate->signature) {
802  m = rz_asn1_stringify_integer(certificate->signature->binary, certificate->signature->length);
803  if (m) {
804  pj_ks(pj, "Signature", m->string);
805  }
807  }
808  pj_end(pj);
809 }
#define e(frag)
lzma_index ** i
Definition: index.h:629
static const char ext[]
Definition: apprentice.c:1981
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 id
Definition: op.c:540
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
RZ_API void rz_asn1_free_object(RASN1Object *object)
Definition: asn1.c:445
#define CLASS_UNIVERSAL
Definition: rz_asn1.h:25
RZ_API void rz_asn1_free_string(RASN1String *string)
Definition: astr.c:313
#define FORM_PRIMITIVE
Definition: rz_asn1.h:31
#define TAG_INTEGER
Definition: rz_asn1.h:37
#define TAG_BITSTRING
Definition: rz_asn1.h:38
#define TAG_OCTETSTRING
Definition: rz_asn1.h:39
RZ_API void rz_asn1_free_binary(RASN1Binary *string)
Definition: asn1.c:463
#define TAG_BOOLEAN
Definition: rz_asn1.h:36
RZ_API RASN1String * rz_asn1_stringify_time(const ut8 *buffer, ut32 length)
Definition: astr.c:108
#define TAG_OID
Definition: rz_asn1.h:41
#define TAG_GENERALIZEDTIME
Definition: rz_asn1.h:56
RZ_API RASN1Binary * rz_asn1_create_binary(const ut8 *buffer, ut32 length)
Definition: asn1.c:152
#define TAG_SET
Definition: rz_asn1.h:49
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_utctime(const ut8 *buffer, ut32 length)
Definition: astr.c:67
RZ_API RASN1String * rz_asn1_stringify_oid(const ut8 *buffer, ut32 length)
Definition: astr.c:249
#define CLASS_CONTEXT
Definition: rz_asn1.h:27
RZ_API RASN1String * rz_asn1_stringify_string(const ut8 *buffer, ut32 length)
Definition: astr.c:55
#define FORM_CONSTRUCTED
Definition: rz_asn1.h:32
#define TAG_SEQUENCE
Definition: rz_asn1.h:48
#define TAG_UTCTIME
Definition: rz_asn1.h:55
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
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_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
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 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_FREE(x)
Definition: rz_types.h:369
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
Definition: buffer.h:15
Definition: zipcmp.c:77
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
RASN1String * algorithm
Definition: rz_x509.h:27
RASN1String * parameters
Definition: rz_x509.h:28
RX509TBSCertificate tbsCertificate
Definition: rz_x509.h:88
RASN1Binary * signature
Definition: rz_x509.h:90
RX509AlgorithmIdentifier algorithmIdentifier
Definition: rz_x509.h:89
RX509AlgorithmIdentifier signature
Definition: rz_x509.h:101
RX509CRLEntry ** revokedCertificates
Definition: rz_x509.h:106
RASN1Binary * userCertificate
Definition: rz_x509.h:96
RASN1String * revocationDate
Definition: rz_x509.h:97
RX509Extension ** extensions
Definition: rz_x509.h:71
RX509AlgorithmIdentifier algorithm
Definition: rz_x509.h:54
RASN1Binary * subjectPublicKeyExponent
Definition: rz_x509.h:59
RASN1Binary * subjectPublicKey
Definition: rz_x509.h:56
RASN1Binary * subjectPublicKeyModule
Definition: rz_x509.h:60
RX509SubjectPublicKeyInfo subjectPublicKeyInfo
Definition: rz_x509.h:81
RASN1String * serialNumber
Definition: rz_x509.h:76
RASN1Binary * subjectUniqueID
Definition: rz_x509.h:83
RX509AlgorithmIdentifier signature
Definition: rz_x509.h:77
RX509Validity validity
Definition: rz_x509.h:79
RASN1Binary * issuerUniqueID
Definition: rz_x509.h:82
RX509Extensions extensions
Definition: rz_x509.h:84
RASN1String * notBefore
Definition: rz_x509.h:16
RASN1String * notAfter
Definition: rz_x509.h:17
#define fail(test)
Definition: tests.h:29
RZ_API void rz_x509_crl_json(PJ *pj, RX509CertificateRevocationList *crl)
Definition: x509.c:719
RZ_API RX509Certificate * rz_x509_parse_certificate2(const ut8 *buffer, ut32 length)
Definition: x509.c:249
void rz_x509_crlentry_dump(RX509CRLEntry *crle, const char *pad, RzStrBuf *sb)
Definition: x509.c:573
RZ_API void rz_x509_crlentry_json(PJ *pj, RX509CRLEntry *crle)
Definition: x509.c:703
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 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_name_json(PJ *pj, RX509Name *name)
Definition: x509.c:638
RZ_API void rz_x509_extensions_json(PJ *pj, RX509Extensions *exts)
Definition: x509.c:671
static void rz_x509_free_crlentry(RX509CRLEntry *entry)
Definition: x509.c:396
RZ_API void rz_x509_free_subjectpublickeyinfo(RX509SubjectPublicKeyInfo *spki)
Definition: x509.c:361
RZ_API void rz_x509_free_extensions(RX509Extensions *ex)
Definition: x509.c:347
static void rz_x509_subjectpublickeyinfo_dump(RX509SubjectPublicKeyInfo *spki, const char *pad, RzStrBuf *sb)
Definition: x509.c:450
RZ_API void rz_x509_free_name(RX509Name *name)
Definition: x509.c:322
RZ_API bool rz_x509_parse_subjectpublickeyinfo(RX509SubjectPublicKeyInfo *spki, RASN1Object *object)
Definition: x509.c:57
RZ_API bool rz_x509_parse_extensions(RX509Extensions *ext, RASN1Object *object)
Definition: x509.c:143
static void rz_x509_free_validity(RX509Validity *validity)
Definition: x509.c:314
RZ_API bool rz_x509_parse_tbscertificate(RX509TBSCertificate *tbsc, RASN1Object *object)
Definition: x509.c:164
static bool is_oid_object(RASN1Object *object)
Definition: x509.c:38
RZ_API void rz_x509_free_extension(RX509Extension *ex)
Definition: x509.c:338
RZ_API RX509Certificate * rz_x509_parse_certificate(RASN1Object *object)
Definition: x509.c:217
static void rz_x509_extensions_dump(RX509Extensions *exts, const char *pad, RzStrBuf *sb)
Definition: x509.c:472
RZ_API void rz_x509_certificate_dump(RX509Certificate *cert, const char *pad, RzStrBuf *sb)
Definition: x509.c:546
static void rz_x509_tbscertificate_dump(RX509TBSCertificate *tbsc, const char *pad, RzStrBuf *sb)
Definition: x509.c:495
RZ_API bool rz_x509_parse_name(RX509Name *name, RASN1Object *object)
Definition: x509.c:79
RZ_API void rz_x509_subjectpublickeyinfo_json(PJ *pj, RX509SubjectPublicKeyInfo *spki)
Definition: x509.c:648
static void rz_x509_validity_dump(RX509Validity *validity, const char *pad, RzStrBuf *sb)
Definition: x509.c:422
RZ_API char * rz_x509_crl_to_string(RX509CertificateRevocationList *crl, const char *pad)
Definition: x509.c:592
static bool rz_x509_parse_validity(RX509Validity *validity, RASN1Object *object)
Definition: x509.c:10
RZ_API bool rz_x509_parse_extension(RX509Extension *ext, RASN1Object *object)
Definition: x509.c:122
RZ_API void rz_x509_free_tbscertificate(RX509TBSCertificate *tbsc)
Definition: x509.c:371
RZ_API RX509CRLEntry * rz_x509_parse_crlentry(RASN1Object *object)
Definition: x509.c:261
RZ_API void rz_x509_certificate_json(PJ *pj, RX509Certificate *certificate)
Definition: x509.c:790
RZ_API void rz_x509_validity_json(PJ *pj, RX509Validity *validity)
Definition: x509.c:627
void rz_x509_free_crl(RX509CertificateRevocationList *crl)
Definition: x509.c:404
RZ_API void rz_x509_tbscertificate_json(PJ *pj, RX509TBSCertificate *tbsc)
Definition: x509.c:744
RZ_API bool rz_x509_parse_algorithmidentifier(RX509AlgorithmIdentifier *ai, RASN1Object *object)
Definition: x509.c:44
static xnu_exception_info ex