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

Go to the source code of this file.

Functions

void rz_x509_name_json (PJ *pj, RX509Name *name)
 
void rz_x509_free_crl (RX509CertificateRevocationList *crl)
 
void rz_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RzStrBuf *sb)
 
static bool rz_pkcs7_parse_attributes (RPKCS7Attributes *attribute, RASN1Object *object)
 
static bool rz_pkcs7_parse_contentinfo (RPKCS7ContentInfo *ci, RASN1Object *object)
 
static bool rz_pkcs7_parse_certificaterevocationlists (RPKCS7CertificateRevocationLists *crls, RASN1Object *object)
 
static void rz_pkcs7_free_certificaterevocationlists (RPKCS7CertificateRevocationLists *crls)
 
static bool rz_pkcs7_parse_extendedcertificatesandcertificates (RPKCS7ExtendedCertificatesAndCertificates *ecac, RASN1Object *object)
 
static void rz_pkcs7_free_extendedcertificatesandcertificates (RPKCS7ExtendedCertificatesAndCertificates *ecac)
 
static bool rz_pkcs7_parse_digestalgorithmidentifier (RPKCS7DigestAlgorithmIdentifiers *dai, RASN1Object *object)
 
static void rz_pkcs7_free_digestalgorithmidentifier (RPKCS7DigestAlgorithmIdentifiers *dai)
 
static void rz_pkcs7_free_contentinfo (RPKCS7ContentInfo *ci)
 
static bool rz_pkcs7_parse_issuerandserialnumber (RPKCS7IssuerAndSerialNumber *iasu, RASN1Object *object)
 
static void rz_pkcs7_free_issuerandserialnumber (RPKCS7IssuerAndSerialNumber *iasu)
 
static bool rz_pkcs7_parse_signerinfo (RPKCS7SignerInfo *si, RASN1Object *object)
 
static void rz_pkcs7_free_attribute (RPKCS7Attribute *attribute)
 
static void rz_pkcs7_free_attributes (RPKCS7Attributes *attributes)
 
static void rz_pkcs7_free_signerinfo (RPKCS7SignerInfo *si)
 
static bool rz_pkcs7_parse_signerinfos (RPKCS7SignerInfos *ss, RASN1Object *object)
 
static void rz_pkcs7_free_signerinfos (RPKCS7SignerInfos *ss)
 
static bool rz_pkcs7_parse_signeddata (RPKCS7SignedData *sd, RASN1Object *object)
 
static void rz_pkcs7_free_signeddata (RPKCS7SignedData *sd)
 
RZ_API RCMSrz_pkcs7_parse_cms (const ut8 *buffer, ut32 length)
 
RZ_API void rz_pkcs7_free_cms (RCMS *container)
 
static RPKCS7Attributerz_pkcs7_parse_attribute (RASN1Object *object)
 
static void rz_x509_signedinfo_dump (RPKCS7SignerInfo *si, const char *pad, RzStrBuf *sb)
 
RZ_API char * rz_pkcs7_cms_to_string (RCMS *container)
 
RZ_API void rz_x509_signedinfo_json (PJ *pj, RPKCS7SignerInfo *si)
 
RZ_API PJrz_pkcs7_cms_json (RCMS *container)
 
static bool rz_pkcs7_parse_spcdata (SpcAttributeTypeAndOptionalValue *data, RASN1Object *object)
 
static bool rz_pkcs7_parse_spcmessagedigest (SpcDigestInfo *messageDigest, RASN1Object *object)
 
RZ_API SpcIndirectDataContentrz_pkcs7_parse_spcinfo (RCMS *cms)
 
static void rz_pkcs7_free_spcdata (SpcAttributeTypeAndOptionalValue *data)
 
static void rz_pkcs7_free_spcmessagedigest (SpcDigestInfo *messageDigest)
 
RZ_API void rz_pkcs7_free_spcinfo (SpcIndirectDataContent *spcinfo)
 

Function Documentation

◆ rz_pkcs7_cms_json()

RZ_API PJ* rz_pkcs7_cms_json ( RCMS container)

Definition at line 592 of file pkcs7.c.

