mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-21 23:01:03 +00:00
Use pj for X509 and PKCS (#12877)
* Convert R_JSON to pj * Ident * iCj support * Change return type * Fix @deroad comments * Fix last issue * Fix empty output
This commit is contained in:
parent
2032399ca8
commit
21cde44c7d
@ -107,11 +107,16 @@ static char *signature (RBinFile *bf, bool json) {
|
||||
return NULL;
|
||||
}
|
||||
struct PE_ (r_bin_pe_obj_t) * bin = bf->o->bin_obj;
|
||||
char *json_str = NULL;
|
||||
if (json) {
|
||||
RJSVar *json = r_pkcs7_cms_json (bin->cms);
|
||||
char *c = r_json_stringify (json, false);
|
||||
r_json_var_free (json);
|
||||
return c;
|
||||
PJ *pj = r_pkcs7_cms_json (bin->cms);
|
||||
if (pj) {
|
||||
json_str = strdup((char *)pj_string(pj));
|
||||
pj_free (pj);
|
||||
return json_str;
|
||||
}
|
||||
json_str = strdup ("{}");
|
||||
return json_str;
|
||||
}
|
||||
return r_pkcs7_cms_to_string (bin->cms);
|
||||
}
|
||||
|
@ -68,9 +68,9 @@ int gettimeofday (struct timeval* p, void* tz);
|
||||
#include "r_util/r_idpool.h"
|
||||
#include "r_util/r_asn1.h"
|
||||
#include "r_util/r_json.h"
|
||||
#include "r_util/pj.h"
|
||||
#include "r_util/r_x509.h"
|
||||
#include "r_util/r_pkcs7.h"
|
||||
#include "r_util/pj.h"
|
||||
// requires io, core, ... #include "r_util/r_print.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -72,7 +72,7 @@ typedef struct r_pkcs7_container_t {
|
||||
R_API RCMS *r_pkcs7_parse_cms(const ut8 *buffer, ut32 length);
|
||||
R_API void r_pkcs7_free_cms(RCMS* container);
|
||||
R_API char *r_pkcs7_cms_to_string(RCMS* container);
|
||||
R_API RJSVar *r_pkcs7_cms_json(RCMS* container);
|
||||
R_API PJ *r_pkcs7_cms_json(RCMS* container);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -108,13 +108,13 @@ R_API RX509CertificateRevocationList* r_x509_parse_crl(RASN1Object *object);
|
||||
// R_API void r_x509_free_crl(RX509CertificateRevocationList *crl);
|
||||
// R_API void r_x509_crl_dump(RX509CertificateRevocationList *crl, const char* pad);
|
||||
R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char* pad);
|
||||
R_API RJSVar *r_x509_crl_json(RX509CertificateRevocationList *crl);
|
||||
R_API void r_x509_crl_json(PJ* pj, RX509CertificateRevocationList *crl);
|
||||
|
||||
R_API RX509Certificate *r_x509_parse_certificate(RASN1Object *object);
|
||||
R_API RX509Certificate *r_x509_parse_certificate2(const ut8 *buffer, ut32 length);
|
||||
R_API void r_x509_free_certificate(RX509Certificate* certificate);
|
||||
R_API char *r_x509_certificate_to_string(RX509Certificate* certificate, const char* pad);
|
||||
R_API RJSVar* r_x509_certificate_json(RX509Certificate *certificate);
|
||||
R_API void r_x509_certificate_json(PJ* pj, RX509Certificate *certificate);
|
||||
R_API void r_x509_certificate_dump(RX509Certificate* cert, const char* pad, RStrBuf *sb);
|
||||
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
#include <r_util.h>
|
||||
#include "./x509.h"
|
||||
|
||||
extern RJSVar *r_x509_name_json (RX509Name* name);
|
||||
extern void *r_x509_name_json (PJ *pj, RX509Name *name);
|
||||
extern void r_x509_free_crl (RX509CertificateRevocationList *crl);
|
||||
extern void r_x509_crlentry_dump (RX509CRLEntry *crle, const char* pad, RStrBuf *sb);
|
||||
static bool r_pkcs7_parse_attributes (RPKCS7Attributes* attribute, RASN1Object *object);
|
||||
extern void r_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb);
|
||||
static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object);
|
||||
|
||||
static bool r_pkcs7_parse_contentinfo (RPKCS7ContentInfo* ci, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_contentinfo(RPKCS7ContentInfo *ci, RASN1Object *object) {
|
||||
if (!ci || !object || object->list.length < 1 || !object->list.objects[0]) {
|
||||
return false;
|
||||
}
|
||||
@ -24,13 +24,13 @@ static bool r_pkcs7_parse_contentinfo (RPKCS7ContentInfo* ci, RASN1Object *objec
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool r_pkcs7_parse_certificaterevocationlists (RPKCS7CertificateRevocationLists *crls, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls, RASN1Object *object) {
|
||||
ut32 i;
|
||||
if (!crls || !object) {
|
||||
return false;
|
||||
}
|
||||
if (object->list.length > 0) {
|
||||
crls->elements = (RX509CertificateRevocationList **) calloc (object->list.length, sizeof (RX509CertificateRevocationList*));
|
||||
crls->elements = (RX509CertificateRevocationList **)calloc (object->list.length, sizeof (RX509CertificateRevocationList *));
|
||||
if (!crls->elements) {
|
||||
return false;
|
||||
}
|
||||
@ -42,7 +42,7 @@ static bool r_pkcs7_parse_certificaterevocationlists (RPKCS7CertificateRevocatio
|
||||
return true;
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_certificaterevocationlists (RPKCS7CertificateRevocationLists *crls) {
|
||||
static void r_pkcs7_free_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls) {
|
||||
ut32 i;
|
||||
if (crls) {
|
||||
for (i = 0; i < crls->length; ++i) {
|
||||
@ -54,13 +54,13 @@ static void r_pkcs7_free_certificaterevocationlists (RPKCS7CertificateRevocation
|
||||
}
|
||||
}
|
||||
|
||||
static bool r_pkcs7_parse_extendedcertificatesandcertificates (RPKCS7ExtendedCertificatesAndCertificates *ecac, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac, RASN1Object *object) {
|
||||
ut32 i;
|
||||
if (!ecac || !object) {
|
||||
return false;
|
||||
}
|
||||
if (object->list.length > 0) {
|
||||
ecac->elements = (RX509Certificate **) calloc (object->list.length, sizeof (RX509Certificate*));
|
||||
ecac->elements = (RX509Certificate **)calloc (object->list.length, sizeof (RX509Certificate *));
|
||||
if (!ecac->elements) {
|
||||
return false;
|
||||
}
|
||||
@ -73,7 +73,7 @@ static bool r_pkcs7_parse_extendedcertificatesandcertificates (RPKCS7ExtendedCer
|
||||
return true;
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_extendedcertificatesandcertificates (RPKCS7ExtendedCertificatesAndCertificates *ecac) {
|
||||
static void r_pkcs7_free_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac) {
|
||||
ut32 i;
|
||||
if (ecac) {
|
||||
for (i = 0; i < ecac->length; ++i) {
|
||||
@ -85,13 +85,13 @@ static void r_pkcs7_free_extendedcertificatesandcertificates (RPKCS7ExtendedCert
|
||||
}
|
||||
}
|
||||
|
||||
static bool r_pkcs7_parse_digestalgorithmidentifier (RPKCS7DigestAlgorithmIdentifiers *dai, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai, RASN1Object *object) {
|
||||
ut32 i;
|
||||
if (!dai || !object) {
|
||||
return false;
|
||||
}
|
||||
if (object->list.length > 0) {
|
||||
dai->elements = (RX509AlgorithmIdentifier **) calloc (object->list.length, sizeof (RX509AlgorithmIdentifier*));
|
||||
dai->elements = (RX509AlgorithmIdentifier **)calloc (object->list.length, sizeof (RX509AlgorithmIdentifier *));
|
||||
if (!dai->elements) {
|
||||
return false;
|
||||
}
|
||||
@ -99,7 +99,7 @@ static bool r_pkcs7_parse_digestalgorithmidentifier (RPKCS7DigestAlgorithmIdenti
|
||||
for (i = 0; i < dai->length; ++i) {
|
||||
// r_x509_parse_algorithmidentifier returns bool,
|
||||
// so i have to allocate before calling the function
|
||||
dai->elements[i] = (RX509AlgorithmIdentifier *) malloc (sizeof (RX509AlgorithmIdentifier));
|
||||
dai->elements[i] = (RX509AlgorithmIdentifier *)malloc (sizeof (RX509AlgorithmIdentifier));
|
||||
//should i handle invalid memory? the function checks the pointer
|
||||
//or it should return if dai->elements[i] == NULL ?
|
||||
if (dai->elements[i]) {
|
||||
@ -112,7 +112,7 @@ static bool r_pkcs7_parse_digestalgorithmidentifier (RPKCS7DigestAlgorithmIdenti
|
||||
return true;
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_digestalgorithmidentifier (RPKCS7DigestAlgorithmIdentifiers *dai) {
|
||||
static void r_pkcs7_free_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai) {
|
||||
ut32 i;
|
||||
if (dai) {
|
||||
for (i = 0; i < dai->length; ++i) {
|
||||
@ -128,7 +128,7 @@ static void r_pkcs7_free_digestalgorithmidentifier (RPKCS7DigestAlgorithmIdentif
|
||||
}
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_contentinfo (RPKCS7ContentInfo* ci) {
|
||||
static void r_pkcs7_free_contentinfo(RPKCS7ContentInfo *ci) {
|
||||
if (ci) {
|
||||
r_asn1_free_binary (ci->content);
|
||||
r_asn1_free_string (ci->contentType);
|
||||
@ -136,7 +136,7 @@ static void r_pkcs7_free_contentinfo (RPKCS7ContentInfo* ci) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool r_pkcs7_parse_issuerandserialnumber (RPKCS7IssuerAndSerialNumber* iasu, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu, RASN1Object *object) {
|
||||
if (!iasu || !object || object->list.length != 2) {
|
||||
return false;
|
||||
}
|
||||
@ -148,7 +148,7 @@ static bool r_pkcs7_parse_issuerandserialnumber (RPKCS7IssuerAndSerialNumber* ia
|
||||
return true;
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_issuerandserialnumber (RPKCS7IssuerAndSerialNumber* iasu) {
|
||||
static void r_pkcs7_free_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu) {
|
||||
if (iasu) {
|
||||
r_x509_free_name (&iasu->issuer);
|
||||
r_asn1_free_binary (iasu->serialNumber);
|
||||
@ -163,7 +163,7 @@ static void r_pkcs7_free_issuerandserialnumber (RPKCS7IssuerAndSerialNumber* ias
|
||||
} RPKCS7SignerInfo;
|
||||
*/
|
||||
|
||||
static bool r_pkcs7_parse_signerinfo (RPKCS7SignerInfo* si, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_signerinfo(RPKCS7SignerInfo *si, RASN1Object *object) {
|
||||
RASN1Object **elems;
|
||||
ut32 shift = 3;
|
||||
if (!si || !object || object->list.length < 5) {
|
||||
@ -171,7 +171,7 @@ static bool r_pkcs7_parse_signerinfo (RPKCS7SignerInfo* si, RASN1Object *object)
|
||||
}
|
||||
elems = object->list.objects;
|
||||
//Following RFC
|
||||
si->version = (ut32) elems[0]->sector[0];
|
||||
si->version = (ut32)elems[0]->sector[0];
|
||||
r_pkcs7_parse_issuerandserialnumber (&si->issuerAndSerialNumber, elems[1]);
|
||||
r_x509_parse_algorithmidentifier (&si->digestAlgorithm, elems[2]);
|
||||
if (shift < object->list.length && elems[shift]->klass == CLASS_CONTEXT && elems[shift]->tag == 0) {
|
||||
@ -198,7 +198,7 @@ static bool r_pkcs7_parse_signerinfo (RPKCS7SignerInfo* si, RASN1Object *object)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_attribute (RPKCS7Attribute* attribute) {
|
||||
static void r_pkcs7_free_attribute(RPKCS7Attribute *attribute) {
|
||||
if (attribute) {
|
||||
r_asn1_free_binary (attribute->data);
|
||||
r_asn1_free_string (attribute->oid);
|
||||
@ -206,7 +206,7 @@ static void r_pkcs7_free_attribute (RPKCS7Attribute* attribute) {
|
||||
}
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_attributes (RPKCS7Attributes* attributes) {
|
||||
static void r_pkcs7_free_attributes(RPKCS7Attributes *attributes) {
|
||||
ut32 i;
|
||||
if (attributes) {
|
||||
for (i = 0; i < attributes->length; ++i) {
|
||||
@ -217,7 +217,7 @@ static void r_pkcs7_free_attributes (RPKCS7Attributes* attributes) {
|
||||
}
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_signerinfo (RPKCS7SignerInfo* si) {
|
||||
static void r_pkcs7_free_signerinfo(RPKCS7SignerInfo *si) {
|
||||
if (si) {
|
||||
r_pkcs7_free_issuerandserialnumber (&si->issuerAndSerialNumber);
|
||||
r_x509_free_algorithmidentifier (&si->digestAlgorithm);
|
||||
@ -229,13 +229,13 @@ static void r_pkcs7_free_signerinfo (RPKCS7SignerInfo* si) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool r_pkcs7_parse_signerinfos (RPKCS7SignerInfos *ss, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_signerinfos(RPKCS7SignerInfos *ss, RASN1Object *object) {
|
||||
ut32 i;
|
||||
if (!ss || !object) {
|
||||
return false;
|
||||
}
|
||||
if (object->list.length > 0) {
|
||||
ss->elements = (RPKCS7SignerInfo **) calloc (object->list.length, sizeof (RPKCS7SignerInfo*));
|
||||
ss->elements = (RPKCS7SignerInfo **)calloc (object->list.length, sizeof (RPKCS7SignerInfo *));
|
||||
if (!ss->elements) {
|
||||
return false;
|
||||
}
|
||||
@ -252,7 +252,7 @@ static bool r_pkcs7_parse_signerinfos (RPKCS7SignerInfos *ss, RASN1Object *objec
|
||||
return true;
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_signerinfos (RPKCS7SignerInfos *ss) {
|
||||
static void r_pkcs7_free_signerinfos(RPKCS7SignerInfos *ss) {
|
||||
ut32 i;
|
||||
if (ss) {
|
||||
for (i = 0; i < ss->length; i++) {
|
||||
@ -264,7 +264,7 @@ static void r_pkcs7_free_signerinfos (RPKCS7SignerInfos *ss) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool r_pkcs7_parse_signeddata (RPKCS7SignedData *sd, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_signeddata(RPKCS7SignedData *sd, RASN1Object *object) {
|
||||
ut32 shift = 3;
|
||||
if (!sd || !object || object->list.length < 4) {
|
||||
return false;
|
||||
@ -272,7 +272,7 @@ static bool r_pkcs7_parse_signeddata (RPKCS7SignedData *sd, RASN1Object *object)
|
||||
memset (sd, 0, sizeof (RPKCS7SignedData));
|
||||
RASN1Object **elems = object->list.objects;
|
||||
//Following RFC
|
||||
sd->version = (ut32) elems[0]->sector[0];
|
||||
sd->version = (ut32)elems[0]->sector[0];
|
||||
r_pkcs7_parse_digestalgorithmidentifier (&sd->digestAlgorithms, elems[1]);
|
||||
r_pkcs7_parse_contentinfo (&sd->contentInfo, elems[2]);
|
||||
//Optional
|
||||
@ -293,7 +293,7 @@ static bool r_pkcs7_parse_signeddata (RPKCS7SignedData *sd, RASN1Object *object)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void r_pkcs7_free_signeddata (RPKCS7SignedData* sd) {
|
||||
static void r_pkcs7_free_signeddata(RPKCS7SignedData *sd) {
|
||||
if (sd) {
|
||||
r_pkcs7_free_digestalgorithmidentifier (&sd->digestAlgorithms);
|
||||
r_pkcs7_free_contentinfo (&sd->contentInfo);
|
||||
@ -304,7 +304,7 @@ static void r_pkcs7_free_signeddata (RPKCS7SignedData* sd) {
|
||||
}
|
||||
}
|
||||
|
||||
R_API RCMS *r_pkcs7_parse_cms (const ut8 *buffer, ut32 length) {
|
||||
R_API RCMS *r_pkcs7_parse_cms(const ut8 *buffer, ut32 length) {
|
||||
RASN1Object *object;
|
||||
RCMS *container;
|
||||
if (!buffer || !length) {
|
||||
@ -332,7 +332,7 @@ R_API RCMS *r_pkcs7_parse_cms (const ut8 *buffer, ut32 length) {
|
||||
return container;
|
||||
}
|
||||
|
||||
R_API void r_pkcs7_free_cms (RCMS* container) {
|
||||
R_API void r_pkcs7_free_cms(RCMS *container) {
|
||||
if (container) {
|
||||
r_asn1_free_string (container->contentType);
|
||||
r_pkcs7_free_signeddata (&container->signedData);
|
||||
@ -340,8 +340,8 @@ R_API void r_pkcs7_free_cms (RCMS* container) {
|
||||
}
|
||||
}
|
||||
|
||||
static RPKCS7Attribute* r_pkcs7_parse_attribute (RASN1Object *object) {
|
||||
RPKCS7Attribute* attribute;
|
||||
static RPKCS7Attribute *r_pkcs7_parse_attribute(RASN1Object *object) {
|
||||
RPKCS7Attribute *attribute;
|
||||
if (!object || object->list.length < 1) {
|
||||
return NULL;
|
||||
}
|
||||
@ -353,7 +353,7 @@ static RPKCS7Attribute* r_pkcs7_parse_attribute (RASN1Object *object) {
|
||||
attribute->oid = r_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length);
|
||||
}
|
||||
if (object->list.length == 2) {
|
||||
RASN1Object * obj1 = object->list.objects[1];
|
||||
RASN1Object *obj1 = object->list.objects[1];
|
||||
if (obj1) {
|
||||
attribute->data = r_asn1_create_binary (obj1->sector, obj1->length);
|
||||
}
|
||||
@ -361,7 +361,7 @@ static RPKCS7Attribute* r_pkcs7_parse_attribute (RASN1Object *object) {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
static bool r_pkcs7_parse_attributes (RPKCS7Attributes* attributes, RASN1Object *object) {
|
||||
static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attributes, RASN1Object *object) {
|
||||
ut32 i;
|
||||
if (!attributes || !object || !object->list.length) {
|
||||
return false;
|
||||
@ -369,7 +369,7 @@ static bool r_pkcs7_parse_attributes (RPKCS7Attributes* attributes, RASN1Object
|
||||
|
||||
attributes->length = object->list.length;
|
||||
if (attributes->length > 0) {
|
||||
attributes->elements = R_NEWS0 (RPKCS7Attribute*, attributes->length);
|
||||
attributes->elements = R_NEWS0 (RPKCS7Attribute *, attributes->length);
|
||||
if (!attributes->elements) {
|
||||
attributes->length = 0;
|
||||
return false;
|
||||
@ -383,7 +383,7 @@ static bool r_pkcs7_parse_attributes (RPKCS7Attributes* attributes, RASN1Object
|
||||
|
||||
#if 0
|
||||
// XXX: unused
|
||||
static void r_pkcs7_signerinfos_dump (RX509CertificateRevocationList *crl, const char* pad, RStrBuf *sb) {
|
||||
static void r_pkcs7_signerinfos_dump(RX509CertificateRevocationList *crl, const char* pad, RStrBuf *sb) {
|
||||
RASN1String *algo = NULL, *last = NULL, *next = NULL;
|
||||
ut32 i;
|
||||
char *pad2, *pad3;
|
||||
@ -412,7 +412,7 @@ static void r_pkcs7_signerinfos_dump (RX509CertificateRevocationList *crl, const
|
||||
}
|
||||
#endif
|
||||
|
||||
static void r_x509_signedinfo_dump (RPKCS7SignerInfo *si, const char* pad, RStrBuf *sb) {
|
||||
static void r_x509_signedinfo_dump(RPKCS7SignerInfo *si, const char *pad, RStrBuf *sb) {
|
||||
RASN1String *s = NULL;
|
||||
RASN1Binary *o = NULL;
|
||||
ut32 i;
|
||||
@ -442,36 +442,35 @@ static void r_x509_signedinfo_dump (RPKCS7SignerInfo *si, const char* pad, RStrB
|
||||
pad2, pad3, s ? s->string : "Missing", pad2);
|
||||
|
||||
for (i = 0; i < si->authenticatedAttributes.length; ++i) {
|
||||
RPKCS7Attribute* attr = si->authenticatedAttributes.elements[i];
|
||||
RPKCS7Attribute *attr = si->authenticatedAttributes.elements[i];
|
||||
if (!attr) {
|
||||
continue;
|
||||
}
|
||||
r_strbuf_appendf (sb, "%s%s: %u bytes\n", pad3, attr->oid ? attr->oid->string : "Missing",
|
||||
attr->data ? attr->data->length : 0);
|
||||
attr->data ? attr->data->length : 0);
|
||||
}
|
||||
s = si->digestEncryptionAlgorithm.algorithm;
|
||||
r_strbuf_appendf (sb, "%sDigest Encryption Algorithm\n%s%s\n", pad2, pad3, s ? s->string : "Missing");
|
||||
|
||||
|
||||
// if ((o = si->encryptedDigest)) s = r_asn1_stringify_bytes (o->binary, o->length);
|
||||
// else s = NULL;
|
||||
// eprintf ("%sEncrypted Digest: %u bytes\n%s\n", pad2, o ? o->length : 0, s ? s->string : "Missing");
|
||||
// r_asn1_free_string (s);
|
||||
// if ((o = si->encryptedDigest)) s = r_asn1_stringify_bytes (o->binary, o->length);
|
||||
// else s = NULL;
|
||||
// eprintf ("%sEncrypted Digest: %u bytes\n%s\n", pad2, o ? o->length : 0, s ? s->string : "Missing");
|
||||
// r_asn1_free_string (s);
|
||||
r_strbuf_appendf (sb, "%sEncrypted Digest: %u bytes\n", pad2, o ? o->length : 0);
|
||||
r_strbuf_appendf (sb, "%sUnauthenticated Attributes:\n", pad2);
|
||||
for (i = 0; i < si->unauthenticatedAttributes.length; ++i) {
|
||||
RPKCS7Attribute* attr = si->unauthenticatedAttributes.elements[i];
|
||||
RPKCS7Attribute *attr = si->unauthenticatedAttributes.elements[i];
|
||||
if (!attr) {
|
||||
continue;
|
||||
}
|
||||
o = attr->data;
|
||||
eprintf ("%s%s: %u bytes\n", pad3, attr->oid ? attr->oid->string : "Missing",
|
||||
o ? o->length : 0);
|
||||
o ? o->length : 0);
|
||||
}
|
||||
free (pad3);
|
||||
}
|
||||
|
||||
R_API char *r_pkcs7_cms_to_string (RCMS* container) {
|
||||
R_API char *r_pkcs7_cms_to_string(RCMS *container) {
|
||||
ut32 i;
|
||||
if (!container) {
|
||||
return NULL;
|
||||
@ -512,133 +511,122 @@ R_API char *r_pkcs7_cms_to_string (RCMS* container) {
|
||||
return r_strbuf_drain (sb);
|
||||
}
|
||||
|
||||
RJSVar *r_x509_signedinfo_json (RPKCS7SignerInfo* si) {
|
||||
RJSVar* array = NULL;
|
||||
RJSVar* var = NULL;
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
R_API void r_x509_signedinfo_json(PJ *pj, RPKCS7SignerInfo *si) {
|
||||
ut32 i;
|
||||
if (!si) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
(void)r_json_object_add (obj, "Version", r_json_number_new (si->version + 1));
|
||||
(void)r_json_object_add (obj, "Issuer", r_x509_name_json (&si->issuerAndSerialNumber.issuer));
|
||||
if (si->issuerAndSerialNumber.serialNumber) {
|
||||
RASN1Binary *o = si->issuerAndSerialNumber.serialNumber;
|
||||
RASN1String *s = r_asn1_stringify_integer (o->binary, o->length);
|
||||
if (s) {
|
||||
(void)r_json_object_add (obj, "SerialNumber", r_json_string_new (s->string));
|
||||
if (si) {
|
||||
pj_o (pj);
|
||||
pj_ki (pj, "Version", si->version + 1);
|
||||
pj_k (pj, "Issuer");
|
||||
pj_o (pj);
|
||||
r_x509_name_json (pj, &si->issuerAndSerialNumber.issuer);
|
||||
pj_end (pj);
|
||||
if (si->issuerAndSerialNumber.serialNumber) {
|
||||
RASN1Binary *o = si->issuerAndSerialNumber.serialNumber;
|
||||
RASN1String *s = r_asn1_stringify_integer (o->binary, o->length);
|
||||
if (s) {
|
||||
pj_ks (pj, "SerialNumber", s->string);
|
||||
}
|
||||
r_asn1_free_string (s);
|
||||
}
|
||||
r_asn1_free_string (s);
|
||||
}
|
||||
|
||||
if (si->digestAlgorithm.algorithm) {
|
||||
(void) r_json_object_add (obj, "DigestAlgorithm", r_json_string_new (si->digestAlgorithm.algorithm->string));
|
||||
}
|
||||
|
||||
array = r_json_array_new (si->authenticatedAttributes.length);
|
||||
for (i = 0; i < si->authenticatedAttributes.length; ++i) {
|
||||
RPKCS7Attribute* attr = si->authenticatedAttributes.elements[i];
|
||||
if (!attr) {
|
||||
continue;
|
||||
if (si->digestAlgorithm.algorithm) {
|
||||
pj_ks (pj, "DigestAlgorithm", si->digestAlgorithm.algorithm->string);
|
||||
}
|
||||
RJSVar* attribute = r_json_object_new ();
|
||||
if (attr->oid) {
|
||||
var = r_json_string_new (attr->oid->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (attribute, "oid", var), var);
|
||||
pj_k (pj, "AuthenticatedAttributes");
|
||||
pj_a (pj);
|
||||
for (i = 0; i < si->authenticatedAttributes.length; ++i) {
|
||||
RPKCS7Attribute *attr = si->authenticatedAttributes.elements[i];
|
||||
if (!attr) {
|
||||
continue;
|
||||
}
|
||||
pj_o (pj);
|
||||
if (attr->oid) {
|
||||
pj_ks (pj, "oid", attr->oid->string);
|
||||
}
|
||||
if (attr->data) {
|
||||
pj_ki (pj, "length", attr->data->length);
|
||||
}
|
||||
pj_end (pj);
|
||||
}
|
||||
if (attr->data) {
|
||||
var = r_json_number_new (attr->data->length);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (attribute, "length", var), var);
|
||||
pj_end (pj);
|
||||
if (si->digestEncryptionAlgorithm.algorithm) {
|
||||
pj_ks (pj, "DigestEncryptionAlgorithm", si->digestEncryptionAlgorithm.algorithm->string);
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_array_add (array, attribute), attribute);
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "AuthenticatedAttributes", array), array);
|
||||
if (si->digestEncryptionAlgorithm.algorithm) {
|
||||
var = r_json_string_new (si->digestEncryptionAlgorithm.algorithm->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "DigestEncryptionAlgorithm", var), var);
|
||||
}
|
||||
|
||||
if (si->encryptedDigest) {
|
||||
RASN1Binary *o = si->encryptedDigest;
|
||||
RASN1String *s = r_asn1_stringify_integer (o->binary, o->length);
|
||||
if (s) {
|
||||
var = r_json_string_new (s->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "EncryptedDigest", var), var);
|
||||
if (si->encryptedDigest) {
|
||||
RASN1Binary *o = si->encryptedDigest;
|
||||
RASN1String *s = r_asn1_stringify_integer (o->binary, o->length);
|
||||
if (s) {
|
||||
pj_ks (pj, "EncryptedDigest", s->string);
|
||||
}
|
||||
r_asn1_free_string (s);
|
||||
}
|
||||
r_asn1_free_string (s);
|
||||
}
|
||||
|
||||
|
||||
array = r_json_array_new (si->unauthenticatedAttributes.length);
|
||||
for (i = 0; i < si->unauthenticatedAttributes.length; ++i) {
|
||||
RPKCS7Attribute* attr = si->unauthenticatedAttributes.elements[i];
|
||||
if (!attr) {
|
||||
continue;
|
||||
}
|
||||
RJSVar* attribute = r_json_object_new ();
|
||||
if (attr->oid) {
|
||||
var = r_json_string_new (attr->oid->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (attribute, "oid", var), var);
|
||||
}
|
||||
if (attr->data) {
|
||||
var = r_json_number_new (attr->data->length);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (attribute, "length", var), var);
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_array_add (array, attribute), attribute);
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "UnauthenticatedAttributes", array), array);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
RJSVar *r_pkcs7_cms_json (RCMS* container) {
|
||||
RJSVar* array = NULL;
|
||||
RJSVar* var = NULL;
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
ut32 i;
|
||||
if (!container) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
var = r_json_number_new (container->signedData.version);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Version", var), var);
|
||||
|
||||
if (container->signedData.digestAlgorithms.elements) {
|
||||
array = r_json_array_new (container->signedData.digestAlgorithms.length);
|
||||
for (i = 0; i < container->signedData.digestAlgorithms.length; ++i) {
|
||||
if (container->signedData.digestAlgorithms.elements[i]) {
|
||||
RASN1String *s = container->signedData.digestAlgorithms.elements[i]->algorithm;
|
||||
if (s) {
|
||||
var = r_json_string_new (s->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_array_add (array, var), var);
|
||||
}
|
||||
pj_k (pj, "UnauthenticatedAttributes");
|
||||
pj_a (pj);
|
||||
for (i = 0; i < si->unauthenticatedAttributes.length; ++i) {
|
||||
RPKCS7Attribute *attr = si->unauthenticatedAttributes.elements[i];
|
||||
if (!attr) {
|
||||
continue;
|
||||
}
|
||||
if (attr->oid) {
|
||||
pj_ks (pj, "oid", attr->oid->string);
|
||||
}
|
||||
if (attr->data) {
|
||||
pj_ki (pj, "length", attr->data->length);
|
||||
}
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "DigestAlgorithms", array), array);
|
||||
pj_end (pj);
|
||||
pj_end (pj);
|
||||
}
|
||||
|
||||
array = r_json_array_new (container->signedData.certificates.length);
|
||||
for (i = 0; i < container->signedData.certificates.length; ++i) {
|
||||
var = r_x509_certificate_json (container->signedData.certificates.elements[i]);
|
||||
R_JSON_FREE_ON_FAIL (r_json_array_add (array, var), var);
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Certificates", array), array);
|
||||
|
||||
array = r_json_array_new (container->signedData.crls.length);
|
||||
for (i = 0; i < container->signedData.crls.length; ++i) {
|
||||
var = r_x509_crl_json (container->signedData.crls.elements[i]);
|
||||
R_JSON_FREE_ON_FAIL (r_json_array_add (array, var), var);
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "CRL", array), array);
|
||||
|
||||
if (container->signedData.signerinfos.elements) {
|
||||
array = r_json_array_new (container->signedData.signerinfos.length);
|
||||
for (i = 0; i < container->signedData.signerinfos.length; ++i) {
|
||||
var = r_x509_signedinfo_json (container->signedData.signerinfos.elements[i]);
|
||||
R_JSON_FREE_ON_FAIL (r_json_array_add (array, var), var);
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "SignerInfos", array), array);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
R_API PJ *r_pkcs7_cms_json (RCMS *container) {
|
||||
PJ *pj = NULL;
|
||||
if (container) {
|
||||
ut32 i;
|
||||
|
||||
pj = pj_new ();
|
||||
|
||||
pj_o (pj);
|
||||
pj_kn (pj, "Version", container->signedData.version);
|
||||
|
||||
if (container->signedData.digestAlgorithms.elements) {
|
||||
pj_k (pj, "DigestAlgorithms");
|
||||
pj_a (pj);
|
||||
for (i = 0; i < container->signedData.digestAlgorithms.length; ++i) {
|
||||
if (container->signedData.digestAlgorithms.elements[i]) {
|
||||
RASN1String *s = container->signedData.digestAlgorithms.elements[i]->algorithm;
|
||||
if (s) {
|
||||
pj_s (pj, s->string);
|
||||
}
|
||||
}
|
||||
}
|
||||
pj_end (pj);
|
||||
}
|
||||
|
||||
pj_k (pj, "Certificates");
|
||||
pj_a (pj);
|
||||
for (i = 0; i < container->signedData.certificates.length; ++i) {
|
||||
r_x509_certificate_json (pj, container->signedData.certificates.elements[i]);
|
||||
}
|
||||
pj_end (pj);
|
||||
pj_end (pj);
|
||||
pj_k (pj, "CRL");
|
||||
pj_a (pj);
|
||||
for (i = 0; i < container->signedData.crls.length; ++i) {
|
||||
r_x509_crl_json (pj, container->signedData.crls.elements[i]);
|
||||
}
|
||||
pj_end (pj);
|
||||
pj_k (pj, "SignerInfos");
|
||||
pj_a (pj);
|
||||
if (container->signedData.signerinfos.elements) {
|
||||
for (i = 0; i < container->signedData.signerinfos.length; ++i) {
|
||||
r_x509_signedinfo_json (pj, container->signedData.signerinfos.elements[i]);
|
||||
}
|
||||
}
|
||||
pj_end (pj);
|
||||
pj_end (pj);
|
||||
}
|
||||
return pj;
|
||||
}
|
||||
|
450
libr/util/x509.c
450
libr/util/x509.c
@ -12,8 +12,8 @@ static bool r_x509_parse_validity(RX509Validity *validity, RASN1Object *object)
|
||||
return false;
|
||||
}
|
||||
if (object->klass == CLASS_UNIVERSAL &&
|
||||
object->tag == TAG_SEQUENCE &&
|
||||
object->form == FORM_CONSTRUCTED) {
|
||||
object->tag == TAG_SEQUENCE &&
|
||||
object->form == FORM_CONSTRUCTED) {
|
||||
o = object->list.objects[0];
|
||||
if (o->klass == CLASS_UNIVERSAL && o->form == FORM_PRIMITIVE) {
|
||||
if (o->tag == TAG_UTCTIME) {
|
||||
@ -34,7 +34,7 @@ static bool r_x509_parse_validity(RX509Validity *validity, RASN1Object *object)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool r_x509_parse_algorithmidentifier(RX509AlgorithmIdentifier *ai, RASN1Object * object) {
|
||||
bool r_x509_parse_algorithmidentifier (RX509AlgorithmIdentifier *ai, RASN1Object *object) {
|
||||
if (!ai || !object || object->list.length < 1 || !object->list.objects) {
|
||||
return false;
|
||||
}
|
||||
@ -46,7 +46,7 @@ bool r_x509_parse_algorithmidentifier(RX509AlgorithmIdentifier *ai, RASN1Object
|
||||
return true;
|
||||
}
|
||||
|
||||
bool r_x509_parse_subjectpublickeyinfo(RX509SubjectPublicKeyInfo * spki, RASN1Object *object) {
|
||||
bool r_x509_parse_subjectpublickeyinfo (RX509SubjectPublicKeyInfo *spki, RASN1Object *object) {
|
||||
RASN1Object *o;
|
||||
if (!spki || !object || object->list.length != 2) {
|
||||
return false;
|
||||
@ -68,19 +68,19 @@ bool r_x509_parse_subjectpublickeyinfo(RX509SubjectPublicKeyInfo * spki, RASN1Ob
|
||||
return true;
|
||||
}
|
||||
|
||||
bool r_x509_parse_name (RX509Name *name, RASN1Object * object) {
|
||||
bool r_x509_parse_name (RX509Name *name, RASN1Object *object) {
|
||||
ut32 i;
|
||||
if (!name || !object || !object->list.length) {
|
||||
return false;
|
||||
}
|
||||
if (object->klass == CLASS_UNIVERSAL && object->tag == TAG_SEQUENCE) {
|
||||
name->length = object->list.length;
|
||||
name->names = (RASN1String**) calloc (name->length, sizeof (RASN1String*));
|
||||
name->names = (RASN1String **)calloc (name->length, sizeof (RASN1String *));
|
||||
if (!name->names) {
|
||||
name->length = 0;
|
||||
return false;
|
||||
}
|
||||
name->oids = (RASN1String**) calloc (name->length, sizeof (RASN1String*));
|
||||
name->oids = (RASN1String **)calloc (name->length, sizeof (RASN1String *));
|
||||
if (!name->oids) {
|
||||
name->length = 0;
|
||||
R_FREE (name->names);
|
||||
@ -89,15 +89,15 @@ bool r_x509_parse_name (RX509Name *name, RASN1Object * object) {
|
||||
for (i = 0; i < object->list.length; ++i) {
|
||||
RASN1Object *o = object->list.objects[i];
|
||||
if (o && o->klass == CLASS_UNIVERSAL &&
|
||||
o->tag == TAG_SET &&
|
||||
o->form == FORM_CONSTRUCTED &&
|
||||
o->list.length == 1) {
|
||||
o->tag == TAG_SET &&
|
||||
o->form == FORM_CONSTRUCTED &&
|
||||
o->list.length == 1) {
|
||||
o = o->list.objects[0];
|
||||
if (o && o->list.length > 1 &&
|
||||
o->klass == CLASS_UNIVERSAL &&
|
||||
o->tag == TAG_SEQUENCE) {
|
||||
o->klass == CLASS_UNIVERSAL &&
|
||||
o->tag == TAG_SEQUENCE) {
|
||||
if (o->list.objects[0]->klass == CLASS_UNIVERSAL &&
|
||||
o->list.objects[0]->tag == TAG_OID) {
|
||||
o->list.objects[0]->tag == TAG_OID) {
|
||||
name->oids[i] = r_asn1_stringify_oid (o->list.objects[0]->sector, o->list.objects[0]->length);
|
||||
}
|
||||
RASN1Object *obj1 = o->list.objects[1];
|
||||
@ -132,13 +132,13 @@ bool r_x509_parse_extension (RX509Extension *ext, RASN1Object *object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool r_x509_parse_extensions (RX509Extensions *ext, RASN1Object * object) {
|
||||
bool r_x509_parse_extensions (RX509Extensions *ext, RASN1Object *object) {
|
||||
ut32 i;
|
||||
if (!ext || !object || object->list.length != 1 || !object->list.objects[0]->length) {
|
||||
return false;
|
||||
}
|
||||
object = object->list.objects[0];
|
||||
ext->extensions = (RX509Extension**) calloc (object->list.length, sizeof (RX509Extension*));
|
||||
ext->extensions = (RX509Extension **)calloc (object->list.length, sizeof (RX509Extension *));
|
||||
if (!ext->extensions) {
|
||||
return false;
|
||||
}
|
||||
@ -153,7 +153,7 @@ bool r_x509_parse_extensions (RX509Extensions *ext, RASN1Object * object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool r_x509_parse_tbscertificate (RX509TBSCertificate *tbsc, RASN1Object * object) {
|
||||
bool r_x509_parse_tbscertificate (RX509TBSCertificate *tbsc, RASN1Object *object) {
|
||||
RASN1Object **elems;
|
||||
ut32 i;
|
||||
ut32 shift = 0;
|
||||
@ -163,12 +163,12 @@ bool r_x509_parse_tbscertificate (RX509TBSCertificate *tbsc, RASN1Object * objec
|
||||
elems = object->list.objects;
|
||||
//Following RFC
|
||||
if (elems[0]->list.length == 1 &&
|
||||
elems[0]->klass == CLASS_CONTEXT &&
|
||||
elems[0]->form == FORM_CONSTRUCTED &&
|
||||
elems[0]->list.objects[0]->tag == TAG_INTEGER &&
|
||||
elems[0]->list.objects[0]->length == 1) {
|
||||
elems[0]->klass == CLASS_CONTEXT &&
|
||||
elems[0]->form == FORM_CONSTRUCTED &&
|
||||
elems[0]->list.objects[0]->tag == TAG_INTEGER &&
|
||||
elems[0]->list.objects[0]->length == 1) {
|
||||
//Integer inside a CLASS_CONTEXT
|
||||
tbsc->version = (ut32) elems[0]->list.objects[0]->sector[0];
|
||||
tbsc->version = (ut32)elems[0]->list.objects[0]->sector[0];
|
||||
shift = 1;
|
||||
} else {
|
||||
tbsc->version = 0;
|
||||
@ -206,7 +206,7 @@ bool r_x509_parse_tbscertificate (RX509TBSCertificate *tbsc, RASN1Object * objec
|
||||
return true;
|
||||
}
|
||||
|
||||
RX509Certificate * r_x509_parse_certificate (RASN1Object *object) {
|
||||
RX509Certificate *r_x509_parse_certificate (RASN1Object *object) {
|
||||
if (!object) {
|
||||
return NULL;
|
||||
}
|
||||
@ -238,7 +238,7 @@ fail:
|
||||
return cert;
|
||||
}
|
||||
|
||||
RX509Certificate * r_x509_parse_certificate2 (const ut8 *buffer, ut32 length) {
|
||||
RX509Certificate *r_x509_parse_certificate2 (const ut8 *buffer, ut32 length) {
|
||||
RX509Certificate *certificate;
|
||||
RASN1Object *object;
|
||||
if (!buffer || !length) {
|
||||
@ -255,7 +255,7 @@ RX509CRLEntry *r_x509_parse_crlentry (RASN1Object *object) {
|
||||
if (!object || object->list.length != 2) {
|
||||
return NULL;
|
||||
}
|
||||
entry = (RX509CRLEntry *) malloc (sizeof (RX509CRLEntry));
|
||||
entry = (RX509CRLEntry *)malloc (sizeof (RX509CRLEntry));
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
@ -264,13 +264,13 @@ RX509CRLEntry *r_x509_parse_crlentry (RASN1Object *object) {
|
||||
return entry;
|
||||
}
|
||||
|
||||
R_API RX509CertificateRevocationList* r_x509_parse_crl (RASN1Object *object) {
|
||||
R_API RX509CertificateRevocationList *r_x509_parse_crl(RASN1Object *object) {
|
||||
RX509CertificateRevocationList *crl;
|
||||
RASN1Object **elems;
|
||||
if (!object || object->list.length < 4) {
|
||||
return NULL;
|
||||
}
|
||||
crl = (RX509CertificateRevocationList *) malloc (sizeof (RX509CertificateRevocationList));
|
||||
crl = (RX509CertificateRevocationList *)malloc (sizeof (RX509CertificateRevocationList));
|
||||
if (!crl) {
|
||||
return NULL;
|
||||
}
|
||||
@ -282,7 +282,7 @@ R_API RX509CertificateRevocationList* r_x509_parse_crl (RASN1Object *object) {
|
||||
crl->nextUpdate = r_asn1_stringify_utctime (elems[3]->sector, elems[3]->length);
|
||||
if (object->list.length > 4 && object->list.objects[4]) {
|
||||
ut32 i;
|
||||
crl->revokedCertificates = calloc (object->list.objects[4]->list.length, sizeof (RX509CRLEntry*));
|
||||
crl->revokedCertificates = calloc (object->list.objects[4]->list.length, sizeof (RX509CRLEntry *));
|
||||
if (!crl->revokedCertificates) {
|
||||
free (crl);
|
||||
return NULL;
|
||||
@ -295,7 +295,7 @@ R_API RX509CertificateRevocationList* r_x509_parse_crl (RASN1Object *object) {
|
||||
return crl;
|
||||
}
|
||||
|
||||
void r_x509_free_algorithmidentifier (RX509AlgorithmIdentifier * ai) {
|
||||
void r_x509_free_algorithmidentifier (RX509AlgorithmIdentifier *ai) {
|
||||
if (ai) {
|
||||
// no need to free ai, since this functions is used internally
|
||||
r_asn1_free_string (ai->algorithm);
|
||||
@ -303,7 +303,7 @@ void r_x509_free_algorithmidentifier (RX509AlgorithmIdentifier * ai) {
|
||||
}
|
||||
}
|
||||
|
||||
static void r_x509_free_validity (RX509Validity * validity) {
|
||||
static void r_x509_free_validity(RX509Validity *validity) {
|
||||
if (validity) {
|
||||
// not freeing validity since it's not allocated dinamically
|
||||
r_asn1_free_string (validity->notAfter);
|
||||
@ -311,7 +311,7 @@ static void r_x509_free_validity (RX509Validity * validity) {
|
||||
}
|
||||
}
|
||||
|
||||
void r_x509_free_name (RX509Name * name) {
|
||||
void r_x509_free_name (RX509Name *name) {
|
||||
ut32 i;
|
||||
if (!name) {
|
||||
return;
|
||||
@ -327,7 +327,7 @@ void r_x509_free_name (RX509Name * name) {
|
||||
// not freeing name since it's not allocated dinamically
|
||||
}
|
||||
|
||||
void r_x509_free_extension (RX509Extension * ex) {
|
||||
void r_x509_free_extension (RX509Extension *ex) {
|
||||
if (ex) {
|
||||
r_asn1_free_string (ex->extnID);
|
||||
r_asn1_free_binary (ex->extnValue);
|
||||
@ -336,7 +336,7 @@ void r_x509_free_extension (RX509Extension * ex) {
|
||||
}
|
||||
}
|
||||
|
||||
void r_x509_free_extensions (RX509Extensions * ex) {
|
||||
void r_x509_free_extensions (RX509Extensions *ex) {
|
||||
ut32 i;
|
||||
if (!ex) {
|
||||
return;
|
||||
@ -350,7 +350,7 @@ void r_x509_free_extensions (RX509Extensions * ex) {
|
||||
//no need to free ex, since this functions is used internally
|
||||
}
|
||||
|
||||
void r_x509_free_subjectpublickeyinfo (RX509SubjectPublicKeyInfo * spki) {
|
||||
void r_x509_free_subjectpublickeyinfo (RX509SubjectPublicKeyInfo *spki) {
|
||||
if (spki) {
|
||||
r_x509_free_algorithmidentifier (&spki->algorithm);
|
||||
r_asn1_free_binary (spki->subjectPublicKey);
|
||||
@ -360,7 +360,7 @@ void r_x509_free_subjectpublickeyinfo (RX509SubjectPublicKeyInfo * spki) {
|
||||
}
|
||||
}
|
||||
|
||||
void r_x509_free_tbscertificate (RX509TBSCertificate * tbsc) {
|
||||
void r_x509_free_tbscertificate (RX509TBSCertificate *tbsc) {
|
||||
if (tbsc) {
|
||||
// version is ut32
|
||||
r_asn1_free_string (tbsc->serialNumber);
|
||||
@ -376,7 +376,7 @@ void r_x509_free_tbscertificate (RX509TBSCertificate * tbsc) {
|
||||
}
|
||||
}
|
||||
|
||||
void r_x509_free_certificate (RX509Certificate * certificate) {
|
||||
void r_x509_free_certificate (RX509Certificate *certificate) {
|
||||
if (certificate) {
|
||||
r_asn1_free_binary (certificate->signature);
|
||||
r_x509_free_algorithmidentifier (&certificate->algorithmIdentifier);
|
||||
@ -385,7 +385,7 @@ void r_x509_free_certificate (RX509Certificate * certificate) {
|
||||
}
|
||||
}
|
||||
|
||||
static void r_x509_free_crlentry (RX509CRLEntry *entry) {
|
||||
static void r_x509_free_crlentry(RX509CRLEntry *entry) {
|
||||
if (entry) {
|
||||
r_asn1_free_binary (entry->userCertificate);
|
||||
r_asn1_free_string (entry->revocationDate);
|
||||
@ -411,19 +411,19 @@ void r_x509_free_crl (RX509CertificateRevocationList *crl) {
|
||||
}
|
||||
}
|
||||
|
||||
static void r_x509_validity_dump (RX509Validity* validity, const char* pad, RStrBuf *sb) {
|
||||
static void r_x509_validity_dump(RX509Validity *validity, const char *pad, RStrBuf *sb) {
|
||||
if (!validity) {
|
||||
return;
|
||||
}
|
||||
if (!pad) {
|
||||
pad = "";
|
||||
}
|
||||
const char* b = validity->notBefore ? validity->notBefore->string : "Missing";
|
||||
const char* a = validity->notAfter ? validity->notAfter->string : "Missing";
|
||||
const char *b = validity->notBefore ? validity->notBefore->string : "Missing";
|
||||
const char *a = validity->notAfter ? validity->notAfter->string : "Missing";
|
||||
r_strbuf_appendf (sb, "%sNot Before: %s\n%sNot After: %s\n", pad, b, pad, a);
|
||||
}
|
||||
|
||||
void r_x509_name_dump (RX509Name* name, const char* pad, RStrBuf *sb) {
|
||||
void r_x509_name_dump (RX509Name *name, const char *pad, RStrBuf *sb) {
|
||||
ut32 i;
|
||||
if (!name) {
|
||||
return;
|
||||
@ -439,7 +439,7 @@ void r_x509_name_dump (RX509Name* name, const char* pad, RStrBuf *sb) {
|
||||
}
|
||||
}
|
||||
|
||||
static void r_x509_subjectpublickeyinfo_dump (RX509SubjectPublicKeyInfo* spki, const char* pad, RStrBuf *sb) {
|
||||
static void r_x509_subjectpublickeyinfo_dump(RX509SubjectPublicKeyInfo *spki, const char *pad, RStrBuf *sb) {
|
||||
const char *a;
|
||||
if (!spki) {
|
||||
return;
|
||||
@ -448,7 +448,7 @@ static void r_x509_subjectpublickeyinfo_dump (RX509SubjectPublicKeyInfo* spki, c
|
||||
pad = "";
|
||||
}
|
||||
a = spki->algorithm.algorithm ? spki->algorithm.algorithm->string : "Missing";
|
||||
RASN1String* m = NULL;
|
||||
RASN1String *m = NULL;
|
||||
if (spki->subjectPublicKeyModule) {
|
||||
m = r_asn1_stringify_integer (spki->subjectPublicKeyModule->binary, spki->subjectPublicKeyModule->length);
|
||||
}
|
||||
@ -456,12 +456,12 @@ static void r_x509_subjectpublickeyinfo_dump (RX509SubjectPublicKeyInfo* spki, c
|
||||
// r = snprintf (buffer, length, "%sAlgorithm: %s\n%sModule: %s\n%sExponent: %u bytes\n%s\n", pad, a, pad, m->string,
|
||||
// pad, spki->subjectPublicKeyExponent->length - 1, e->string);
|
||||
r_strbuf_appendf (sb, "%sAlgorithm: %s\n%sModule: %s\n%sExponent: %u bytes\n", pad, a, pad, m ? m->string : "Missing",
|
||||
pad, spki->subjectPublicKeyExponent ? spki->subjectPublicKeyExponent->length - 1 : 0);
|
||||
pad, spki->subjectPublicKeyExponent ? spki->subjectPublicKeyExponent->length - 1 : 0);
|
||||
r_asn1_free_string (m);
|
||||
// r_asn1_free_string (e);
|
||||
}
|
||||
|
||||
static void r_x509_extensions_dump (RX509Extensions* exts, const char* pad, RStrBuf *sb) {
|
||||
static void r_x509_extensions_dump(RX509Extensions *exts, const char *pad, RStrBuf *sb) {
|
||||
ut32 i;
|
||||
if (!exts) {
|
||||
return;
|
||||
@ -484,7 +484,7 @@ static void r_x509_extensions_dump (RX509Extensions* exts, const char* pad, RStr
|
||||
}
|
||||
}
|
||||
|
||||
static void r_x509_tbscertificate_dump (RX509TBSCertificate* tbsc, const char* pad, RStrBuf *sb) {
|
||||
static void r_x509_tbscertificate_dump(RX509TBSCertificate *tbsc, const char *pad, RStrBuf *sb) {
|
||||
RASN1String *sid = NULL, *iid = NULL;
|
||||
if (!tbsc) {
|
||||
return;
|
||||
@ -497,9 +497,9 @@ static void r_x509_tbscertificate_dump (RX509TBSCertificate* tbsc, const char* p
|
||||
return;
|
||||
}
|
||||
r_strbuf_appendf (sb, "%sVersion: v%u\n"
|
||||
"%sSerial Number:\n%s %s\n"
|
||||
"%sSignature Algorithm:\n%s %s\n"
|
||||
"%sIssuer:\n",
|
||||
"%sSerial Number:\n%s %s\n"
|
||||
"%sSignature Algorithm:\n%s %s\n"
|
||||
"%sIssuer:\n",
|
||||
pad, tbsc->version + 1,
|
||||
pad, pad, tbsc->serialNumber ? tbsc->serialNumber->string : "Missing",
|
||||
pad, pad, tbsc->signature.algorithm ? tbsc->signature.algorithm->string : "Missing",
|
||||
@ -535,7 +535,7 @@ static void r_x509_tbscertificate_dump (RX509TBSCertificate* tbsc, const char* p
|
||||
free (pad2);
|
||||
}
|
||||
|
||||
void r_x509_certificate_dump (RX509Certificate* cert, const char* pad, RStrBuf *sb) {
|
||||
void r_x509_certificate_dump (RX509Certificate *cert, const char *pad, RStrBuf *sb) {
|
||||
RASN1String *algo = NULL;
|
||||
char *pad2;
|
||||
if (!cert) {
|
||||
@ -562,7 +562,7 @@ void r_x509_certificate_dump (RX509Certificate* cert, const char* pad, RStrBuf *
|
||||
// r_asn1_free_string (signature);
|
||||
}
|
||||
|
||||
void r_x509_crlentry_dump (RX509CRLEntry *crle, const char* pad, RStrBuf *sb) {
|
||||
void r_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb) {
|
||||
RASN1String *id = NULL, *utc = NULL;
|
||||
if (!crle) {
|
||||
return;
|
||||
@ -575,13 +575,13 @@ void r_x509_crlentry_dump (RX509CRLEntry *crle, const char* pad, RStrBuf *sb) {
|
||||
id = r_asn1_stringify_integer (crle->userCertificate->binary, crle->userCertificate->length);
|
||||
}
|
||||
r_strbuf_appendf (sb, "%sUser Certificate:\n%s %s\n"
|
||||
"%sRevocation Date:\n%s %s\n",
|
||||
"%sRevocation Date:\n%s %s\n",
|
||||
pad, pad, id ? id->string : "Missing",
|
||||
pad, pad, utc ? utc->string : "Missing");
|
||||
r_asn1_free_string (id);
|
||||
}
|
||||
|
||||
R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char* pad) {
|
||||
R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char *pad) {
|
||||
RASN1String *algo = NULL, *last = NULL, *next = NULL;
|
||||
ut32 i;
|
||||
char *pad2, *pad3;
|
||||
@ -601,12 +601,12 @@ R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char
|
||||
next = crl->nextUpdate;
|
||||
RStrBuf *sb = r_strbuf_new ("");
|
||||
r_strbuf_appendf (sb, "%sCRL:\n%sSignature:\n%s%s\n%sIssuer\n", pad, pad2, pad3,
|
||||
algo ? algo->string : "", pad2);
|
||||
algo ? algo->string : "", pad2);
|
||||
r_x509_name_dump (&crl->issuer, pad3, sb);
|
||||
|
||||
r_strbuf_appendf (sb, "%sLast Update: %s\n%sNext Update: %s\n%sRevoked Certificates:\n",
|
||||
pad2, last ? last->string : "Missing",
|
||||
pad2, next ? next->string : "Missing", pad2);
|
||||
pad2, last ? last->string : "Missing",
|
||||
pad2, next ? next->string : "Missing", pad2);
|
||||
|
||||
for (i = 0; i < crl->length; i++) {
|
||||
r_x509_crlentry_dump (crl->revokedCertificates[i], pad3, sb);
|
||||
@ -616,230 +616,184 @@ R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char
|
||||
return r_strbuf_drain (sb);
|
||||
}
|
||||
|
||||
RJSVar *r_x509_validity_json (RX509Validity* validity) {
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
RJSVar* var = NULL;
|
||||
if (!validity) {
|
||||
return obj;
|
||||
R_API void r_x509_validity_json(PJ *pj, RX509Validity *validity) {
|
||||
if (validity) {
|
||||
if (validity->notBefore) {
|
||||
pj_ks (pj, "NotBefore", validity->notBefore->string);
|
||||
}
|
||||
if (validity->notAfter) {
|
||||
pj_ks (pj, "NotAfter", validity->notAfter->string);
|
||||
}
|
||||
}
|
||||
if (validity->notBefore) {
|
||||
var = r_json_string_new (validity->notBefore->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "NotBefore", var), var);
|
||||
}
|
||||
if (validity->notAfter) {
|
||||
var = r_json_string_new (validity->notAfter->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "NotAfter", var), var);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
RJSVar *r_x509_name_json (RX509Name* name) {
|
||||
R_API void r_x509_name_json(PJ *pj, RX509Name *name) {
|
||||
ut32 i;
|
||||
RJSVar* var = NULL;
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
if (!name) {
|
||||
return obj;
|
||||
}
|
||||
for (i = 0; i < name->length; ++i) {
|
||||
if (!name->oids[i] || !name->names[i]) {
|
||||
continue;
|
||||
}
|
||||
var = r_json_string_new (name->names[i]->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, name->oids[i]->string, var), var);
|
||||
pj_ks (pj, name->oids[i]->string, name->names[i]->string);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
RJSVar* r_x509_subjectpublickeyinfo_json (RX509SubjectPublicKeyInfo* spki) {
|
||||
R_API void r_x509_subjectpublickeyinfo_json(PJ *pj, RX509SubjectPublicKeyInfo *spki) {
|
||||
RASN1String *m = NULL;
|
||||
RJSVar* var = NULL;
|
||||
RJSVar *obj = r_json_object_new ();
|
||||
if (!spki) {
|
||||
return obj;
|
||||
}
|
||||
if (spki->algorithm.algorithm) {
|
||||
var = r_json_string_new (spki->algorithm.algorithm->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Algorithm", var), var);
|
||||
}
|
||||
if (spki->subjectPublicKeyModule) {
|
||||
m = r_asn1_stringify_integer (spki->subjectPublicKeyModule->binary, spki->subjectPublicKeyModule->length);
|
||||
if (m) {
|
||||
var = r_json_string_new (m->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Module", var), var);
|
||||
if (spki) {
|
||||
if (spki->algorithm.algorithm) {
|
||||
pj_ks (pj, "Algorithm", spki->algorithm.algorithm->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
if (spki->subjectPublicKeyExponent) {
|
||||
m = r_asn1_stringify_integer (spki->subjectPublicKeyExponent->binary, spki->subjectPublicKeyExponent->length);
|
||||
if (m) {
|
||||
var = r_json_string_new (m->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Exponent", var), var);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
RJSVar *r_x509_extensions_json (RX509Extensions* exts) {
|
||||
ut32 i;
|
||||
RASN1String *m = NULL;
|
||||
RJSVar* array = NULL;
|
||||
RJSVar* var = NULL;
|
||||
if (!exts) {
|
||||
return array;
|
||||
}
|
||||
array = r_json_array_new (exts->length);
|
||||
for (i = 0; i < exts->length; ++i) {
|
||||
RX509Extension *e = exts->extensions[i];
|
||||
if (!e) {
|
||||
continue;
|
||||
}
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
if (!obj) {
|
||||
break;
|
||||
}
|
||||
if (e->extnID) {
|
||||
var = r_json_string_new (e->extnID->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "OID", var), var);
|
||||
}
|
||||
if (e->critical) {
|
||||
var = r_json_boolean_new (1);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Critical", var), var);
|
||||
}
|
||||
//TODO handle extensions correctly..
|
||||
if (e->extnValue) {
|
||||
m = r_asn1_stringify_integer (e->extnValue->binary, e->extnValue->length);
|
||||
if (spki->subjectPublicKeyModule) {
|
||||
m = r_asn1_stringify_integer (spki->subjectPublicKeyModule->binary, spki->subjectPublicKeyModule->length);
|
||||
if (m) {
|
||||
var = r_json_string_new (m->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Value", var), var);
|
||||
pj_ks (pj, "Module", m->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
R_JSON_FREE_ON_FAIL (r_json_array_add (array, obj), obj);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
RJSVar *r_x509_crlentry_json (RX509CRLEntry *crle) {
|
||||
RASN1String *m = NULL;
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
RJSVar* var = NULL;
|
||||
if (!crle) {
|
||||
return obj;
|
||||
}
|
||||
if (crle->userCertificate) {
|
||||
m = r_asn1_stringify_integer (crle->userCertificate->binary, crle->userCertificate->length);
|
||||
if (m) {
|
||||
var = r_json_string_new (m->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "UserCertificate", var), var);
|
||||
if (spki->subjectPublicKeyExponent) {
|
||||
m = r_asn1_stringify_integer (spki->subjectPublicKeyExponent->binary, spki->subjectPublicKeyExponent->length);
|
||||
if (m) {
|
||||
pj_ks (pj, "Exponent", m->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
if (crle->revocationDate) {
|
||||
var = r_json_string_new (crle->revocationDate->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "RevocationDate", var), var);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
R_API RJSVar *r_x509_crl_json (RX509CertificateRevocationList *crl) {
|
||||
R_API void r_x509_extensions_json(PJ *pj, RX509Extensions *exts) {
|
||||
if (exts) {
|
||||
RASN1String *m = NULL;
|
||||
ut32 i;
|
||||
pj_a (pj);
|
||||
for (i = 0; i < exts->length; ++i) {
|
||||
RX509Extension *e = exts->extensions[i];
|
||||
if (!e) {
|
||||
continue;
|
||||
}
|
||||
if (e->extnID) {
|
||||
pj_ks (pj, "OID", e->extnID->string);
|
||||
}
|
||||
if (e->critical) {
|
||||
pj_kb (pj, "Critical", e->critical);
|
||||
}
|
||||
//TODO handle extensions correctly..
|
||||
if (e->extnValue) {
|
||||
m = r_asn1_stringify_integer (e->extnValue->binary, e->extnValue->length);
|
||||
if (m) {
|
||||
pj_ks (pj, "Value", m->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
}
|
||||
pj_end (pj);
|
||||
pj_end (pj);
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_x509_crlentry_json(PJ *pj, RX509CRLEntry *crle) {
|
||||
RASN1String *m = NULL;
|
||||
if (crle) {
|
||||
if (crle->userCertificate) {
|
||||
m = r_asn1_stringify_integer (crle->userCertificate->binary, crle->userCertificate->length);
|
||||
if (m) {
|
||||
pj_ks (pj, "UserCertificate", m->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
if (crle->revocationDate) {
|
||||
pj_ks (pj, "RevocationDate", crle->revocationDate->string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_x509_crl_json(PJ *pj, RX509CertificateRevocationList *crl) {
|
||||
ut32 i;
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
RJSVar* array = NULL;
|
||||
RJSVar* var = NULL;
|
||||
if (!crl) {
|
||||
return obj;
|
||||
RJSVar *array = NULL;
|
||||
if (crl) {
|
||||
if (crl->signature.algorithm) {
|
||||
pj_ks (pj, "Signature", crl->signature.algorithm->string);
|
||||
}
|
||||
pj_k (pj, "Issuer");
|
||||
pj_o (pj);
|
||||
r_x509_name_json (pj, &crl->issuer);
|
||||
pj_end (pj);
|
||||
if (crl->lastUpdate) {
|
||||
pj_ks (pj, "LastUpdate", crl->lastUpdate->string);
|
||||
}
|
||||
if (crl->nextUpdate) {
|
||||
pj_ks (pj, "NextUpdate", crl->nextUpdate->string);
|
||||
}
|
||||
pj_k (pj, "RevokedCertificates");
|
||||
pj_a (pj);
|
||||
array = r_json_array_new (crl->length);
|
||||
for (i = 0; i < crl->length; ++i) {
|
||||
r_x509_crlentry_json (pj, crl->revokedCertificates[i]);
|
||||
}
|
||||
pj_end (pj);
|
||||
}
|
||||
|
||||
if (crl->signature.algorithm) {
|
||||
var = r_json_string_new (crl->signature.algorithm->string);
|
||||
R_JSON_FREE_ON_FAIL(r_json_object_add (obj, "Signature", var), var);
|
||||
}
|
||||
r_json_object_add (obj, "Issuer", r_x509_name_json (&crl->issuer));
|
||||
if (crl->lastUpdate) {
|
||||
var = r_json_string_new (crl->lastUpdate->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "LastUpdate", var), var);
|
||||
}
|
||||
if (crl->nextUpdate) {
|
||||
var = r_json_string_new (crl->nextUpdate->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "NextUpdate", var), var);
|
||||
}
|
||||
|
||||
array = r_json_array_new (crl->length);
|
||||
for (i = 0; i < crl->length; ++i) {
|
||||
var = r_x509_crlentry_json (crl->revokedCertificates[i]);
|
||||
R_JSON_FREE_ON_FAIL (r_json_array_add (array, var), var);
|
||||
}
|
||||
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "RevokedCertificates", array), array);
|
||||
return obj;
|
||||
}
|
||||
|
||||
RJSVar *r_x509_tbscertificate_json (RX509TBSCertificate* tbsc) {
|
||||
R_API void r_x509_tbscertificate_json(PJ *pj, RX509TBSCertificate *tbsc) {
|
||||
pj_o (pj);
|
||||
RASN1String *m = NULL;
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
RJSVar* var = NULL;
|
||||
if (!tbsc) {
|
||||
return obj;
|
||||
}
|
||||
var = r_json_number_new (tbsc->version + 1);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Version", var), var);
|
||||
if (tbsc->serialNumber) {
|
||||
var = r_json_string_new (tbsc->serialNumber->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "SerialNumber", var), var);
|
||||
}
|
||||
if (tbsc->signature.algorithm) {
|
||||
var = r_json_string_new (tbsc->signature.algorithm->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "SignatureAlgorithm", var), var);
|
||||
}
|
||||
var = r_x509_name_json (&tbsc->issuer);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Issuer", var), var);
|
||||
var = r_x509_validity_json (&tbsc->validity);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Validity", var), var);
|
||||
var = r_x509_name_json (&tbsc->subject);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Subject", var), var);
|
||||
var = r_x509_subjectpublickeyinfo_json (&tbsc->subjectPublicKeyInfo);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "SubjectPublicKeyInfo", var), var);
|
||||
if (tbsc->issuerUniqueID) {
|
||||
m = r_asn1_stringify_integer (tbsc->issuerUniqueID->binary, tbsc->issuerUniqueID->length);
|
||||
if (m) {
|
||||
var = r_json_string_new (m->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "IssuerUniqueID", var), var);
|
||||
if (tbsc) {
|
||||
pj_ki (pj, "Version", tbsc->version + 1);
|
||||
if (tbsc->serialNumber) {
|
||||
pj_ks (pj, "SerialNumber", tbsc->serialNumber->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
if (tbsc->subjectUniqueID) {
|
||||
m = r_asn1_stringify_integer (tbsc->subjectUniqueID->binary, tbsc->subjectUniqueID->length);
|
||||
if (m) {
|
||||
var = r_json_string_new (m->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "SubjectUniqueID", var), var);
|
||||
if (tbsc->signature.algorithm) {
|
||||
pj_ks (pj, "SignatureAlgorithm", tbsc->signature.algorithm->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
pj_k (pj, "Issuer");
|
||||
pj_o (pj);
|
||||
r_x509_name_json (pj, &tbsc->issuer);
|
||||
pj_end (pj);
|
||||
pj_k (pj, "Validity");
|
||||
pj_o (pj);
|
||||
r_x509_validity_json (pj, &tbsc->validity);
|
||||
pj_end (pj);
|
||||
pj_k (pj, "Subject");
|
||||
pj_o (pj);
|
||||
r_x509_name_json (pj, &tbsc->subject);
|
||||
pj_end (pj);
|
||||
pj_k (pj, "SubjectPublicKeyInfo");
|
||||
pj_o (pj);
|
||||
r_x509_subjectpublickeyinfo_json (pj, &tbsc->subjectPublicKeyInfo);
|
||||
pj_end (pj);
|
||||
if (tbsc->issuerUniqueID) {
|
||||
m = r_asn1_stringify_integer (tbsc->issuerUniqueID->binary, tbsc->issuerUniqueID->length);
|
||||
if (m) {
|
||||
pj_ks (pj, "IssuerUniqueID", m->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
if (tbsc->subjectUniqueID) {
|
||||
m = r_asn1_stringify_integer (tbsc->subjectUniqueID->binary, tbsc->subjectUniqueID->length);
|
||||
if (m) {
|
||||
pj_ks (pj, "SubjectUniqueID", m->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
pj_k (pj, "Extensions");
|
||||
r_x509_extensions_json (pj, &tbsc->extensions);
|
||||
}
|
||||
var = r_x509_extensions_json (&tbsc->extensions);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Extensions", var), var);
|
||||
return obj;
|
||||
}
|
||||
|
||||
RJSVar* r_x509_certificate_json (RX509Certificate *certificate) {
|
||||
RASN1String *m = NULL;
|
||||
RJSVar* obj = r_json_object_new ();
|
||||
RJSVar* var = NULL;
|
||||
if (!certificate) {
|
||||
return obj;
|
||||
}
|
||||
r_json_object_add (obj, "TBSCertificate", r_x509_tbscertificate_json (&certificate->tbsCertificate));
|
||||
if (certificate->algorithmIdentifier.algorithm) {
|
||||
var = r_json_string_new (certificate->algorithmIdentifier.algorithm->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Algorithm", var), var);
|
||||
}
|
||||
if (certificate->signature) {
|
||||
m = r_asn1_stringify_integer (certificate->signature->binary, certificate->signature->length);
|
||||
if (m) {
|
||||
var = r_json_string_new (m->string);
|
||||
R_JSON_FREE_ON_FAIL (r_json_object_add (obj, "Signature", var), var);
|
||||
R_API void r_x509_certificate_json(PJ *pj, RX509Certificate *certificate) {
|
||||
if (certificate) {
|
||||
RASN1String *m = NULL;
|
||||
pj_o (pj);
|
||||
pj_k (pj, "TBSCertificate");
|
||||
r_x509_tbscertificate_json (pj, &certificate->tbsCertificate);
|
||||
if (certificate->algorithmIdentifier.algorithm) {
|
||||
pj_ks (pj, "Algorithm", certificate->algorithmIdentifier.algorithm->string);
|
||||
}
|
||||
if (certificate->signature) {
|
||||
m = r_asn1_stringify_integer (certificate->signature->binary, certificate->signature->length);
|
||||
if (m) {
|
||||
pj_ks (pj, "Signature", m->string);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
r_asn1_free_string (m);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user