Rizin
unix-like reverse engineering framework and cli tools
x509.c File Reference
#include <rz_util.h>
#include <rz_cons.h>
#include <stdlib.h>
#include <string.h>
#include "./x509.h"

Go to the source code of this file.

Functions

static bool rz_x509_parse_validity (RX509Validity *validity, RASN1Object *object)
 
static bool is_oid_object (RASN1Object *object)
 
RZ_API bool rz_x509_parse_algorithmidentifier (RX509AlgorithmIdentifier *ai, RASN1Object *object)
 
RZ_API bool rz_x509_parse_subjectpublickeyinfo (RX509SubjectPublicKeyInfo *spki, RASN1Object *object)
 
RZ_API bool rz_x509_parse_name (RX509Name *name, RASN1Object *object)
 
RZ_API bool rz_x509_parse_extension (RX509Extension *ext, RASN1Object *object)
 
RZ_API bool rz_x509_parse_extensions (RX509Extensions *ext, RASN1Object *object)
 
RZ_API bool rz_x509_parse_tbscertificate (RX509TBSCertificate *tbsc, RASN1Object *object)
 
RZ_API RX509Certificaterz_x509_parse_certificate (RASN1Object *object)
 
RZ_API RX509Certificaterz_x509_parse_certificate2 (const ut8 *buffer, ut32 length)
 
RZ_API RX509CRLEntryrz_x509_parse_crlentry (RASN1Object *object)
 
RZ_API RX509CertificateRevocationListrz_x509_parse_crl (RASN1Object *object)
 
RZ_API void rz_x509_free_algorithmidentifier (RX509AlgorithmIdentifier *ai)
 
static void rz_x509_free_validity (RX509Validity *validity)
 
RZ_API void rz_x509_free_name (RX509Name *name)
 
RZ_API void rz_x509_free_extension (RX509Extension *ex)
 
RZ_API void rz_x509_free_extensions (RX509Extensions *ex)
 
RZ_API void rz_x509_free_subjectpublickeyinfo (RX509SubjectPublicKeyInfo *spki)
 
RZ_API void rz_x509_free_tbscertificate (RX509TBSCertificate *tbsc)
 
RZ_API void rz_x509_free_certificate (RX509Certificate *certificate)
 
static void rz_x509_free_crlentry (RX509CRLEntry *entry)
 
void rz_x509_free_crl (RX509CertificateRevocationList *crl)
 
static void rz_x509_validity_dump (RX509Validity *validity, const char *pad, RzStrBuf *sb)
 
RZ_API void rz_x509_name_dump (RX509Name *name, const char *pad, RzStrBuf *sb)
 
static void rz_x509_subjectpublickeyinfo_dump (RX509SubjectPublicKeyInfo *spki, const char *pad, RzStrBuf *sb)
 
static void rz_x509_extensions_dump (RX509Extensions *exts, const char *pad, RzStrBuf *sb)
 
static void rz_x509_tbscertificate_dump (RX509TBSCertificate *tbsc, const char *pad, RzStrBuf *sb)
 
RZ_API void rz_x509_certificate_dump (RX509Certificate *cert, const char *pad, RzStrBuf *sb)
 
void rz_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RzStrBuf *sb)
 
RZ_API char * rz_x509_crl_to_string (RX509CertificateRevocationList *crl, const char *pad)
 
RZ_API void rz_x509_validity_json (PJ *pj, RX509Validity *validity)
 
RZ_API void rz_x509_name_json (PJ *pj, RX509Name *name)
 
RZ_API void rz_x509_subjectpublickeyinfo_json (PJ *pj, RX509SubjectPublicKeyInfo *spki)
 
RZ_API void rz_x509_extensions_json (PJ *pj, RX509Extensions *exts)
 
RZ_API void rz_x509_crlentry_json (PJ *pj, RX509CRLEntry *crle)
 
RZ_API void rz_x509_crl_json (PJ *pj, RX509CertificateRevocationList *crl)
 
RZ_API void rz_x509_tbscertificate_json (PJ *pj, RX509TBSCertificate *tbsc)
 
RZ_API void rz_x509_certificate_json (PJ *pj, RX509Certificate *certificate)
 

Function Documentation