592  {
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 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
RZ_API void rz_x509_signedinfo_json(PJ *pj, RPKCS7SignerInfo *si)
Definition: pkcs7.c:520
static RzSocket * s
Definition: rtr.c:28
RZ_API PJ * pj_new(void)
Definition: pj.c:25
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_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 void rz_x509_crl_json(PJ *pj, RX509CertificateRevocationList *crl)
Definition: x509.c:719
RZ_API void rz_x509_certificate_json(PJ *pj, RX509Certificate *certificate)
Definition: x509.c:790
Definition: rz_pj.h:12
RX509CertificateRevocationList ** elements
Definition: rz_pkcs7.h:12
RPKCS7SignedData signedData
Definition: rz_pkcs7.h:71
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
RPKCS7SignerInfo ** elements
Definition: rz_pkcs7.h:57
RASN1String * algorithm
Definition: rz_x509.h:27

References rz_x509_algorithmidentifier_t::algorithm, rz_pkcs7_signeddata_t::certificates, rz_pkcs7_signeddata_t::crls, rz_pkcs7_signeddata_t::digestAlgorithms, rz_pkcs7_certificaterevocationlists_t::elements, rz_pkcs7_extendedcertificatesandcertificates_t::elements, rz_pkcs7_digestalgorithmidentifiers_t::elements, rz_pkcs7_signerinfos_t::elements, i, rz_pkcs7_certificaterevocationlists_t::length, rz_pkcs7_extendedcertificatesandcertificates_t::length, rz_pkcs7_digestalgorithmidentifiers_t::length, rz_pkcs7_signerinfos_t::length, NULL, pj_a(), pj_end(), pj_k(), pj_kn(), pj_new(), pj_o(), pj_s(), rz_x509_certificate_json(), rz_x509_crl_json(), rz_x509_signedinfo_json(), s, rz_pkcs7_container_t::signedData, rz_pkcs7_signeddata_t::signerinfos, and rz_pkcs7_signeddata_t::version.

Referenced by signature().

◆ rz_pkcs7_cms_to_string()

RZ_API char* rz_pkcs7_cms_to_string ( RCMS container)

Definition at line 479 of file pkcs7.c.

479  {
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 }
static SblHeader sb
Definition: bin_mbn.c:26
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static void rz_x509_signedinfo_dump(RPKCS7SignerInfo *si, const char *pad, RzStrBuf *sb)
Definition: pkcs7.c:421
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
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

References rz_x509_algorithmidentifier_t::algorithm, rz_pkcs7_signeddata_t::certificates, rz_pkcs7_signeddata_t::crls, rz_pkcs7_signeddata_t::digestAlgorithms, rz_pkcs7_certificaterevocationlists_t::elements, rz_pkcs7_extendedcertificatesandcertificates_t::elements, rz_pkcs7_digestalgorithmidentifiers_t::elements, rz_pkcs7_signerinfos_t::elements, free(), i, rz_pkcs7_certificaterevocationlists_t::length, rz_pkcs7_extendedcertificatesandcertificates_t::length, rz_pkcs7_digestalgorithmidentifiers_t::length, rz_pkcs7_signerinfos_t::length, NULL, rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), rz_x509_certificate_dump(), rz_x509_crl_to_string(), rz_x509_signedinfo_dump(), s, sb, rz_pkcs7_container_t::signedData, rz_pkcs7_signeddata_t::signerinfos, and rz_pkcs7_signeddata_t::version.

Referenced by cmd_print_fromage(), and signature().

◆ rz_pkcs7_free_attribute()

static void rz_pkcs7_free_attribute ( RPKCS7Attribute attribute)
static

Definition at line 202 of file pkcs7.c.

202  {
203  if (attribute) {
204  rz_asn1_free_binary(attribute->data);
205  rz_asn1_free_string(attribute->oid);
206  free(attribute);
207  }
208 }
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
RASN1Binary * data
Definition: rz_pkcs7.h:37
RASN1String * oid
Definition: rz_pkcs7.h:36

References rz_pkcs7_attribute_t::data, free(), rz_pkcs7_attribute_t::oid, rz_asn1_free_binary(), and rz_asn1_free_string().

Referenced by rz_pkcs7_free_attributes().

