mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-04 04:28:20 +00:00
Add pFo, parse certs from mach0's cdhash and minor x509 cleanup
This commit is contained in:
parent
9b69f8261f
commit
35bd0fbf06
@ -746,8 +746,36 @@ static bool parse_signature(struct MACH0_(obj_t) *bin, ut64 off) {
|
||||
parseCodeDirectory (bin->b, data + idx.offset, link.datasize);
|
||||
}
|
||||
break;
|
||||
case 0x10000:
|
||||
// TODO
|
||||
case 0x10000: // ASN1/DER certificate
|
||||
{
|
||||
ut8 header[8] = {0};
|
||||
r_buf_read_at (bin->b, data + idx.offset, header, sizeof (header));
|
||||
ut32 length = R_MIN (UT16_MAX, r_read_ble32 (header + 4, 1));
|
||||
ut8 *p = calloc (length, 1);
|
||||
if (p) {
|
||||
r_buf_read_at (bin->b, data + idx.offset + 0, p, length);
|
||||
ut32 *words = (ut32*)p;
|
||||
eprintf ("Magic: %x\n", words[0]);
|
||||
words += 2;
|
||||
eprintf ("wtf DUMP @%d!%d\n",
|
||||
(int)data + idx.offset + 8, (int)length);
|
||||
eprintf ("openssl pkcs7 -print_certs -text -inform der -in DUMP\n",
|
||||
(int)data + idx.offset + 8, (int)length);
|
||||
eprintf ("openssl asn1parse -offset %d -length %d -inform der -in /bin/ls\n",
|
||||
(int)data + idx.offset + 8, (int)length);
|
||||
eprintf ("pFp@%d!%d\n",
|
||||
(int)data + idx.offset + 8, (int)length);
|
||||
#if 0
|
||||
int fd = open ("DUMP", O_RDWR|O_CREAT, 0644);
|
||||
if (fd != -1) {
|
||||
eprintf ("See DUMP file.\n");
|
||||
write (fd, words, length);
|
||||
close (fd);
|
||||
}
|
||||
#endif
|
||||
free (p);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CSSLOT_REQUIREMENTS:
|
||||
#if 0
|
||||
|
@ -36,7 +36,8 @@ static const char *help_msg_p6[] = {
|
||||
static const char *help_msg_pF[] = {
|
||||
"Usage: pF[apd]", "[len]", "parse ASN1, PKCS, X509, DER",
|
||||
"pFa", "[len]", "decode ASN1 from current block",
|
||||
"pFp", "[len]", "Same with PKCS7",
|
||||
"pFo", "[len]", "decode ASN1 OID",
|
||||
"pFp", "[len]", "decode PKCS7",
|
||||
"pFx", "[len]", "Same with X509",
|
||||
NULL
|
||||
};
|
||||
@ -178,6 +179,7 @@ static const char *help_msg_p[] = {
|
||||
"pd", "[?] [sz] [a] [b]", "disassemble N opcodes (pd) or N bytes (pD)",
|
||||
"pd--", "[n]", "context disassembly of N instructions",
|
||||
"pf", "[?][.nam] [fmt]", "print formatted data (pf.name, pf.name $<expr>)",
|
||||
"pF", "[?][apx]", "print asn1, pkcs7 or x509",
|
||||
"ph", "[?][=|hash] ([len])", "calculate hash for a block",
|
||||
"pj", "[?] [len]", "print as indented JSON",
|
||||
"p", "[iI][df] [len]", "print N ops/bytes (f=func) (see pi? and pdi)",
|
||||
@ -897,10 +899,23 @@ static void print_format_help_help_help_help(RCore *core) {
|
||||
|
||||
static void cmd_print_fromage(RCore *core, const char *input, const ut8* data, int size) {
|
||||
switch (*input) {
|
||||
case '?':
|
||||
case '?': // "pF?"
|
||||
r_core_cmd_help (core, help_msg_pF);
|
||||
break;
|
||||
case 'p':
|
||||
case 'o': // "pFo" asn1 oid
|
||||
{
|
||||
RASN1Object *asn1 = r_asn1_create_object (data, size);
|
||||
if (asn1) {
|
||||
RASN1String *str1 = r_asn1_stringify_oid (data, size);
|
||||
if (str1) {
|
||||
r_cons_printf ("%s\n", str1->string);
|
||||
r_asn1_free_string (str1);
|
||||
}
|
||||
r_asn1_free_object (asn1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'p': // "pFp"
|
||||
{
|
||||
RCMS *cms = r_pkcs7_parse_cms (data, size);
|
||||
if (cms) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <string.h>
|
||||
#include "./x509.h"
|
||||
|
||||
bool r_x509_parse_validity (RX509Validity *validity, RASN1Object *object) {
|
||||
static bool r_x509_parse_validity(RX509Validity *validity, RASN1Object *object) {
|
||||
RASN1Object *o;
|
||||
if (!validity || !object || object->list.length != 2) {
|
||||
return false;
|
||||
@ -33,7 +33,7 @@ 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;
|
||||
}
|
||||
@ -45,7 +45,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;
|
||||
@ -303,7 +303,7 @@ void r_x509_free_algorithmidentifier (RX509AlgorithmIdentifier * ai) {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -1,9 +1,6 @@
|
||||
#ifndef R_X509_INTERNAL_H
|
||||
#define R_X509_INTERNAL_H
|
||||
|
||||
R_API bool r_x509_parse_validity (RX509Validity *validity, RASN1Object *object);
|
||||
R_API void r_x509_free_validity (RX509Validity* validity);
|
||||
|
||||
R_API bool r_x509_parse_algorithmidentifier (RX509AlgorithmIdentifier *ai, RASN1Object * object);
|
||||
R_API void r_x509_free_algorithmidentifier (RX509AlgorithmIdentifier * ai);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user