◆ is_oid_object()

static bool is_oid_object ( RASN1Object object)
inlinestatic

Definition at line 38 of file x509.c.

38  {
39  return object->list.objects[0] &&
40  object->list.objects[0]->klass == CLASS_UNIVERSAL &&
41  object->list.objects[0]->tag == TAG_OID;
42 }
#define CLASS_UNIVERSAL
Definition: rz_asn1.h:25
#define TAG_OID
Definition: rz_asn1.h:41

References CLASS_UNIVERSAL, and TAG_OID.

Referenced by rz_x509_parse_algorithmidentifier().

◆ rz_x509_certificate_dump()

RZ_API void rz_x509_certificate_dump ( RX509Certificate cert,
const char *  pad,
RzStrBuf sb 
)

Definition at line 546 of file x509.c.

546  {
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 }
static SblHeader sb
Definition: bin_mbn.c:26
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
ut32 length
Definition: rz_asn1.h:75
const char * string
Definition: rz_asn1.h:65
RASN1String * algorithm
Definition: rz_x509.h:27
RX509TBSCertificate tbsCertificate
Definition: rz_x509.h:88
RASN1Binary * signature
Definition: rz_x509.h:90
RX509AlgorithmIdentifier algorithmIdentifier
Definition: rz_x509.h:89
static void rz_x509_tbscertificate_dump(RX509TBSCertificate *tbsc, const char *pad, RzStrBuf *sb)
Definition: x509.c:495

References rz_x509_algorithmidentifier_t::algorithm, rz_x509_certificate_t::algorithmIdentifier, free(), rz_asn1_bin_t::length, NULL, pad(), rz_str_newf(), rz_strbuf_appendf(), rz_x509_tbscertificate_dump(), sb, rz_x509_certificate_t::signature, rz_asn1_string_t::string, and rz_x509_certificate_t::tbsCertificate.

Referenced by cmd_print_fromage(), and rz_pkcs7_cms_to_string().

◆ rz_x509_certificate_json()

RZ_API void rz_x509_certificate_json ( PJ pj,
RX509Certificate certificate 
)

Definition at line 790 of file x509.c.

790  {
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 }
RZ_API void rz_asn1_free_string(RASN1String *string)
Definition: astr.c:313
RZ_API RASN1String * rz_asn1_stringify_integer(const ut8 *buffer, ut32 length)
Definition: astr.c:185
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
ut8 * binary
Definition: rz_asn1.h:76
RZ_API void rz_x509_tbscertificate_json(PJ *pj, RX509TBSCertificate *tbsc)
Definition: x509.c:744

References rz_x509_algorithmidentifier_t::algorithm, rz_x509_certificate_t::algorithmIdentifier, rz_asn1_bin_t::binary, rz_asn1_bin_t::length, regress::m, NULL, pj_end(), pj_k(), pj_ks(), pj_o(), rz_asn1_free_string(), rz_asn1_stringify_integer(), rz_x509_tbscertificate_json(), rz_x509_certificate_t::signature, rz_asn1_string_t::string, and rz_x509_certificate_t::tbsCertificate.

Referenced by rz_pkcs7_cms_json().

◆ rz_x509_crl_json()

RZ_API void rz_x509_crl_json ( PJ pj,
RX509CertificateRevocationList crl 
)

Definition at line 719 of file x509.c.

719  {
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 }
lzma_index ** i
Definition: index.h:629
uint32_t ut32
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
RX509AlgorithmIdentifier signature
Definition: rz_x509.h:101
RX509CRLEntry ** revokedCertificates
Definition: rz_x509.h:106
RZ_API void rz_x509_crlentry_json(PJ *pj, RX509CRLEntry *crle)
Definition: x509.c:703
RZ_API void rz_x509_name_json(PJ *pj, RX509Name *name)
Definition: x509.c:638

References rz_x509_algorithmidentifier_t::algorithm, i, rz_x509_certificaterevocationlist::issuer, rz_x509_certificaterevocationlist::lastUpdate, rz_x509_certificaterevocationlist::length, rz_x509_certificaterevocationlist::nextUpdate, pj_a(), pj_end(), pj_k(), pj_ks(), pj_o(), rz_x509_certificaterevocationlist::revokedCertificates, rz_x509_crlentry_json(), rz_x509_name_json(), rz_x509_certificaterevocationlist::signature, and rz_asn1_string_t::string.