◆ rz_pkcs7_free_attributes()

static void rz_pkcs7_free_attributes ( RPKCS7Attributes attributes)
static

Definition at line 210 of file pkcs7.c.

210  {
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 }
static void rz_pkcs7_free_attribute(RPKCS7Attribute *attribute)
Definition: pkcs7.c:202
#define RZ_FREE(x)
Definition: rz_types.h:369
RPKCS7Attribute ** elements
Definition: rz_pkcs7.h:42

References rz_pkcs7_attributes_t::elements, i, rz_pkcs7_attributes_t::length, RZ_FREE, and rz_pkcs7_free_attribute().

Referenced by rz_pkcs7_free_signerinfo().

◆ rz_pkcs7_free_certificaterevocationlists()

static void rz_pkcs7_free_certificaterevocationlists ( RPKCS7CertificateRevocationLists crls)
static

Definition at line 46 of file pkcs7.c.

46  {
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 }
void rz_x509_free_crl(RX509CertificateRevocationList *crl)
Definition: x509.c:404

References rz_pkcs7_certificaterevocationlists_t::elements, i, rz_pkcs7_certificaterevocationlists_t::length, NULL, RZ_FREE, and rz_x509_free_crl().

Referenced by rz_pkcs7_free_signeddata().

◆ rz_pkcs7_free_cms()

RZ_API void rz_pkcs7_free_cms ( RCMS container)

Definition at line 341 of file pkcs7.c.

341  {
342  if (container) {
343  rz_asn1_free_string(container->contentType);
345  free(container);
346  }
347 }
static void rz_pkcs7_free_signeddata(RPKCS7SignedData *sd)
Definition: pkcs7.c:297
RASN1String * contentType
Definition: rz_pkcs7.h:70

References rz_pkcs7_container_t::contentType, free(), rz_asn1_free_string(), rz_pkcs7_free_signeddata(), and rz_pkcs7_container_t::signedData.

Referenced by cmd_print_fromage(), and rz_bin_pe_free().

◆ rz_pkcs7_free_contentinfo()

static void rz_pkcs7_free_contentinfo ( RPKCS7ContentInfo ci)
static

Definition at line 132 of file pkcs7.c.

132  {
133  if (ci) {
136  // Used internally pkcs #7, so it shouldn't free ci.
137  }
138 }
RASN1Binary * content
Definition: rz_pkcs7.h:27
RASN1String * contentType
Definition: rz_pkcs7.h:26

References rz_pkcs7_contentinfo_t::content, rz_pkcs7_contentinfo_t::contentType, rz_asn1_free_binary(), and rz_asn1_free_string().

Referenced by rz_pkcs7_free_signeddata().

◆ rz_pkcs7_free_digestalgorithmidentifier()

static void rz_pkcs7_free_digestalgorithmidentifier ( RPKCS7DigestAlgorithmIdentifiers dai)
static

Definition at line 116 of file pkcs7.c.

116  {
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 }
RZ_API void rz_x509_free_algorithmidentifier(RX509AlgorithmIdentifier *ai)
Definition: x509.c:306

References rz_pkcs7_digestalgorithmidentifiers_t::elements, i, rz_pkcs7_digestalgorithmidentifiers_t::length, RZ_FREE, and rz_x509_free_algorithmidentifier().

Referenced by rz_pkcs7_free_signeddata().

◆ rz_pkcs7_free_extendedcertificatesandcertificates()

static void rz_pkcs7_free_extendedcertificatesandcertificates ( RPKCS7ExtendedCertificatesAndCertificates ecac)
static

Definition at line 77 of file pkcs7.c.

77  {
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 }
RZ_API void rz_x509_free_certificate(RX509Certificate *certificate)
Definition: x509.c:387

References rz_pkcs7_extendedcertificatesandcertificates_t::elements, i, rz_pkcs7_extendedcertificatesandcertificates_t::length, NULL, RZ_FREE, and rz_x509_free_certificate().

Referenced by rz_pkcs7_free_signeddata().

◆ rz_pkcs7_free_issuerandserialnumber()

static void rz_pkcs7_free_issuerandserialnumber ( RPKCS7IssuerAndSerialNumber iasu)
static

