//
// sub_E02CA8 from 0xe02ca8 to 0xe02ff4 (844 bytes)
//
// 4 xrefs:
// > X509_check_host @ 0xe04638
// > X509_check_email @ 0xe04710
// > X509_check_ip @ 0xe04780
// > X509_check_ip_asc @ 0xe04990
//
// 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
//
__int64 __fastcall sub_E02CA8(__int64 a1, const char *a2, unsigned __int64 a3, int a4, int a5, _QWORD *a6)
{
size_t v7; // x26
unsigned int v9; // w25
int v12; // w28
unsigned int v13; // w27
__int64 (__fastcall *v14)(int, int, void *); // d11
unsigned int *ext_d2i; // x0
unsigned int *v16; // x20
int v17; // w22
int v18; // w19
__int64 v19; // x0
int *v21; // x22
_BYTE *v22; // x23
int v23; // w24
_BYTE *v24; // x0
int v25; // w1
int v26; // w23
int index_by_NID; // w19
unsigned int **subject_name; // x21
__int64 entry; // x0
unsigned int *data; // x4
int v31; // w0
__int64 v32; // x22
int v33; // w20
_BYTE *v34; // [xsp+88h] [xbp+88h] BYREF
v7 = a3;
v9 = a4 & 0xFFFF7FFF;
if ( a5 == 1 )
{
v12 = 22;
v13 = 48;
v14 = sub_E02FF4;
}
else if ( a5 == 2 )
{
if ( a3 > 1 && *a2 == 46 )
v9 |= 0x8000u;
v12 = 22;
v13 = 13;
if ( (v9 & 2) != 0 )
v14 = (__int64 (__fastcall *)(int, int, void *))sub_E028B0;
else
v14 = (__int64 (__fastcall *)(int, int, void *))sub_E03144;
}
else
{
v12 = 4;
v13 = 0;
v14 = (__int64 (__fastcall *)(int, int, void *))sub_E02BDC;
}
if ( !a3 )
v7 = strlen(a2);
ext_d2i = (unsigned int *)X509_get_ext_d2i(a1);
v16 = ext_d2i;
if ( !ext_d2i )
goto LABEL_13;
v17 = 0;
v18 = 0;
if ( (int)OPENSSL_sk_num(ext_d2i) <= 0 )
{
LABEL_11:
GENERAL_NAMES_free((__int64)v16);
if ( v17 && (v9 & 1) == 0 )
return 0;
LABEL_13:
if ( v13 && (v9 & 0x20) == 0 )
{
index_by_NID = -1;
subject_name = (unsigned int **)X509_get_subject_name(a1);
while ( 1 )
{
index_by_NID = X509_NAME_get_index_by_NID(subject_name, v13, index_by_NID);
if ( index_by_NID < 0 )
break;
entry = X509_NAME_get_entry((__int64 *)subject_name, index_by_NID);
data = (unsigned int *)X509_NAME_ENTRY_get_data(entry);
if ( *((_QWORD *)data + 1) && *data )
{
v31 = ASN1_STRING_to_UTF8(&v34, data);
v32 = v31;
if ( v31 < 0 )
return (unsigned int)-1;
v33 = ((__int64 (__fastcall *)(_BYTE *, _QWORD, const char *, size_t, _QWORD))v14)(v34, v31, a2, v7, v9);
if ( v33 > 0 && a6 )
{
*a6 = CRYPTO_strndup(v34, v32, (__int64)"crypto/x509v3/v3_utl.c", 0x2FFu);
CRYPTO_free(v34, (__int64)"crypto/x509v3/v3_utl.c", 768);
return (unsigned int)v33;
}
CRYPTO_free(v34, (__int64)"crypto/x509v3/v3_utl.c", 768);
if ( v33 )
return (unsigned int)v33;
}
}
}
return 0;
}
while ( 1 )
{
v19 = OPENSSL_sk_value((__int64)v16, v18);
if ( *(_DWORD *)v19 == a5 )
break;
++v18;
LABEL_10:
if ( v18 >= (int)OPENSSL_sk_num(v16) )
goto LABEL_11;
}
v21 = *(int **)(v19 + 8);
v22 = *((_BYTE **)v21 + 1);
if ( !v22 )
goto LABEL_19;
v23 = *v21;
if ( !*v21 || v12 != v21[1] )
goto LABEL_19;
if ( v12 == 22 )
{
v26 = ((__int64 (__fastcall *)(_QWORD, _QWORD, const char *, size_t, _QWORD))v14)(
*((_QWORD *)v21 + 1),
v23,
a2,
v7,
v9);
if ( v26 > 0 && a6 )
{
v24 = *((_BYTE **)v21 + 1);
v25 = *v21;
goto LABEL_26;
}
if ( v26 )
goto LABEL_27;
v17 = 1;
goto LABEL_20;
}
if ( v23 != (_DWORD)v7 || memcmp(*((const void **)v21 + 1), a2, v7) )
{
LABEL_19:
v17 = 1;
LABEL_20:
++v18;
goto LABEL_10;
}
if ( a6 )
{
v24 = v22;
v25 = v23;
v26 = 1;
LABEL_26:
*a6 = CRYPTO_strndup(v24, v25, (__int64)"crypto/x509v3/v3_utl.c", 0x2F1u);
goto LABEL_27;
}
v26 = 1;
LABEL_27:
GENERAL_NAMES_free((__int64)v16);
return (unsigned int)v26;
}