Referenced by rz_pkcs7_cms_json().

◆ rz_x509_crl_to_string()

RZ_API char* rz_x509_crl_to_string ( RX509CertificateRevocationList crl,
const char *  pad 
)

Definition at line 592 of file x509.c.

592  {
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 }
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
void rz_x509_crlentry_dump(RX509CRLEntry *crle, const char *pad, RzStrBuf *sb)
Definition: x509.c:573
RZ_API void rz_x509_name_dump(RX509Name *name, const char *pad, RzStrBuf *sb)
Definition: x509.c:434

References rz_x509_algorithmidentifier_t::algorithm, free(), i, rz_x509_certificaterevocationlist::issuer, rz_x509_certificaterevocationlist::lastUpdate, rz_x509_certificaterevocationlist::length, rz_x509_certificaterevocationlist::nextUpdate, NULL, pad(), rz_x509_certificaterevocationlist::revokedCertificates, rz_str_newf(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), rz_x509_crlentry_dump(), rz_x509_name_dump(), sb, rz_x509_certificaterevocationlist::signature, and rz_asn1_string_t::string.

Referenced by rz_pkcs7_cms_to_string().

◆ rz_x509_crlentry_dump()

void rz_x509_crlentry_dump ( RX509CRLEntry crle,
const char *  pad,
RzStrBuf sb 
)

Definition at line 573 of file x509.c.

573  {
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 }
int id
Definition: op.c:540
RASN1Binary * userCertificate
Definition: rz_x509.h:96
RASN1String * revocationDate
Definition: rz_x509.h:97

References rz_asn1_bin_t::binary, id, rz_asn1_bin_t::length, NULL, pad(), rz_x509_crlentry::revocationDate, rz_asn1_free_string(), rz_asn1_stringify_integer(), rz_strbuf_appendf(), sb, and rz_x509_crlentry::userCertificate.

Referenced by rz_x509_crl_to_string().

◆ rz_x509_crlentry_json()

RZ_API void rz_x509_crlentry_json ( PJ pj,
RX509CRLEntry crle 
)

Definition at line 703 of file x509.c.

703  {
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 }

References rz_asn1_bin_t::binary, rz_asn1_bin_t::length, regress::m, NULL, pj_ks(), rz_x509_crlentry::revocationDate, rz_asn1_free_string(), rz_asn1_stringify_integer(), rz_asn1_string_t::string, and rz_x509_crlentry::userCertificate.

Referenced by rz_x509_crl_json().

◆ rz_x509_extensions_dump()

static void rz_x509_extensions_dump ( RX509Extensions exts,
const char *  pad,
RzStrBuf sb 
)
static

Definition at line 472 of file x509.c.

472  {
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 }
#define e(frag)
RX509Extension ** extensions
Definition: rz_x509.h:71

References e, rz_x509_extensions_t::extensions, i, rz_x509_extensions_t::length, pad(), rz_strbuf_appendf(), and sb.

Referenced by rz_x509_tbscertificate_dump().

◆ rz_x509_extensions_json()

RZ_API void rz_x509_extensions_json ( PJ pj,
RX509Extensions exts 
)

Definition at line 671 of file x509.c.

671  {
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 }
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177

References e, rz_x509_extensions_t::extensions, i, rz_x509_extensions_t::length, regress::m, NULL, pj_a(), pj_end(), pj_kb(), pj_ks(), pj_o(), rz_asn1_free_string(), and rz_asn1_stringify_integer().

Referenced by rz_x509_tbscertificate_json().

◆ rz_x509_free_algorithmidentifier()

RZ_API void rz_x509_free_algorithmidentifier ( RX509AlgorithmIdentifier ai)

◆ rz_x509_free_certificate()

RZ_API void rz_x509_free_certificate ( RX509Certificate certificate)

Definition at line 387 of file x509.c.