Definition at line 152 of file pkcs7.c.

152  {
153  if (iasu) {
154  rz_x509_free_name(&iasu->issuer);
156  // Used internally pkcs #7, so it shouldn't free iasu.
157  }
158 }
RZ_API void rz_x509_free_name(RX509Name *name)
Definition: x509.c:322

References rz_pkcs7_issuerandserialnumber_t::issuer, rz_asn1_free_binary(), rz_x509_free_name(), and rz_pkcs7_issuerandserialnumber_t::serialNumber.

Referenced by rz_pkcs7_free_signerinfo().

◆ rz_pkcs7_free_signeddata()

static void rz_pkcs7_free_signeddata ( RPKCS7SignedData sd)
static

Definition at line 297 of file pkcs7.c.

297  {
298  if (sd) {
304  // Used internally pkcs #7, so it shouldn't free sd.
305  }
306 }
static void rz_pkcs7_free_signerinfos(RPKCS7SignerInfos *ss)
Definition: pkcs7.c:256
static void rz_pkcs7_free_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac)
Definition: pkcs7.c:77
static void rz_pkcs7_free_contentinfo(RPKCS7ContentInfo *ci)
Definition: pkcs7.c:132
static void rz_pkcs7_free_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai)
Definition: pkcs7.c:116
static void rz_pkcs7_free_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls)
Definition: pkcs7.c:46
RPKCS7ContentInfo contentInfo
Definition: rz_pkcs7.h:63

References rz_pkcs7_signeddata_t::certificates, rz_pkcs7_signeddata_t::contentInfo, rz_pkcs7_signeddata_t::crls, rz_pkcs7_signeddata_t::digestAlgorithms, rz_pkcs7_free_certificaterevocationlists(), rz_pkcs7_free_contentinfo(), rz_pkcs7_free_digestalgorithmidentifier(), rz_pkcs7_free_extendedcertificatesandcertificates(), rz_pkcs7_free_signerinfos(), and rz_pkcs7_signeddata_t::signerinfos.

Referenced by rz_pkcs7_free_cms().

◆ rz_pkcs7_free_signerinfo()

static void rz_pkcs7_free_signerinfo ( RPKCS7SignerInfo si)
static

Definition at line 221 of file pkcs7.c.

221  {
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 }
si
static void rz_pkcs7_free_attributes(RPKCS7Attributes *attributes)
Definition: pkcs7.c:210
static void rz_pkcs7_free_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu)
Definition: pkcs7.c:152

References free(), rz_asn1_free_binary(), rz_pkcs7_free_attributes(), rz_pkcs7_free_issuerandserialnumber(), rz_x509_free_algorithmidentifier(), and si.

Referenced by rz_pkcs7_free_signerinfos().

◆ rz_pkcs7_free_signerinfos()

static void rz_pkcs7_free_signerinfos ( RPKCS7SignerInfos ss)
static

Definition at line 256 of file pkcs7.c.

256  {
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 }
static void rz_pkcs7_free_signerinfo(RPKCS7SignerInfo *si)
Definition: pkcs7.c:221

References rz_pkcs7_signerinfos_t::elements, i, rz_pkcs7_signerinfos_t::length, NULL, RZ_FREE, and rz_pkcs7_free_signerinfo().

Referenced by rz_pkcs7_free_signeddata().

◆ rz_pkcs7_free_spcdata()

static void rz_pkcs7_free_spcdata ( SpcAttributeTypeAndOptionalValue data)
static

Definition at line 715 of file pkcs7.c.

715  {
716  if (data) {
717  rz_asn1_free_string(data->type);
718  rz_asn1_free_binary(data->data);
719  }
720 }

References SpcAttributeTypeAndOptionalValue::data, rz_asn1_free_binary(), rz_asn1_free_string(), and SpcAttributeTypeAndOptionalValue::type.

Referenced by rz_pkcs7_free_spcinfo().

◆ rz_pkcs7_free_spcinfo()

RZ_API void rz_pkcs7_free_spcinfo ( SpcIndirectDataContent spcinfo)

Definition at line 729 of file pkcs7.c.

