From 5ef76f42b8483420dda9b57c07c37f39bd71f7ea Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Sat, 27 Dec 2025 19:00:27 +0800 Subject: [PATCH] Fix small mistake on x509 structure. (#5690) * Fix small mistake on x509 structure. * Add test with ed25519 certificate --- librz/util/x509.c | 52 ++++++++++++++------------ test/db/cmd/cmd_asn1 | 88 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 24 deletions(-) diff --git a/librz/util/x509.c b/librz/util/x509.c index 9f18e54cfc..d8d72b0f52 100644 --- a/librz/util/x509.c +++ b/librz/util/x509.c @@ -604,7 +604,7 @@ static void x509_subjectpublickeyinfo_to_structure(RzStructuredData *parent, RzX } rz_asn1_string_free(m); } else if (spki->subjectPublicKey) { - m = rz_asn1_stringify_bytes(spki->subjectPublicKeyExponent->binary, spki->subjectPublicKeyExponent->length); + m = rz_asn1_stringify_bytes(spki->subjectPublicKey->binary, spki->subjectPublicKey->length); if (m) { rz_structured_data_map_add_string(parent, "subjectPublicKey", m->string); } @@ -617,7 +617,6 @@ static void x509_extensions_to_structure(RzStructuredData *parent, RzX509Extensi return; } - RzASN1String *m = NULL; RzStructuredData *extensions = rz_structured_data_map_add_array(parent, "extensions"); for (ut32 i = 0; i < exts->length; i++) { RzX509Extension *e = exts->extensions[i]; @@ -632,29 +631,34 @@ static void x509_extensions_to_structure(RzStructuredData *parent, RzX509Extensi if (e->critical) { rz_structured_data_map_add_boolean(extension, "critical", e->critical); } - if (e->extnValue) { - if (rz_str_is_printable_limited((const char *)e->extnValue->binary, e->extnValue->length)) { - m = rz_asn1_stringify_string(e->extnValue->binary, e->extnValue->length); - } else if (e->extnValue->length > 3) { - RzASN1Object *obj = rz_asn1_object_parse(e->extnValue->binary, e->extnValue->length); - if (obj) { - RzStructuredData *sd = rz_asn1_to_structure(obj, true); - rz_asn1_object_free(obj); - rz_structured_data_map_add(extension, "extnValue", sd); - continue; - } - } - - if (!m && e->extnValue->length < 20) { - m = rz_asn1_stringify_integer(e->extnValue->binary, e->extnValue->length); - } else if (!m) { - m = rz_asn1_stringify_bytes(e->extnValue->binary, e->extnValue->length); - } - if (m) { - rz_structured_data_map_add_string(extension, "extnValue", m->string); - } - rz_asn1_string_free(m); + if (!e->extnValue) { + continue; } + + RzASN1String *m = NULL; + const RzASN1Binary *val = e->extnValue; + + if (rz_str_is_printable_limited((const char *)val->binary, val->length)) { + m = rz_asn1_stringify_string(val->binary, val->length); + } else if (val->length > 3) { + RzASN1Object *obj = rz_asn1_object_parse(val->binary, val->length); + if (obj) { + RzStructuredData *sd = rz_asn1_to_structure(obj, true); + rz_asn1_object_free(obj); + rz_structured_data_map_add(extension, "extnValue", sd); + continue; + } + } + + if (!m && val->length < 20) { + m = rz_asn1_stringify_integer(val->binary, val->length); + } else if (!m) { + m = rz_asn1_stringify_bytes(val->binary, val->length); + } + if (m) { + rz_structured_data_map_add_string(extension, "extnValue", m->string); + } + rz_asn1_string_free(m); } } diff --git a/test/db/cmd/cmd_asn1 b/test/db/cmd/cmd_asn1 index 744d9d53a0..18c3cceaca 100644 --- a/test/db/cmd/cmd_asn1 +++ b/test/db/cmd/cmd_asn1 @@ -1383,3 +1383,91 @@ pe32: EOF RUN + +NAME=x509 ed25519 +FILE== +CMDS=<S....<...6.....| + : 07 00 72 bb 37 b6 d1 4b 0b f6 a3 2c 9a 49 d0 08 |..r.7..K...,.I..| +--- +tbsCertificate: + version: 1 + serialNumber: "19:6e:fc:cf:0d:0e:2f:41:a9:b4:98:be:f9:af:75:74:16:bb:0e:c4" + signature: + algorithm: "ed25519 (1.3.101.112)" + issuer: + - oid: "countryName (2.5.4.6)" + value: "DE" + - oid: "commonName (2.5.4.3)" + value: "www.example.com" + validity: + notBefore: "31/03/2019 17:51:22 GMT" + notAfter: "28/02/2021 17:51:22 GMT" + subject: + - oid: "countryName (2.5.4.6)" + value: "DE" + - oid: "commonName (2.5.4.3)" + value: "www.example.com" + subjectPublicKeyInfo: + algorithm: "ed25519 (1.3.101.112)" + subjectPublicKey: | + 2b ce e0 d1 bf 02 0b 57 80 e6 6b ca 5e df 6e 7b +......W..k.^.n{ + 36 70 25 85 84 ca 0e f8 63 4c 53 64 49 2a 09 cc 6p%.....cLSdI*.. + extensions: [] +algorithmIdentifier: + algorithm: "ed25519 (1.3.101.112)" +signature: | + 20 8b bf 69 ad d0 b6 bd c8 13 9b 68 fe 7b d6 55 ..i.......h.{.U + 8f 72 dd c8 b0 1b 90 e7 03 bd 17 dc 02 d4 84 5b .r.............[ + 3e 53 96 8b b5 f6 3c b0 d4 f5 36 0e f6 86 df 94 >S....<...6..... + 07 00 72 bb 37 b6 d1 4b 0b f6 a3 2c 9a 49 d0 08 ..r.7..K...,.I.. + +EOF +RUN