387  {
388  if (certificate) {
389  rz_asn1_free_binary(certificate->signature);
392  free(certificate);
393  }
394 }
RZ_API void rz_asn1_free_binary(RASN1Binary *string)
Definition: asn1.c:463
RZ_API void rz_x509_free_algorithmidentifier(RX509AlgorithmIdentifier *ai)
Definition: x509.c:306
RZ_API void rz_x509_free_tbscertificate(RX509TBSCertificate *tbsc)
Definition: x509.c:371

References rz_x509_certificate_t::algorithmIdentifier, free(), rz_asn1_free_binary(), rz_x509_free_algorithmidentifier(), rz_x509_free_tbscertificate(), rz_x509_certificate_t::signature, and rz_x509_certificate_t::tbsCertificate.

Referenced by cmd_print_fromage(), and rz_pkcs7_free_extendedcertificatesandcertificates().

◆ rz_x509_free_crl()

◆ rz_x509_free_crlentry()

static void rz_x509_free_crlentry ( RX509CRLEntry entry)
static

Definition at line 396 of file x509.c.

396  {
397  if (entry) {
398  rz_asn1_free_binary(entry->userCertificate);
399  rz_asn1_free_string(entry->revocationDate);
400  free(entry);
401  }
402 }
Definition: zipcmp.c:77

References free(), rz_asn1_free_binary(), and rz_asn1_free_string().

Referenced by rz_x509_free_crl().

◆ rz_x509_free_extension()

RZ_API void rz_x509_free_extension ( RX509Extension ex)

Definition at line 338 of file x509.c.

338  {
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 }
static xnu_exception_info ex

References ex, free(), rz_asn1_free_binary(), and rz_asn1_free_string().

Referenced by rz_x509_free_extensions(), and rz_x509_parse_extensions().

◆ rz_x509_free_extensions()

RZ_API void rz_x509_free_extensions ( RX509Extensions ex)

Definition at line 347 of file x509.c.

347  {
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 }
RZ_API void rz_x509_free_extension(RX509Extension *ex)
Definition: x509.c:338

References ex, free(), i, and rz_x509_free_extension().

Referenced by rz_x509_free_tbscertificate().

◆ rz_x509_free_name()

RZ_API void rz_x509_free_name ( RX509Name name)

Definition at line 322 of file x509.c.

322  {
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 }
Definition: z80asm.h:102

References i, rz_asn1_free_string(), and RZ_FREE.

Referenced by rz_pkcs7_free_issuerandserialnumber(), rz_x509_free_crl(), and rz_x509_free_tbscertificate().

◆ rz_x509_free_subjectpublickeyinfo()

◆ rz_x509_free_tbscertificate()

RZ_API void rz_x509_free_tbscertificate ( RX509TBSCertificate tbsc)

Definition at line 371 of file x509.c.

371  {
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 }
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
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_free_validity(RX509Validity *validity)
Definition: x509.c:314

References rz_x509_tbscertificate_t::extensions, rz_x509_tbscertificate_t::issuer, rz_x509_tbscertificate_t::issuerUniqueID, rz_asn1_free_binary(), rz_asn1_free_string(), rz_x509_free_algorithmidentifier(), rz_x509_free_extensions(), rz_x509_free_name(), rz_x509_free_subjectpublickeyinfo(), rz_x509_free_validity(), rz_x509_tbscertificate_t::serialNumber, rz_x509_tbscertificate_t::signature, rz_x509_tbscertificate_t::subject, rz_x509_tbscertificate_t::subjectPublicKeyInfo, rz_x509_tbscertificate_t::subjectUniqueID, and rz_x509_tbscertificate_t::validity.

Referenced by rz_x509_free_certificate().

◆ rz_x509_free_validity()

static void rz_x509_free_validity ( RX509Validity validity)
static

Definition at line 314 of file x509.c.

314  {
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 }
RASN1String * notBefore
Definition: rz_x509.h:16
RASN1String * notAfter
Definition: rz_x509.h:17

References rz_x509_validity_t::notAfter, rz_x509_validity_t::notBefore, and rz_asn1_free_string().

Referenced by rz_x509_free_tbscertificate().

◆ rz_x509_name_dump()

RZ_API void rz_x509_name_dump ( RX509Name name,
const char *  pad,
RzStrBuf sb 
)

Definition at line 434 of file x509.c.

434  {
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 }

References i, pad(), rz_strbuf_appendf(), and sb.