729  {
730  if (spcinfo) {
731  rz_pkcs7_free_spcdata(&spcinfo->data);
733  }
734 }
static void rz_pkcs7_free_spcdata(SpcAttributeTypeAndOptionalValue *data)
Definition: pkcs7.c:715
static void rz_pkcs7_free_spcmessagedigest(SpcDigestInfo *messageDigest)
Definition: pkcs7.c:722
SpcAttributeTypeAndOptionalValue data
Definition: rz_pkcs7.h:85
SpcDigestInfo messageDigest
Definition: rz_pkcs7.h:86

References SpcIndirectDataContent::data, SpcIndirectDataContent::messageDigest, rz_pkcs7_free_spcdata(), and rz_pkcs7_free_spcmessagedigest().

Referenced by rz_bin_pe_free().

◆ rz_pkcs7_free_spcmessagedigest()

static void rz_pkcs7_free_spcmessagedigest ( SpcDigestInfo messageDigest)
static

Definition at line 722 of file pkcs7.c.

722  {
723  if (messageDigest) {
724  rz_asn1_free_binary(messageDigest->digest);
726  }
727 }
RASN1Binary * digest
Definition: rz_pkcs7.h:81
RX509AlgorithmIdentifier digestAlgorithm
Definition: rz_pkcs7.h:80

References SpcDigestInfo::digest, SpcDigestInfo::digestAlgorithm, rz_asn1_free_binary(), and rz_x509_free_algorithmidentifier().

Referenced by rz_pkcs7_free_spcinfo().

◆ rz_pkcs7_parse_attribute()

static RPKCS7Attribute* rz_pkcs7_parse_attribute ( RASN1Object object)
static

Definition at line 349 of file pkcs7.c.

349  {
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 }
RZ_API RASN1Binary * rz_asn1_create_binary(const ut8 *buffer, ut32 length)
Definition: asn1.c:152
RZ_API RASN1String * rz_asn1_stringify_oid(const ut8 *buffer, ut32 length)
Definition: astr.c:249
#define RZ_NEW0(x)
Definition: rz_types.h:284
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

References rz_pkcs7_attribute_t::data, rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, NULL, rz_asn1_list_t::objects, rz_pkcs7_attribute_t::oid, rz_asn1_create_binary(), rz_asn1_stringify_oid(), RZ_NEW0, and rz_asn1_object_t::sector.

Referenced by rz_pkcs7_parse_attributes().

◆ rz_pkcs7_parse_attributes()

static bool rz_pkcs7_parse_attributes ( RPKCS7Attributes attribute,
RASN1Object object 
)
static

Definition at line 370 of file pkcs7.c.

370  {
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 }
static RPKCS7Attribute * rz_pkcs7_parse_attribute(RASN1Object *object)
Definition: pkcs7.c:349
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282

References rz_pkcs7_attributes_t::elements, i, rz_asn1_list_t::length, rz_pkcs7_attributes_t::length, rz_asn1_object_t::list, rz_asn1_list_t::objects, RZ_NEWS0, and rz_pkcs7_parse_attribute().

Referenced by rz_pkcs7_parse_signerinfo().

◆ rz_pkcs7_parse_certificaterevocationlists()

static bool rz_pkcs7_parse_certificaterevocationlists ( RPKCS7CertificateRevocationLists crls,
RASN1Object object 
)
static

Definition at line 28 of file pkcs7.c.

28  {
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 }
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API RX509CertificateRevocationList * rz_x509_parse_crl(RASN1Object *object)
Definition: x509.c:275

References calloc(), rz_pkcs7_certificaterevocationlists_t::elements, i, rz_asn1_list_t::length, rz_pkcs7_certificaterevocationlists_t::length, rz_asn1_object_t::list, rz_asn1_list_t::objects, and rz_x509_parse_crl().

Referenced by rz_pkcs7_parse_signeddata().

◆ rz_pkcs7_parse_cms()

RZ_API RCMS* rz_pkcs7_parse_cms ( const ut8 buffer,
ut32  length 
)

Definition at line 308 of file pkcs7.c.

