//
// SSL_use_certificate_chain_file from 0xd456b8 to 0xd4587c (452 bytes)
//
// 2 xrefs:
// > sub_D61DC0 @ 0xd61dfc
// > ??> @ 0xbd558
//
// 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 SSL_use_certificate_chain_file(__int64 a1, __int64 a2)
{
__int64 v4; // x0
__int64 v5; // x22
__int64 v6; // x23
__int64 v7; // x0
__int64 v8; // x0
__int64 v9; // x21
__int64 bio_X509_AUX; // x24
__int64 v11; // x0
unsigned int v12; // w25
_QWORD *bio_X509; // x19
__int64 error; // x0
__int64 v16; // x0
v4 = ERR_clear_error(a1);
v5 = *(_QWORD *)(a1 + 4400);
v6 = *(_QWORD *)(a1 + 4408);
v7 = BIO_s_file(v4);
v8 = BIO_new(v7);
v9 = v8;
if ( v8 )
{
if ( (int)BIO_ctrl(v8, 108, 3, a2) <= 0 )
{
bio_X509_AUX = 0;
ERR_put_error(20, 220, 2, "ssl/ssl_rsa.c", 611);
v12 = 0;
}
else
{
bio_X509_AUX = PEM_read_bio_X509_AUX(v9, 0, v5, v6);
if ( bio_X509_AUX )
{
v11 = SSL_use_certificate(a1, bio_X509_AUX);
v12 = v11;
if ( ERR_peek_error(v11) || !v12 )
{
v12 = 0;
}
else if ( (unsigned int)SSL_ctrl(a1, 88, 0, nullptr) )
{
while ( 1 )
{
bio_X509 = (_QWORD *)PEM_read_bio_X509(v9, 0, v5, v6);
if ( !bio_X509 )
break;
if ( !(unsigned int)SSL_ctrl(a1, 89, 0, bio_X509) )
{
v12 = 0;
X509_free(bio_X509);
goto LABEL_8;
}
}
error = ERR_peek_last_error(a1, 89, 0);
if ( BYTE3(error) == 9 && (v16 = error & 0xFFF, (_DWORD)v16 == 108) )
ERR_clear_error(v16);
else
v12 = 0;
}
else
{
v12 = 0;
}
}
else
{
v12 = 0;
ERR_put_error(20, 220, 9, "ssl/ssl_rsa.c", 618);
}
}
}
else
{
bio_X509_AUX = 0;
v12 = 0;
ERR_put_error(20, 220, 7, "ssl/ssl_rsa.c", 606);
}
LABEL_8:
X509_free(bio_X509_AUX);
BIO_free(v9);
return v12;
}