Referenced by rz_x509_crl_to_string(), rz_x509_signedinfo_dump(), and rz_x509_tbscertificate_dump().

◆ rz_x509_name_json()

RZ_API void rz_x509_name_json ( PJ pj,
RX509Name name 
)

Definition at line 638 of file x509.c.

638  {
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 }

References i, and pj_ks().

Referenced by rz_x509_crl_json(), rz_x509_signedinfo_json(), and rz_x509_tbscertificate_json().

◆ rz_x509_parse_algorithmidentifier()

RZ_API bool rz_x509_parse_algorithmidentifier ( RX509AlgorithmIdentifier ai,
RASN1Object object 
)

Definition at line 44 of file x509.c.

44  {
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 }
RZ_API RASN1String * rz_asn1_stringify_oid(const ut8 *buffer, ut32 length)
Definition: astr.c:249
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
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
static bool is_oid_object(RASN1Object *object)
Definition: x509.c:38

References rz_x509_algorithmidentifier_t::algorithm, is_oid_object(), rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, NULL, rz_asn1_list_t::objects, rz_x509_algorithmidentifier_t::parameters, rz_asn1_stringify_oid(), rz_return_val_if_fail, and rz_asn1_object_t::sector.

Referenced by rz_pkcs7_parse_digestalgorithmidentifier(), rz_pkcs7_parse_signerinfo(), rz_pkcs7_parse_spcmessagedigest(), rz_x509_parse_certificate(), rz_x509_parse_crl(), rz_x509_parse_subjectpublickeyinfo(), and rz_x509_parse_tbscertificate().

◆ rz_x509_parse_certificate()

RZ_API RX509Certificate* rz_x509_parse_certificate ( RASN1Object object)

Definition at line 217 of file x509.c.

217  {
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 }
RZ_API void rz_asn1_free_object(RASN1Object *object)
Definition: asn1.c:445
#define FORM_PRIMITIVE
Definition: rz_asn1.h:31
#define TAG_BITSTRING
Definition: rz_asn1.h:38
RZ_API RASN1Binary * rz_asn1_create_binary(const ut8 *buffer, ut32 length)
Definition: asn1.c:152
#define FORM_CONSTRUCTED
Definition: rz_asn1.h:32
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define fail(test)
Definition: tests.h:29
RZ_API bool rz_x509_parse_tbscertificate(RX509TBSCertificate *tbsc, RASN1Object *object)
Definition: x509.c:164
RZ_API bool rz_x509_parse_algorithmidentifier(RX509AlgorithmIdentifier *ai, RASN1Object *object)
Definition: x509.c:44

References rz_x509_certificate_t::algorithmIdentifier, CLASS_UNIVERSAL, fail, rz_asn1_object_t::form, FORM_CONSTRUCTED, FORM_PRIMITIVE, rz_asn1_object_t::klass, rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, NULL, rz_asn1_list_t::objects, rz_asn1_create_binary(), rz_asn1_free_object(), RZ_FREE, RZ_NEW0, rz_x509_parse_algorithmidentifier(), rz_x509_parse_tbscertificate(), rz_asn1_object_t::sector, rz_x509_certificate_t::signature, TAG_BITSTRING, rz_x509_certificate_t::tbsCertificate, and autogen_x86imm::tmp.

Referenced by cmd_print_fromage(), rz_pkcs7_parse_extendedcertificatesandcertificates(), and rz_x509_parse_certificate2().

◆ rz_x509_parse_certificate2()

RZ_API RX509Certificate* rz_x509_parse_certificate2 ( const ut8 buffer,
ut32  length 
)

Definition at line 249 of file x509.c.

249  {
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 }
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
RZ_API RASN1Object * rz_asn1_create_object(const ut8 *buffer, ut32 length, const ut8 *start_pointer)
Definition: asn1.c:120
Definition: buffer.h:15
RZ_API RX509Certificate * rz_x509_parse_certificate(RASN1Object *object)
Definition: x509.c:217

References length, NULL, rz_asn1_create_object(), and rz_x509_parse_certificate().

◆ rz_x509_parse_crl()

RZ_API RX509CertificateRevocationList* rz_x509_parse_crl ( RASN1Object object)