308  {
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 }
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
static bool rz_pkcs7_parse_signeddata(RPKCS7SignedData *sd, RASN1Object *object)
Definition: pkcs7.c:268
RZ_API void rz_asn1_free_object(RASN1Object *object)
Definition: asn1.c:445
RZ_API RASN1Object * rz_asn1_create_object(const ut8 *buffer, ut32 length, const ut8 *start_pointer)
Definition: asn1.c:120
Definition: buffer.h:15

References rz_pkcs7_container_t::contentType, free(), rz_asn1_list_t::length, rz_asn1_object_t::length, length, rz_asn1_object_t::list, NULL, rz_asn1_list_t::objects, rz_asn1_create_object(), rz_asn1_free_object(), rz_asn1_stringify_oid(), RZ_NEW0, rz_pkcs7_parse_signeddata(), rz_asn1_object_t::sector, and rz_pkcs7_container_t::signedData.

Referenced by bin_pe_init_security(), and cmd_print_fromage().

◆ rz_pkcs7_parse_contentinfo()

static bool rz_pkcs7_parse_contentinfo ( RPKCS7ContentInfo ci,
RASN1Object object 
)
static

Definition at line 14 of file pkcs7.c.

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

References rz_pkcs7_contentinfo_t::content, rz_pkcs7_contentinfo_t::contentType, 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(), and rz_asn1_object_t::sector.

Referenced by rz_pkcs7_parse_signeddata().

◆ rz_pkcs7_parse_digestalgorithmidentifier()

static bool rz_pkcs7_parse_digestalgorithmidentifier ( RPKCS7DigestAlgorithmIdentifiers dai,
RASN1Object object 
)
static

Definition at line 89 of file pkcs7.c.

89  {
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 }
return memset(p, 0, total)
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API bool rz_x509_parse_algorithmidentifier(RX509AlgorithmIdentifier *ai, RASN1Object *object)
Definition: x509.c:44

References calloc(), rz_pkcs7_digestalgorithmidentifiers_t::elements, i, rz_asn1_list_t::length, rz_pkcs7_digestalgorithmidentifiers_t::length, rz_asn1_object_t::list, malloc(), memset(), rz_asn1_list_t::objects, and rz_x509_parse_algorithmidentifier().

Referenced by rz_pkcs7_parse_signeddata().

◆ rz_pkcs7_parse_extendedcertificatesandcertificates()

static bool rz_pkcs7_parse_extendedcertificatesandcertificates ( RPKCS7ExtendedCertificatesAndCertificates ecac,
RASN1Object object 
)
static

Definition at line 58 of file pkcs7.c.

58  {
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 }
RZ_API RX509Certificate * rz_x509_parse_certificate(RASN1Object *object)
Definition: x509.c:217

References calloc(), rz_pkcs7_extendedcertificatesandcertificates_t::elements, i, rz_asn1_list_t::length, rz_pkcs7_extendedcertificatesandcertificates_t::length, rz_asn1_object_t::list, NULL, rz_asn1_list_t::objects, and rz_x509_parse_certificate().

Referenced by rz_pkcs7_parse_signeddata().

◆ rz_pkcs7_parse_issuerandserialnumber()

static bool rz_pkcs7_parse_issuerandserialnumber ( RPKCS7IssuerAndSerialNumber iasu,
RASN1Object object 
)
static

Definition at line 140 of file pkcs7.c.

140  {
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 }
RZ_API bool rz_x509_parse_name(RX509Name *name, RASN1Object *object)
Definition: x509.c:79

References rz_pkcs7_issuerandserialnumber_t::issuer, 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_x509_parse_name(), rz_asn1_object_t::sector, and rz_pkcs7_issuerandserialnumber_t::serialNumber.

Referenced by rz_pkcs7_parse_signerinfo().

◆ rz_pkcs7_parse_signeddata()

static bool rz_pkcs7_parse_signeddata ( RPKCS7SignedData sd,
RASN1Object object 
)
static

Definition at line 268 of file pkcs7.c.

