//
// sub_64231C from 0x64231c to 0x642aee (2002 bytes)
//
// 1 xrefs:
// > sub_642BAC @ 0x642f24
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
int __fastcall sub_64231C(size_t a1, int a2)
{
int result; // r0
int v4; // r0
int v5; // r11
int v6; // r0
int v7; // r6
int subject_name; // r0
size_t v9; // r0
int issuer_name; // r0
size_t v11; // r0
int version; // r0
size_t v13; // r0
int *serialNumber; // r6
int v15; // r5
int v16; // r2
size_t v17; // r0
int v18; // r0
int v19; // r5
size_t v20; // r0
int v21; // r9
int v22; // r4
int v23; // r0
int v24; // r8
int object; // r0
unsigned int *v26; // lr
unsigned int v27; // r4
int *v28; // r11
unsigned int i; // r1
unsigned int v30; // r2
const char *v31; // r3
int v32; // r0
unsigned int v33; // r2
int v34; // t1
int v35; // r0
size_t v36; // r0
int v37; // r0
size_t v38; // r0
int pubkey; // r8
int v40; // r0
int *v41; // r3
int v42; // r5
int v43; // r2
size_t v44; // r0
size_t v45; // r0
int v46; // r1
int v47; // r0
int data; // r0
int v49; // r4
size_t v50; // r0
int v51; // r6
size_t v52; // r0
_DWORD *v53; // r6
size_t v54; // r0
unsigned int *v55; // r5
size_t v56; // r0
int v57; // r6
int v58; // r5
_DWORD *v59; // r6
size_t v60; // r0
int v62; // [sp+10h] [bp-2DCh]
int v63; // [sp+18h] [bp-2D4h]
int v64; // [sp+28h] [bp-2C4h]
signed int v65; // [sp+30h] [bp-2BCh]
int v66; // [sp+34h] [bp-2B8h]
int peer_cert_chain; // [sp+38h] [bp-2B4h]
int v68; // [sp+40h] [bp-2ACh] BYREF
int *v69; // [sp+44h] [bp-2A8h] BYREF
int v70; // [sp+48h] [bp-2A4h] BYREF
int v71[2]; // [sp+4Ch] [bp-2A0h] BYREF
int v72; // [sp+54h] [bp-298h] BYREF
int v73; // [sp+58h] [bp-294h] BYREF
int v74; // [sp+5Ch] [bp-290h] BYREF
_DWORD *v75; // [sp+60h] [bp-28Ch] BYREF
unsigned int *v76; // [sp+64h] [bp-288h] BYREF
int v77[32]; // [sp+68h] [bp-284h] BYREF
int v78[129]; // [sp+E8h] [bp-204h] BYREF
peer_cert_chain = SSL_get_peer_cert_chain(a2);
if ( !peer_cert_chain )
return 27;
v65 = ((int (*)(void))OPENSSL_sk_num)();
result = sub_645B58(a1, v65);
if ( !result )
{
v4 = BIO_s_mem();
v5 = BIO_new(v4);
if ( v65 <= 0 )
{
LABEL_43:
BIO_free(v5);
return 0;
}
v62 = 0;
while ( 1 )
{
v6 = OPENSSL_sk_value(peer_cert_chain, v62);
v69 = nullptr;
v7 = v6;
v64 = v6;
subject_name = X509_get_subject_name();
X509_NAME_print_ex(v5, subject_name, 0, (char *)&loc_82031C + 3);
v9 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "Subject", v68, v9);
BIO_ctrl(v5, 1, 0, 0);
issuer_name = X509_get_issuer_name(v7);
X509_NAME_print_ex(v5, issuer_name, 0, (char *)&loc_82031C + 3);
v11 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "Issuer", v68, v11);
BIO_ctrl(v5, 1, 0, 0);
version = X509_get_version(v7);
BIO_printf(v5, "%lx", version);
v13 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "Version", v68, v13);
BIO_ctrl(v5, 1, 0, 0);
serialNumber = (int *)X509_get_serialNumber(v7);
if ( serialNumber[1] == 258 )
BIO_puts(v5, "-");
if ( *serialNumber > 0 )
{
v15 = 0;
do
{
v16 = *(unsigned __int8 *)(serialNumber[2] + v15++);
BIO_printf(v5, "%02x", v16);
}
while ( v15 < *serialNumber );
}
v17 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "Serial Number", v68, v17);
v18 = BIO_ctrl(v5, 1, 0, 0);
v75 = nullptr;
v19 = ASN1_STRING_new(v18);
if ( v19 )
{
X509_get0_signature(&v69, &v75, v64);
X509_signature_print(v5, v75, v19);
ASN1_STRING_free(v19);
if ( v75 )
{
i2a_ASN1_OBJECT(v5, *v75);
v20 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "Public Key Algorithm", v68, v20);
BIO_ctrl(v5, 1, 0, 0);
}
}
v63 = X509_get0_extensions(v64);
if ( ((int (*)(void))OPENSSL_sk_num)() > 0 )
{
v21 = 0;
v66 = v5;
while ( v21 < OPENSSL_sk_num(v63) )
{
v22 = OPENSSL_sk_value(v63, v21);
v23 = BIO_s_mem();
v24 = BIO_new(v23);
if ( !v24 )
break;
object = X509_EXTENSION_get_object(v22);
i2t_ASN1_OBJECT(v77, 128, object);
if ( !X509V3_EXT_print(v24, v22, 0, 0) )
{
data = X509_EXTENSION_get_data(v22);
ASN1_STRING_print(v24, data);
}
BIO_ctrl(v24, 115, 0, &v76);
v26 = v76;
v27 = 0;
v28 = v78;
for ( i = *v76; v27 < *v76; v28 = (int *)((char *)v28 + v47) )
{
while ( 1 )
{
v30 = v26[1];
if ( *(_BYTE *)(v30 + v27) == 10 )
{
++v27;
v31 = ", ";
}
else
{
v31 = &byte_9B1912;
}
if ( v27 < i )
break;
LABEL_29:
if ( ++v27 >= i )
goto LABEL_30;
}
v32 = *(unsigned __int8 *)(v30 + v27);
v33 = v30 + v27;
if ( v32 == 32 )
{
while ( ++v27 < i )
{
v34 = *(unsigned __int8 *)++v33;
v32 = v34;
if ( v34 != 32 )
goto LABEL_44;
}
goto LABEL_29;
}
LABEL_44:
++v27;
v47 = sub_624640(v28, (char *)v78 - (char *)v28 + 512, "%s%c", v31, v32);
v26 = v76;
i = *v76;
}
LABEL_30:
++v21;
sub_645C80(a1, v62, (int)v77, (char *)v78);
BIO_free(v24);
}
v5 = v66;
}
v35 = X509_get0_notBefore(v64);
ASN1_TIME_print(v5, v35);
v36 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "Start date", v68, v36);
BIO_ctrl(v5, 1, 0, 0);
v37 = X509_get0_notAfter(v64);
ASN1_TIME_print(v5, v37);
v38 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "Expire date", v68, v38);
BIO_ctrl(v5, 1, 0, 0);
pubkey = X509_get_pubkey(v64);
if ( !pubkey )
{
sub_61807C(a1, " Unable to load public key\n");
goto LABEL_37;
}
v40 = EVP_PKEY_id();
if ( v40 == 28 )
break;
if ( v40 == 116 )
{
v57 = EVP_PKEY_get0_DSA(pubkey);
DSA_get0_pqg(v57, &v74, &v75, &v76);
DSA_get0_key(v57, v78, v77);
sub_6421F8(a1, v5, v62, "dsa", "p", v74);
sub_6421F8(a1, v5, v62, "dsa", "q", (int)v75);
sub_6421F8(a1, v5, v62, "dsa", "g", (int)v76);
sub_6421F8(a1, v5, v62, "dsa", "priv_key", v77[0]);
sub_6421F8(a1, v5, v62, "dsa", "pub_key", v78[0]);
goto LABEL_36;
}
if ( v40 == 6 )
{
v49 = EVP_PKEY_get0_RSA(pubkey);
RSA_get0_key(v49, &v70, v71);
RSA_get0_factors(v49, &v72, &v73);
RSA_get0_crt_params(v49, &v74, &v75, &v76);
BN_print(v5, v70);
v50 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "RSA Public Key", v68, v50);
BIO_ctrl(v5, 1, 0, 0);
sub_6421F8(a1, v5, v62, "rsa", "n", v70);
sub_6421F8(a1, v5, v62, "rsa", "e", v71[0]);
sub_6421F8(a1, v5, v62, "rsa", "d", v71[1]);
sub_6421F8(a1, v5, v62, "rsa", "p", v72);
v51 = v73;
sub_624640(v78, 32, "%s(%s)", "rsa", "q");
if ( v51 )
BN_print(v5, v51);
v52 = BIO_ctrl(v5, 3, 0, v77);
sub_645BE0(a1, v62, (char *)v78, v77[0], v52);
BIO_ctrl(v5, 1, 0, 0);
sub_6421F8(a1, v5, v62, "rsa", "dmp1", v74);
v53 = v75;
sub_624640(v78, 32, "%s(%s)", "rsa", "dmq1");
if ( v53 )
BN_print(v5, v53);
v54 = BIO_ctrl(v5, 3, 0, v77);
sub_645BE0(a1, v62, (char *)v78, v77[0], v54);
BIO_ctrl(v5, 1, 0, 0);
v55 = v76;
sub_624640(v78, 32, "%s(%s)", "rsa", "iqmp");
if ( v55 )
goto LABEL_51;
goto LABEL_52;
}
LABEL_36:
EVP_PKEY_free(pubkey);
LABEL_37:
v41 = v69;
if ( v69 )
{
if ( *v69 > 0 )
{
v42 = 0;
do
{
v43 = *(unsigned __int8 *)(v41[2] + v42++);
BIO_printf(v5, "%02x:", v43);
v41 = v69;
}
while ( v42 < *v69 );
}
v44 = BIO_ctrl(v5, 3, 0, &v68);
sub_645BE0(a1, v62, "Signature", v68, v44);
BIO_ctrl(v5, 1, 0, 0);
}
PEM_write_bio_X509(v5, v64);
v45 = BIO_ctrl(v5, 3, 0, &v68);
v46 = v62++;
sub_645BE0(a1, v46, "Cert", v68, v45);
BIO_ctrl(v5, 1, 0, 0);
if ( v62 == v65 )
goto LABEL_43;
}
v58 = EVP_PKEY_get0_DH(pubkey);
DH_get0_pqg(v58, &v72, &v73, &v74);
DH_get0_key(v58, &v76, &v75);
sub_6421F8(a1, v5, v62, "dh", "p", v72);
sub_6421F8(a1, v5, v62, "dh", "q", v73);
sub_6421F8(a1, v5, v62, "dh", "g", v74);
v59 = v75;
sub_624640(v78, 32, "%s(%s)", "dh", "priv_key");
if ( v59 )
BN_print(v5, v59);
v60 = BIO_ctrl(v5, 3, 0, v77);
sub_645BE0(a1, v62, (char *)v78, v77[0], v60);
BIO_ctrl(v5, 1, 0, 0);
v55 = v76;
sub_624640(v78, 32, "%s(%s)", "dh", "pub_key");
if ( v55 )
LABEL_51:
BN_print(v5, v55);
LABEL_52:
v56 = BIO_ctrl(v5, 3, 0, v77);
sub_645BE0(a1, v62, (char *)v78, v77[0], v56);
BIO_ctrl(v5, 1, 0, 0);
goto LABEL_36;
}
return result;
}