Definition at line 275 of file x509.c.

275  {
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 }
return memset(p, 0, total)
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API RASN1String * rz_asn1_stringify_utctime(const ut8 *buffer, ut32 length)
Definition: astr.c:67
RZ_API bool rz_x509_parse_name(RX509Name *name, RASN1Object *object)
Definition: x509.c:79
RZ_API RX509CRLEntry * rz_x509_parse_crlentry(RASN1Object *object)
Definition: x509.c:261

References calloc(), free(), i, rz_x509_certificaterevocationlist::issuer, rz_x509_certificaterevocationlist::lastUpdate, rz_asn1_list_t::length, rz_x509_certificaterevocationlist::length, length, rz_asn1_object_t::list, malloc(), memset(), rz_x509_certificaterevocationlist::nextUpdate, NULL, rz_asn1_list_t::objects, rz_x509_certificaterevocationlist::revokedCertificates, rz_asn1_stringify_utctime(), rz_x509_parse_algorithmidentifier(), rz_x509_parse_crlentry(), rz_x509_parse_name(), and rz_x509_certificaterevocationlist::signature.

Referenced by rz_pkcs7_parse_certificaterevocationlists().

◆ rz_x509_parse_crlentry()

RZ_API RX509CRLEntry* rz_x509_parse_crlentry ( RASN1Object object)

Definition at line 261 of file x509.c.

261  {
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 }

References rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, malloc(), NULL, rz_asn1_list_t::objects, rz_asn1_create_binary(), rz_asn1_stringify_utctime(), and rz_asn1_object_t::sector.

Referenced by rz_x509_parse_crl().

◆ rz_x509_parse_extension()

RZ_API bool rz_x509_parse_extension ( RX509Extension ext,
RASN1Object object 
)

Definition at line 122 of file x509.c.

122  {
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 }
static const char ext[]
Definition: apprentice.c:1981
#define TAG_OCTETSTRING
Definition: rz_asn1.h:39
#define TAG_BOOLEAN
Definition: rz_asn1.h:36

References ext, rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, rz_asn1_list_t::objects, rz_asn1_create_binary(), rz_asn1_stringify_oid(), rz_asn1_object_t::sector, rz_asn1_object_t::tag, TAG_BOOLEAN, TAG_OCTETSTRING, and TAG_OID.

Referenced by rz_x509_parse_extensions().

◆ rz_x509_parse_extensions()

RZ_API bool rz_x509_parse_extensions ( RX509Extensions ext,
RASN1Object object 
)

Definition at line 143 of file x509.c.

143  {
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 }
RZ_API bool rz_x509_parse_extension(RX509Extension *ext, RASN1Object *object)
Definition: x509.c:122

References calloc(), ext, i, rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, NULL, rz_asn1_list_t::objects, RZ_NEW0, rz_x509_free_extension(), and rz_x509_parse_extension().

Referenced by rz_x509_parse_tbscertificate().

◆ rz_x509_parse_name()

RZ_API bool rz_x509_parse_name ( RX509Name name,
RASN1Object object 
)

Definition at line 79 of file x509.c.

79  {
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 }
#define TAG_SET
Definition: rz_asn1.h:49
RZ_API RASN1String * rz_asn1_stringify_string(const ut8 *buffer, ut32 length)
Definition: astr.c:55
#define TAG_SEQUENCE
Definition: rz_asn1.h:48

References calloc(), CLASS_UNIVERSAL, rz_asn1_object_t::form, FORM_CONSTRUCTED, i, rz_asn1_object_t::klass, rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, rz_asn1_list_t::objects, rz_asn1_stringify_oid(), rz_asn1_stringify_string(), RZ_FREE, rz_asn1_object_t::sector, rz_asn1_object_t::tag, TAG_OID, TAG_SEQUENCE, and TAG_SET.

Referenced by rz_pkcs7_parse_issuerandserialnumber(), rz_x509_parse_crl(), and rz_x509_parse_tbscertificate().

◆ rz_x509_parse_subjectpublickeyinfo()

RZ_API bool rz_x509_parse_subjectpublickeyinfo ( RX509SubjectPublicKeyInfo spki,
RASN1Object object 
)