268  {
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 }
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
static bool rz_pkcs7_parse_contentinfo(RPKCS7ContentInfo *ci, RASN1Object *object)
Definition: pkcs7.c:14
static bool rz_pkcs7_parse_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai, RASN1Object *object)
Definition: pkcs7.c:89
static bool rz_pkcs7_parse_signerinfos(RPKCS7SignerInfos *ss, RASN1Object *object)
Definition: pkcs7.c:233
static bool rz_pkcs7_parse_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac, RASN1Object *object)
Definition: pkcs7.c:58
static bool rz_pkcs7_parse_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls, RASN1Object *object)
Definition: pkcs7.c:28
#define CLASS_CONTEXT
Definition: rz_asn1.h:27

References rz_pkcs7_signeddata_t::certificates, CLASS_CONTEXT, rz_pkcs7_signeddata_t::contentInfo, rz_pkcs7_signeddata_t::crls, rz_pkcs7_signeddata_t::digestAlgorithms, rz_asn1_object_t::klass, rz_asn1_list_t::length, rz_asn1_object_t::list, list(), memset(), rz_asn1_list_t::objects, rz_pkcs7_parse_certificaterevocationlists(), rz_pkcs7_parse_contentinfo(), rz_pkcs7_parse_digestalgorithmidentifier(), rz_pkcs7_parse_extendedcertificatesandcertificates(), rz_pkcs7_parse_signerinfos(), shift(), rz_pkcs7_signeddata_t::signerinfos, rz_asn1_object_t::tag, and rz_pkcs7_signeddata_t::version.

Referenced by rz_pkcs7_parse_cms().

◆ rz_pkcs7_parse_signerinfo()

static bool rz_pkcs7_parse_signerinfo ( RPKCS7SignerInfo si,
RASN1Object object 
)
static

Definition at line 167 of file pkcs7.c.

167  {
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 }
static bool rz_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object)
Definition: pkcs7.c:370
static bool rz_pkcs7_parse_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu, RASN1Object *object)
Definition: pkcs7.c:140

References CLASS_CONTEXT, rz_asn1_object_t::klass, rz_asn1_list_t::length, rz_asn1_object_t::length, rz_asn1_object_t::list, list(), rz_asn1_list_t::objects, rz_asn1_create_binary(), rz_pkcs7_parse_attributes(), rz_pkcs7_parse_issuerandserialnumber(), rz_x509_parse_algorithmidentifier(), rz_asn1_object_t::sector, shift(), si, and rz_asn1_object_t::tag.

Referenced by rz_pkcs7_parse_signerinfos().

◆ rz_pkcs7_parse_signerinfos()

static bool rz_pkcs7_parse_signerinfos ( RPKCS7SignerInfos ss,
RASN1Object object 
)
static

Definition at line 233 of file pkcs7.c.

233  {
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 }
static bool rz_pkcs7_parse_signerinfo(RPKCS7SignerInfo *si, RASN1Object *object)
Definition: pkcs7.c:167

References calloc(), rz_pkcs7_signerinfos_t::elements, i, rz_asn1_list_t::length, rz_pkcs7_signerinfos_t::length, rz_asn1_object_t::list, rz_asn1_list_t::objects, RZ_NEW0, and rz_pkcs7_parse_signerinfo().

Referenced by rz_pkcs7_parse_signeddata().

◆ rz_pkcs7_parse_spcdata()

static bool rz_pkcs7_parse_spcdata ( SpcAttributeTypeAndOptionalValue data,
RASN1Object object 
)
static

Definition at line 643 of file pkcs7.c.

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

References SpcAttributeTypeAndOptionalValue::data, 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, and SpcAttributeTypeAndOptionalValue::type.

Referenced by rz_pkcs7_parse_spcinfo().

◆ rz_pkcs7_parse_spcinfo()

RZ_API SpcIndirectDataContent* rz_pkcs7_parse_spcinfo ( RCMS cms)

Definition at line 674 of file pkcs7.c.

674  {
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 }
int type
Definition: mipsasm.c:17
static bool rz_pkcs7_parse_spcdata(SpcAttributeTypeAndOptionalValue *data, RASN1Object *object)
Definition: pkcs7.c:643
static bool rz_pkcs7_parse_spcmessagedigest(SpcDigestInfo *messageDigest, RASN1Object *object)
Definition: pkcs7.c:661
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
ut32 length
Definition: rz_asn1.h:75
ut8 * binary
Definition: rz_asn1.h:76

