Rizin
unix-like reverse engineering framework and cli tools
rz_pkcs7.h File Reference
#include <rz_util/rz_x509.h>

Go to the source code of this file.

Classes

struct  rz_pkcs7_certificaterevocationlists_t
 
struct  rz_pkcs7_extendedcertificatesandcertificates_t
 
struct  rz_pkcs7_digestalgorithmidentifiers_t
 
struct  rz_pkcs7_contentinfo_t
 
struct  rz_pkcs7_issuerandserialnumber_t
 
struct  rz_pkcs7_attribute_t
 
struct  rz_pkcs7_attributes_t
 
struct  rz_pkcs7_signerinfo_t
 
struct  rz_pkcs7_signerinfos_t
 
struct  rz_pkcs7_signeddata_t
 
struct  rz_pkcs7_container_t
 
struct  SpcAttributeTypeAndOptionalValue
 
struct  SpcDigestInfo
 
struct  SpcIndirectDataContent
 

Typedefs

typedef struct rz_pkcs7_certificaterevocationlists_t RPKCS7CertificateRevocationLists
 
typedef struct rz_pkcs7_extendedcertificatesandcertificates_t RPKCS7ExtendedCertificatesAndCertificates
 
typedef struct rz_pkcs7_digestalgorithmidentifiers_t RPKCS7DigestAlgorithmIdentifiers
 
typedef struct rz_pkcs7_contentinfo_t RPKCS7ContentInfo
 
typedef struct rz_pkcs7_issuerandserialnumber_t RPKCS7IssuerAndSerialNumber
 
typedef struct rz_pkcs7_attribute_t RPKCS7Attribute
 
typedef struct rz_pkcs7_attributes_t RPKCS7Attributes
 
typedef struct rz_pkcs7_signerinfo_t RPKCS7SignerInfo
 
typedef struct rz_pkcs7_signerinfos_t RPKCS7SignerInfos
 
typedef struct rz_pkcs7_signeddata_t RPKCS7SignedData
 
typedef struct rz_pkcs7_container_t RCMS
 

Functions

RZ_API RCMSrz_pkcs7_parse_cms (const ut8 *buffer, ut32 length)
 
RZ_API void rz_pkcs7_free_cms (RCMS *container)
 
RZ_API char * rz_pkcs7_cms_to_string (RCMS *container)
 
RZ_API PJrz_pkcs7_cms_json (RCMS *container)
 
RZ_API SpcIndirectDataContentrz_pkcs7_parse_spcinfo (RCMS *cms)
 
RZ_API void rz_pkcs7_free_spcinfo (SpcIndirectDataContent *spcinfo)
 

Typedef Documentation

◆ RCMS

typedef struct rz_pkcs7_container_t RCMS

◆ RPKCS7Attribute

◆ RPKCS7Attributes

◆ RPKCS7CertificateRevocationLists

◆ RPKCS7ContentInfo

◆ RPKCS7DigestAlgorithmIdentifiers

◆ RPKCS7ExtendedCertificatesAndCertificates

◆ RPKCS7IssuerAndSerialNumber

◆ RPKCS7SignedData

◆ RPKCS7SignerInfo

◆ RPKCS7SignerInfos

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_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
RZ_API void rz_asn1_free_string(RASN1String *string)
Definition: astr.c:313
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_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_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
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
Definition: buffer.h:15
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_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_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
#define RZ_FREE(x)
Definition: rz_types.h:369
ut32 length
Definition: rz_asn1.h:75
ut8 * binary
Definition: rz_asn1.h:76
RASN1Binary * content
Definition: rz_pkcs7.h:27
RASN1String * contentType
Definition: rz_pkcs7.h:26
RPKCS7ContentInfo contentInfo
Definition: rz_pkcs7.h:63

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().