◆ rz_x509_parse_tbscertificate()

RZ_API bool rz_x509_parse_tbscertificate ( RX509TBSCertificate tbsc,
RASN1Object object 
)

Definition at line 164 of file x509.c.

164  {
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 }
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 void list(RzEgg *egg)
Definition: rz-gg.c:52
#define TAG_INTEGER
Definition: rz_asn1.h:37
#define CLASS_CONTEXT
Definition: rz_asn1.h:27
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 bool rz_x509_parse_validity(RX509Validity *validity, RASN1Object *object)
Definition: x509.c:10

References CLASS_CONTEXT, CLASS_UNIVERSAL, rz_x509_tbscertificate_t::extensions, rz_asn1_object_t::form, FORM_CONSTRUCTED, i, rz_x509_tbscertificate_t::issuer, rz_x509_tbscertificate_t::issuerUniqueID, rz_asn1_object_t::klass, rz_asn1_list_t::length, rz_asn1_object_t::length, length, rz_asn1_object_t::list, list(), rz_asn1_list_t::objects, rz_asn1_create_binary(), rz_asn1_stringify_integer(), rz_x509_parse_algorithmidentifier(), rz_x509_parse_extensions(), rz_x509_parse_name(), rz_x509_parse_subjectpublickeyinfo(), rz_x509_parse_validity(), rz_asn1_object_t::sector, rz_x509_tbscertificate_t::serialNumber, shift(), rz_x509_tbscertificate_t::signature, rz_x509_tbscertificate_t::subject, rz_x509_tbscertificate_t::subjectPublicKeyInfo, rz_x509_tbscertificate_t::subjectUniqueID, rz_asn1_object_t::tag, test-lz4-versions::tag, TAG_INTEGER, rz_x509_tbscertificate_t::validity, and rz_x509_tbscertificate_t::version.

Referenced by rz_x509_parse_certificate().

◆ rz_x509_parse_validity()

static bool rz_x509_parse_validity ( RX509Validity validity,
RASN1Object object 
)
static

Definition at line 10 of file x509.c.

10  {
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 }
RZ_API RASN1String * rz_asn1_stringify_time(const ut8 *buffer, ut32 length)
Definition: astr.c:108
#define TAG_GENERALIZEDTIME
Definition: rz_asn1.h:56
#define TAG_UTCTIME
Definition: rz_asn1.h:55

References CLASS_UNIVERSAL, rz_asn1_object_t::form, FORM_CONSTRUCTED, FORM_PRIMITIVE, rz_asn1_object_t::klass, rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, rz_x509_validity_t::notAfter, rz_x509_validity_t::notBefore, rz_asn1_list_t::objects, rz_asn1_stringify_time(), rz_asn1_stringify_utctime(), rz_asn1_object_t::sector, rz_asn1_object_t::tag, TAG_GENERALIZEDTIME, TAG_SEQUENCE, and TAG_UTCTIME.

Referenced by rz_x509_parse_tbscertificate().

◆ rz_x509_subjectpublickeyinfo_dump()

static void rz_x509_subjectpublickeyinfo_dump ( RX509SubjectPublicKeyInfo spki,
const char *  pad,
RzStrBuf sb 
)
static

Definition at line 450 of file x509.c.

450  {
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 }
#define a(i)
Definition: sha256.c:41

References a, rz_x509_algorithmidentifier_t::algorithm, rz_x509_subjectpublickeyinfo_t::algorithm, rz_asn1_bin_t::binary, rz_asn1_bin_t::length, regress::m, NULL, pad(), rz_asn1_free_string(), rz_asn1_stringify_integer(), rz_strbuf_appendf(), sb, rz_asn1_string_t::string, rz_x509_subjectpublickeyinfo_t::subjectPublicKeyExponent, and rz_x509_subjectpublickeyinfo_t::subjectPublicKeyModule.

Referenced by rz_x509_tbscertificate_dump().

◆ rz_x509_subjectpublickeyinfo_json()

RZ_API void rz_x509_subjectpublickeyinfo_json ( PJ pj,
RX509SubjectPublicKeyInfo spki 
)

◆ rz_x509_tbscertificate_dump()