References rz_asn1_bin_t::binary, rz_pkcs7_contentinfo_t::content, rz_pkcs7_signeddata_t::contentInfo, rz_pkcs7_contentinfo_t::contentType, SpcIndirectDataContent::data, free(), rz_asn1_list_t::length, rz_asn1_bin_t::length, rz_asn1_object_t::list, SpcIndirectDataContent::messageDigest, NULL, rz_asn1_list_t::objects, rz_asn1_create_object(), rz_asn1_free_object(), RZ_FREE, RZ_NEW0, rz_pkcs7_parse_spcdata(), rz_pkcs7_parse_spcmessagedigest(), rz_return_val_if_fail, rz_pkcs7_container_t::signedData, and type.

Referenced by bin_pe_init_security().

◆ rz_pkcs7_parse_spcmessagedigest()

static bool rz_pkcs7_parse_spcmessagedigest ( SpcDigestInfo messageDigest,
RASN1Object object 
)
static

Definition at line 661 of file pkcs7.c.

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

References SpcDigestInfo::digest, SpcDigestInfo::digestAlgorithm, 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_x509_parse_algorithmidentifier(), and rz_asn1_object_t::sector.

Referenced by rz_pkcs7_parse_spcinfo().

◆ 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
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
RZ_API RASN1String * rz_asn1_stringify_integer(const ut8 *buffer, ut32 length)
Definition: astr.c:185
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_free_crl()

void rz_x509_free_crl ( RX509CertificateRevocationList crl)

Definition at line 404 of file x509.c.

404  {
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 }
RX509AlgorithmIdentifier signature
Definition: rz_x509.h:101
RX509CRLEntry ** revokedCertificates
Definition: rz_x509.h:106
static void rz_x509_free_crlentry(RX509CRLEntry *entry)
Definition: x509.c:396

References free(), i, rz_x509_certificaterevocationlist::issuer, rz_x509_certificaterevocationlist::lastUpdate, rz_x509_certificaterevocationlist::length, rz_x509_certificaterevocationlist::nextUpdate, NULL, rz_x509_certificaterevocationlist::revokedCertificates, rz_asn1_free_string(), RZ_FREE, rz_x509_free_algorithmidentifier(), rz_x509_free_crlentry(), rz_x509_free_name(), and rz_x509_certificaterevocationlist::signature.

Referenced by rz_pkcs7_free_certificaterevocationlists().

◆ rz_x509_name_json()

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 }
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
Definition: z80asm.h:102

References i, and pj_ks().

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

◆ rz_x509_signedinfo_dump()

static void rz_x509_signedinfo_dump ( RPKCS7SignerInfo si,
const char *  pad,
RzStrBuf sb 
)
static

Definition at line 421 of file pkcs7.c.

421  {
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 }
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
const char * string
Definition: rz_asn1.h:65
RZ_API void rz_x509_name_dump(RX509Name *name, const char *pad, RzStrBuf *sb)
Definition: x509.c:434

References rz_asn1_bin_t::binary, rz_pkcs7_attribute_t::data, eprintf, free(), i, rz_asn1_bin_t::length, NULL, rz_pkcs7_attribute_t::oid, pad(), rz_asn1_free_string(), rz_asn1_stringify_integer(), rz_str_newf(), rz_strbuf_appendf(), rz_x509_name_dump(), s, sb, si, and rz_asn1_string_t::string.

Referenced by rz_pkcs7_cms_to_string().

◆ rz_x509_signedinfo_json()

RZ_API void rz_x509_signedinfo_json ( PJ pj,
RPKCS7SignerInfo si 
)

Definition at line 520 of file pkcs7.c.

520  {
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 }
void rz_x509_name_json(PJ *pj, RX509Name *name)
Definition: x509.c:638
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149

References rz_asn1_bin_t::binary, rz_pkcs7_attribute_t::data, i, rz_asn1_bin_t::length, rz_pkcs7_attribute_t::oid, pj_a(), pj_end(), pj_k(), pj_ki(), pj_ks(), pj_o(), rz_asn1_free_string(), rz_asn1_stringify_integer(), rz_x509_name_json(), s, si, and rz_asn1_string_t::string.

Referenced by rz_pkcs7_cms_json().