static void rz_x509_tbscertificate_dump ( RX509TBSCertificate tbsc,
const char *  pad,
RzStrBuf sb 
)
static

Definition at line 495 of file x509.c.

495  {
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 }
static void rz_x509_subjectpublickeyinfo_dump(RX509SubjectPublicKeyInfo *spki, const char *pad, RzStrBuf *sb)
Definition: x509.c:450
static void rz_x509_extensions_dump(RX509Extensions *exts, const char *pad, RzStrBuf *sb)
Definition: x509.c:472
static void rz_x509_validity_dump(RX509Validity *validity, const char *pad, RzStrBuf *sb)
Definition: x509.c:422

References rz_x509_algorithmidentifier_t::algorithm, rz_asn1_bin_t::binary, rz_x509_tbscertificate_t::extensions, free(), rz_x509_tbscertificate_t::issuer, rz_x509_tbscertificate_t::issuerUniqueID, rz_asn1_bin_t::length, NULL, pad(), rz_asn1_free_string(), rz_asn1_stringify_integer(), rz_str_newf(), rz_strbuf_appendf(), rz_x509_extensions_dump(), rz_x509_name_dump(), rz_x509_subjectpublickeyinfo_dump(), rz_x509_validity_dump(), sb, rz_x509_tbscertificate_t::serialNumber, rz_x509_tbscertificate_t::signature, rz_asn1_string_t::string, rz_x509_tbscertificate_t::subject, rz_x509_tbscertificate_t::subjectPublicKeyInfo, rz_x509_tbscertificate_t::subjectUniqueID, rz_x509_tbscertificate_t::validity, and rz_x509_tbscertificate_t::version.

Referenced by rz_x509_certificate_dump().

◆ rz_x509_tbscertificate_json()

RZ_API void rz_x509_tbscertificate_json ( PJ pj,
RX509TBSCertificate tbsc 
)

Definition at line 744 of file x509.c.

744  {
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 }
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API void rz_x509_extensions_json(PJ *pj, RX509Extensions *exts)
Definition: x509.c:671
RZ_API void rz_x509_subjectpublickeyinfo_json(PJ *pj, RX509SubjectPublicKeyInfo *spki)
Definition: x509.c:648
RZ_API void rz_x509_validity_json(PJ *pj, RX509Validity *validity)
Definition: x509.c:627

References rz_x509_algorithmidentifier_t::algorithm, rz_asn1_bin_t::binary, rz_x509_tbscertificate_t::extensions, rz_x509_tbscertificate_t::issuer, rz_x509_tbscertificate_t::issuerUniqueID, rz_asn1_bin_t::length, regress::m, NULL, pj_end(), pj_k(), pj_ki(), pj_ks(), pj_o(), rz_asn1_free_string(), rz_asn1_stringify_integer(), rz_x509_extensions_json(), rz_x509_name_json(), rz_x509_subjectpublickeyinfo_json(), rz_x509_validity_json(), rz_x509_tbscertificate_t::serialNumber, rz_x509_tbscertificate_t::signature, rz_asn1_string_t::string, rz_x509_tbscertificate_t::subject, rz_x509_tbscertificate_t::subjectPublicKeyInfo, rz_x509_tbscertificate_t::subjectUniqueID, rz_x509_tbscertificate_t::validity, and rz_x509_tbscertificate_t::version.

Referenced by rz_x509_certificate_json().

◆ rz_x509_validity_dump()

static void rz_x509_validity_dump ( RX509Validity validity,
const char *  pad,
RzStrBuf sb 
)
static

Definition at line 422 of file x509.c.

422  {
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 }
#define b(i)
Definition: sha256.c:42

References a, b, rz_x509_validity_t::notAfter, rz_x509_validity_t::notBefore, pad(), rz_strbuf_appendf(), sb, and rz_asn1_string_t::string.

Referenced by rz_x509_tbscertificate_dump().

◆ rz_x509_validity_json()

RZ_API void rz_x509_validity_json ( PJ pj,
RX509Validity validity 
)

Definition at line 627 of file x509.c.

627  {
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 }

References rz_x509_validity_t::notAfter, rz_x509_validity_t::notBefore, pj_ks(), and rz_asn1_string_t::string.

Referenced by rz_x509_tbscertificate_json().