//
// sub_643938 from 0x643938 to 0x6448e2 (4010 bytes)
//
// 2 xrefs:
// > sub_644CCC @ 0x644da8
// > sub_644E50 @ 0x644f16
//
// 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_643938(int a1, int a2)
{
size_t v4; // r4
_DWORD *v5; // r9
int v6; // r8
int v7; // r11
int v8; // r0
int file; // r6
int v10; // r0
int result; // r0
int v12; // r3
int v13; // r2
int v14; // r5
int v15; // r0
int v16; // r3
bool v17; // zf
int v18; // r5
int v19; // r0
int v20; // r2
int v21; // r1
int v22; // lr
int v23; // r6
int v24; // r3
int v25; // r0
int v26; // r8
int v27; // r5
int v28; // r8
int v29; // r6
FILE *v30; // r0
int v31; // r5
int v32; // r0
int v33; // r0
const char *v34; // r0
int v35; // r2
int v36; // r2
int v37; // r2
int v38; // r3
int v39; // r5
char *v40; // r5
int v41; // r0
const char *v42; // r0
int v43; // r3
int v44; // r6
int v45; // r5
int cert_store; // r6
int v47; // r0
int v48; // r0
int v49; // r3
int v50; // r2
int v51; // r3
int v52; // r0
int v53; // r0
const char *v54; // r0
const char *v55; // r0
const char *v56; // r3
char *v57; // r6
void *v58; // r1
_BOOL4 v59; // r3
int v60; // r0
int v61; // r0
const char *v62; // r0
int v63; // r0
const char *v64; // r2
const char *v65; // r3
int v66; // r3
int v67; // r0
int (__fastcall *v68)(size_t, _DWORD, _DWORD); // r3
int v69; // r6
int v70; // r0
int v71; // r5
int v72; // r0
int v73; // r3
int v74; // r5
int v75; // r0
int v76; // r4
int v77; // r6
int certificate; // r0
int pubkey; // r5
int privatekey; // r0
int v81; // r0
int v82; // r0
const char *v83; // r0
int v84; // r5
int v85; // r3
const char *v86; // r2
const char *v87; // r3
int v88; // r0
const char *v89; // r0
int v90; // r0
int v91; // r0
const char *v92; // r0
int error; // r0
const char *v94; // r0
int method; // r6
int v96; // r0
int opener; // r0
int v98; // r0
int v99; // r0
int closer; // r0
int private_key; // r5
int v102; // r0
int v103; // r5
__int64 stream; // [sp+8h] [bp-BCh]
FILE *streama; // [sp+8h] [bp-BCh]
int v106; // [sp+10h] [bp-B4h]
const char *v107; // [sp+14h] [bp-B0h]
const char *v108; // [sp+18h] [bp-ACh]
const char *v109; // [sp+1Ch] [bp-A8h]
char *cp; // [sp+20h] [bp-A4h]
int v111; // [sp+24h] [bp-A0h]
int v112; // [sp+28h] [bp-9Ch]
int v113; // [sp+2Ch] [bp-98h]
char *v114; // [sp+30h] [bp-94h]
const char *v115; // [sp+34h] [bp-90h]
int v116; // [sp+38h] [bp-8Ch] BYREF
int v117; // [sp+3Ch] [bp-88h] BYREF
_DWORD buf[32]; // [sp+40h] [bp-84h] BYREF
v4 = *(_DWORD *)a1;
v111 = *(_DWORD *)(a1 + 4 * (a2 + 104));
if ( *(_DWORD *)(a1 + 248) != 2 )
{
v5 = (_DWORD *)(v4 + 680);
v6 = *(_DWORD *)(a1 + 548);
v7 = *(unsigned __int8 *)(a1 + 552);
v106 = *(_DWORD *)(v4 + 732);
HIDWORD(stream) = *(_DWORD *)(v4 + 704);
LODWORD(stream) = *(_DWORD *)(v4 + 708);
v108 = *(const char **)(a1 + 560);
v109 = *(const char **)(a1 + 556);
v107 = *(const char **)(v4 + 684);
LABEL_3:
cp = *(char **)(a1 + 152);
goto LABEL_4;
}
v12 = *(_DWORD *)(a1 + 420);
if ( v12 == -1 )
v13 = 0;
else
v13 = 24;
if ( *(_DWORD *)(v13 + a1 + 504) != 2 )
{
v6 = *(_DWORD *)(a1 + 580);
v5 = (_DWORD *)(v4 + 772);
LABEL_19:
v106 = *(_DWORD *)(v4 + 824);
HIDWORD(stream) = *(_DWORD *)(v4 + 796);
LABEL_20:
LODWORD(stream) = *(_DWORD *)(v4 + 800);
v108 = *(const char **)(a1 + 592);
LABEL_21:
v7 = *(unsigned __int8 *)(a1 + 584);
v109 = *(const char **)(a1 + 588);
goto LABEL_22;
}
if ( v12 == -1 )
v35 = 0;
else
v35 = 24;
v5 = (_DWORD *)(v4 + 680);
v6 = *(_DWORD *)(a1 + 548);
if ( *(_DWORD *)(v35 + a1 + 504) != 2 )
goto LABEL_19;
if ( v12 == -1 )
v36 = 0;
else
v36 = 24;
v106 = *(_DWORD *)(v4 + 732);
HIDWORD(stream) = *(_DWORD *)(v4 + 704);
if ( *(_DWORD *)(v36 + a1 + 504) != 2 )
goto LABEL_20;
if ( v12 == -1 )
v37 = 0;
else
v37 = 24;
LODWORD(stream) = *(_DWORD *)(v4 + 708);
v108 = *(const char **)(a1 + 560);
if ( *(_DWORD *)(v37 + a1 + 504) != 2 )
goto LABEL_21;
if ( v12 == -1 )
v38 = 0;
else
v38 = 24;
v109 = *(const char **)(a1 + 556);
v7 = *(unsigned __int8 *)(a1 + 552);
if ( *(_DWORD *)(v38 + a1 + 504) == 2 )
{
v107 = *(const char **)(v4 + 684);
goto LABEL_3;
}
LABEL_22:
v107 = *(const char **)(v4 + 776);
cp = *(char **)(a1 + 236);
LABEL_4:
if ( byte_ACAECC )
goto LABEL_5;
if ( ((int (*)(void))RAND_status)() )
{
byte_ACAECC = 1;
goto LABEL_5;
}
v8 = *(_DWORD *)(v4 + 1100);
if ( v8 )
{
file = RAND_load_file(v8, 1024);
if ( ((int (*)(void))RAND_status)() )
{
result = file;
if ( file )
return result;
goto LABEL_5;
}
}
else
{
file = 0;
}
do
{
if ( !RAND_bytes(buf, 64) )
break;
v10 = RAND_add(buf, 64, 0, 1077936128);
}
while ( !RAND_status(v10) );
*(_BYTE *)(v4 + 1668) = 0;
RAND_file_name(v4 + 1668, 0x4000);
if ( !*(_BYTE *)(v4 + 1668) || (v39 = RAND_load_file(v4 + 1668, 1024), !RAND_status(v39)) )
{
sub_61807C(v4, "libcurl is now using a weak random seed!\n");
return 35;
}
result = v39 + file;
if ( !(v39 + file) )
{
LABEL_5:
*v5 = 1;
switch ( v6 )
{
case 0:
case 1:
case 4:
case 5:
case 6:
case 7:
v14 = TLS_client_method();
if ( *(_DWORD *)(a1 + 24 * a2 + 464) )
SSL_CTX_free();
v15 = SSL_CTX_new(v14);
*(_DWORD *)(a1 + 24 * a2 + 464) = v15;
if ( v15 )
{
SSL_CTX_ctrl(v15, 33, 16, 0);
if ( *(_DWORD *)(v4 + 456) && *(_BYTE *)(v4 + 912) )
{
SSL_CTX_set_msg_callback(*(_DWORD *)(a1 + 24 * a2 + 464), sub_641CB4);
SSL_CTX_ctrl(*(_DWORD *)(a1 + 24 * a2 + 464), 16, 0, a1);
}
if ( *(_DWORD *)(a1 + 248) != 2
|| (*(_DWORD *)(a1 + 420) == -1 ? (v43 = 0) : (v43 = 24), *(_DWORD *)(v43 + a1 + 504) == 2) )
{
v16 = *(unsigned __int8 *)(v4 + 676) ^ 1;
}
else
{
v16 = *(unsigned __int8 *)(v4 + 768) ^ 1;
}
v17 = v16 == 0;
v18 = -1677573121;
LOWORD(v19) = 19455;
LOWORD(v20) = 17407;
LOWORD(v21) = 17407;
if ( !v16 )
v18 = -1677571073;
LOWORD(v22) = 17407;
LOWORD(v23) = 19455;
HIWORD(v21) = -26110;
HIWORD(v19) = -32254;
if ( !v16 )
v21 = -1711125505;
LOWORD(v24) = 17407;
HIWORD(v20) = -32254;
HIWORD(v22) = -29182;
if ( v17 )
v20 = v19;
HIWORD(v24) = -27134;
v25 = -1778234369;
v26 = v6 - 2;
HIWORD(v23) = -29182;
if ( !v17 )
{
v23 = v22;
v25 = v24;
}
switch ( v26 )
{
case 0:
sub_6180F8(v4, "OpenSSL was built without SSLv2 support", v20, v24);
return 4;
case 1:
v24 = v106;
if ( v106 == 1 )
sub_61807C(v4, "Set version TLSv1.x for SRP authorisation\n", v20);
v21 = v18;
goto LABEL_48;
case 2:
goto LABEL_48;
case 3:
v21 = v23;
goto LABEL_48;
case 4:
v21 = v25;
goto LABEL_48;
case 5:
sub_6180F8(v4, "OpenSSL was built without TLS 1.3 support", v20, v24);
return 4;
default:
v21 = v20;
LABEL_48:
SSL_CTX_set_options(*(_DWORD *)(a1 + 24 * a2 + 464), v21, v20, v24);
if ( *(_BYTE *)(a1 + 643) )
SSL_CTX_set_next_proto_select_cb(*(_DWORD *)(a1 + 24 * a2 + 464), sub_642284, a1);
if ( *(_BYTE *)(a1 + 644) )
{
LOBYTE(buf[0]) = 8;
qmemcpy((char *)buf + 1, "http/1.1", 8);
sub_61807C(v4, "ALPN, offering %s\n", "http/1.1");
SSL_CTX_set_alpn_protos(*(_DWORD *)(a1 + 24 * a2 + 464), buf, 9);
}
v27 = HIDWORD(stream);
if ( HIDWORD(stream) )
v27 = 1;
if ( !stream )
goto LABEL_94;
v112 = *(_DWORD *)(a1 + 24 * a2 + 464);
if ( *(_DWORD *)(a1 + 248) != 2 )
{
v115 = *(const char **)(v4 + 712);
v114 = *(char **)(v4 + 716);
LABEL_57:
v113 = *(_DWORD *)(v4 + 720);
goto LABEL_58;
}
v50 = *(_DWORD *)(a1 + 420);
if ( v50 == -1 )
v51 = 0;
else
v51 = 24;
if ( *(_DWORD *)(v51 + a1 + 504) == 2 )
{
if ( v50 == -1 )
v66 = 0;
else
v66 = 24;
v115 = *(const char **)(v4 + 712);
v114 = *(char **)(v4 + 716);
if ( *(_DWORD *)(v66 + a1 + 504) == 2 )
goto LABEL_57;
}
else
{
v115 = *(const char **)(v4 + 804);
v114 = *(char **)(v4 + 808);
}
v113 = *(_DWORD *)(v4 + 812);
LABEL_58:
v28 = *(_DWORD *)a1;
if ( (_DWORD)stream && *(_BYTE *)stream && !sub_62AA74((_BYTE *)stream, "PEM") )
{
if ( sub_62AA74((_BYTE *)stream, "DER") )
{
v29 = 2;
}
else
{
if ( sub_62AA74((_BYTE *)stream, "ENG") )
{
if ( !v113 )
{
LABEL_162:
v63 = *(_DWORD *)(v28 + 34608);
if ( !v63 )
{
sub_6180F8(v28, "crypto engine not set, can't load certificate");
return 58;
}
buf[0] = HIDWORD(stream);
buf[1] = 0;
if ( !ENGINE_ctrl(v63, 13, 0, "LOAD_CERT_CTRL", 0) )
{
sub_6180F8(v28, "ssl engine does not support loading certificates");
return 58;
}
if ( !ENGINE_ctrl_cmd(*(_DWORD *)(v28 + 34608), "LOAD_CERT_CTRL", 0, buf, 0, 1) )
{
error = ERR_get_error(0);
v94 = (const char *)ERR_error_string(error, 0);
sub_6180F8(
v28,
"ssl engine cannot load client cert with id '%s' [%s]",
(const char *)HIDWORD(stream),
v94);
return 58;
}
if ( !buf[1] )
{
sub_6180F8(v28, "ssl engine didn't initialized the certificate properly.");
return 58;
}
if ( SSL_CTX_use_certificate(v112) != 1 )
{
sub_6180F8(v28, "unable to set client certificate");
X509_free(buf[1]);
return 58;
}
X509_free(buf[1]);
goto LABEL_140;
}
v29 = 42;
goto LABEL_63;
}
if ( sub_62AA74((_BYTE *)stream, "P12") )
v29 = 43;
else
v29 = -1;
}
}
else
{
v29 = 1;
}
if ( !v27 )
goto LABEL_94;
if ( v113 )
{
LABEL_63:
SSL_CTX_set_default_passwd_cb_userdata(v112, v113);
SSL_CTX_set_default_passwd_cb(v112, sub_642254);
}
if ( v29 == 2 )
{
v60 = SSL_CTX_use_certificate_file(v112, HIDWORD(stream), 2);
if ( v60 != 1 )
{
v61 = ERR_get_error(v60);
v62 = (const char *)ERR_error_string(v61, 0);
sub_6180F8(
v28,
"could not load ASN1 client certificate, OpenSSL error %s, (no key found, wrong pass phrase, or wrong file format?)",
v62);
return 58;
}
}
else
{
if ( v29 > 2 )
{
if ( v29 != 42 )
{
buf[0] = 0;
v30 = fopen((const char *)HIDWORD(stream), "rb");
if ( !v30 )
{
sub_6180F8(v28, "could not open PKCS12 file '%s'", (const char *)HIDWORD(stream));
return 58;
}
streama = v30;
v31 = d2i_PKCS12_fp(v30, 0);
v32 = fclose(streama);
if ( !v31 )
{
sub_6180F8(v28, "error reading PKCS12 file '%s'", (const char *)HIDWORD(stream));
return 58;
}
PKCS12_PBE_add(v32);
if ( !PKCS12_parse(v31, v113, &v117, &v116, buf) )
{
v33 = ERR_get_error(0);
v34 = (const char *)ERR_error_string(v33, 0);
sub_6180F8(v28, "could not parse PKCS12 file, check password, OpenSSL error %s", v34);
PKCS12_free(v31);
return 58;
}
PKCS12_free(v31);
v81 = SSL_CTX_use_certificate(v112);
if ( v81 != 1 )
{
v82 = ERR_get_error(v81);
v83 = (const char *)ERR_error_string(v82, 0);
sub_6180F8(v28, "could not load PKCS12 client certificate, OpenSSL error %s", v83);
LABEL_205:
EVP_PKEY_free(v117);
X509_free(v116);
OPENSSL_sk_pop_free(buf[0], X509_free);
return 58;
}
if ( SSL_CTX_use_PrivateKey(v112, v117) != 1 )
{
sub_6180F8(v28, "unable to use private key from PKCS12 file '%s'", (const char *)HIDWORD(stream));
goto LABEL_205;
}
if ( !SSL_CTX_check_private_key(v112) )
{
sub_6180F8(
v28,
"private key from PKCS12 file '%s' does not match certificate in same file",
(const char *)HIDWORD(stream));
goto LABEL_205;
}
v102 = buf[0];
if ( buf[0] )
{
while ( OPENSSL_sk_num(v102) )
{
v103 = OPENSSL_sk_pop(buf[0]);
if ( !SSL_CTX_ctrl(v112, 14, 0, v103) )
{
X509_free(v103);
sub_6180F8(v28, "cannot add certificate to certificate chain");
goto LABEL_205;
}
if ( !SSL_CTX_add_client_CA(v112, v103) )
{
sub_6180F8(v28, "cannot add certificate to client CA list");
goto LABEL_205;
}
v102 = buf[0];
}
}
EVP_PKEY_free(v117);
X509_free(v116);
OPENSSL_sk_pop_free(buf[0], X509_free);
if ( !v114 )
goto LABEL_194;
if ( !*v114 )
goto LABEL_194;
v84 = 1;
if ( sub_62AA74(v114, "PEM") )
goto LABEL_194;
goto LABEL_207;
}
goto LABEL_162;
}
if ( v29 != 1 )
{
sub_6180F8(v28, "not supported file type '%s' for certificate", (const char *)stream);
return 58;
}
v52 = SSL_CTX_use_certificate_chain_file(v112, HIDWORD(stream));
if ( v52 != 1 )
{
v53 = ERR_get_error(v52);
v54 = (const char *)ERR_error_string(v53, 0);
sub_6180F8(
v28,
"could not load PEM client certificate, OpenSSL error %s, (no key found, wrong pass phrase, or wrong file format?)",
v54);
return 58;
}
}
LABEL_140:
if ( v114 )
{
if ( *v114 )
{
v84 = 0;
if ( !sub_62AA74(v114, "PEM") )
{
LABEL_207:
if ( sub_62AA74(v114, "DER") )
{
if ( SSL_CTX_use_PrivateKey_file(v112, v115, 2) != 1 )
{
v56 = v114;
LABEL_147:
sub_6180F8(v28, "unable to set private key file: '%s' type %s", v115, v56);
return 58;
}
}
else if ( sub_62AA74(v114, "ENG") )
{
if ( !*(_DWORD *)(v28 + 34608) )
{
sub_6180F8(v28, "crypto engine not set, can't load private key");
return 58;
}
method = UI_create_method("curl user interface");
if ( !method )
{
sub_6180F8(v28, "unable do create OpenSSL user-interface method");
return 58;
}
v96 = ((int (*)(void))UI_OpenSSL)();
opener = UI_method_get_opener(v96);
v98 = UI_method_set_opener(method, opener);
v99 = UI_OpenSSL(v98);
closer = UI_method_get_closer(v99);
UI_method_set_closer(method, closer);
UI_method_set_reader(method, sub_641F30);
UI_method_set_writer(method, sub_641EF4);
private_key = ENGINE_load_private_key(*(_DWORD *)(v28 + 34608), v115, method, v113);
UI_destroy_method(method);
if ( !private_key )
{
sub_6180F8(v28, "failed to load private key from crypto engine");
return 58;
}
if ( SSL_CTX_use_PrivateKey(v112, private_key) != 1 )
{
sub_6180F8(v28, "unable to set private key");
EVP_PKEY_free(private_key);
return 58;
}
EVP_PKEY_free(private_key);
}
else
{
if ( !sub_62AA74(v114, "P12") )
{
sub_6180F8(v28, "not supported file type for private key");
return 58;
}
if ( !v84 )
{
sub_6180F8(v28, "file type P12 for private key not supported");
return 58;
}
}
goto LABEL_194;
}
}
}
v55 = v115;
if ( !v115 )
v55 = (const char *)HIDWORD(stream);
v115 = v55;
if ( SSL_CTX_use_PrivateKey_file(v112, v55, 1) != 1 )
{
v56 = v114;
if ( !v114 )
v56 = "PEM";
goto LABEL_147;
}
LABEL_194:
v77 = SSL_new(v112);
if ( !v77 )
{
sub_6180F8(v28, "unable to create an SSL structure");
return 58;
}
certificate = SSL_get_certificate();
v116 = certificate;
if ( certificate )
{
pubkey = X509_get_pubkey(certificate);
privatekey = SSL_get_privatekey(v77);
EVP_PKEY_copy_parameters(pubkey, privatekey);
EVP_PKEY_free(pubkey);
}
SSL_free(v77);
if ( !SSL_CTX_check_private_key(v112) )
{
sub_6180F8(v28, "Private key does not match the certificate public key");
return 58;
}
LABEL_94:
if ( *(_DWORD *)(a1 + 248) != 2
|| (*(_DWORD *)(a1 + 420) == -1 ? (v49 = 0) : (v49 = 24), *(_DWORD *)(v49 + a1 + 504) == 2) )
{
v40 = *(char **)(a1 + 576);
}
else
{
v40 = *(char **)(a1 + 608);
}
if ( !v40 )
v40 = "ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH";
if ( !SSL_CTX_set_cipher_list(*(_DWORD *)(a1 + 24 * a2 + 464), v40) )
{
sub_6180F8(v4, "failed setting cipher list: %s", v40);
return 59;
}
sub_61807C(v4, "Cipher selection: %s\n", v40);
if ( v106 != 1 )
goto LABEL_112;
if ( *(_DWORD *)(a1 + 248) != 2
|| (*(_DWORD *)(a1 + 420) == -1 ? (v85 = 0) : (v85 = 24), *(_DWORD *)(v85 + a1 + 504) == 2) )
{
v57 = *(char **)(v4 + 724);
}
else
{
v57 = *(char **)(v4 + 816);
}
sub_61807C(v4, "Using TLS-SRP username: %s\n", v57);
if ( !SSL_CTX_set_srp_username(*(_DWORD *)(a1 + 24 * a2 + 464), v57) )
{
sub_6180F8(v4, "Unable to set SRP user name");
return 43;
}
if ( *(_DWORD *)(a1 + 248) != 2 || *(_DWORD *)(a1 + 24 * (*(_DWORD *)(a1 + 420) != -1) + 504) == 2 )
v58 = *(void **)(v4 + 728);
else
v58 = *(void **)(v4 + 820);
if ( !SSL_CTX_set_srp_password(*(_DWORD *)(a1 + 24 * a2 + 464), v58) )
{
sub_6180F8(v4, "failed setting SRP password");
return 43;
}
if ( *(_DWORD *)(a1 + 248) != 2 || *(_DWORD *)(a1 + 24 * (*(_DWORD *)(a1 + 420) != -1) + 504) == 2 )
v59 = *(_DWORD *)(a1 + 576) == 0;
else
v59 = *(_DWORD *)(a1 + 608) == 0;
if ( v59 )
{
sub_61807C(v4, "Setting cipher list SRP\n");
if ( !SSL_CTX_set_cipher_list(*(_DWORD *)(a1 + 24 * a2 + 464), "SRP") )
{
sub_6180F8(v4, "failed setting SRP cipher list");
return 59;
}
}
LABEL_112:
v44 = (int)v108;
if ( v108 )
v44 = 1;
v45 = (int)v109;
if ( v109 )
v45 = 1;
if ( !(v45 | v44) )
goto LABEL_117;
if ( SSL_CTX_load_verify_locations(*(_DWORD *)(a1 + 24 * a2 + 464), v108, v109) )
{
sub_61807C(v4, "successfully set certificate verify locations:\n");
}
else
{
if ( v7 )
{
v64 = v108;
if ( !v44 )
v64 = "none";
v65 = v109;
if ( !v45 )
v65 = "none";
sub_6180F8(v4, "error setting certificate verify locations:\n CAfile: %s\n CApath: %s", v64, v65);
return 77;
}
sub_61807C(v4, "error setting certificate verify locations, continuing anyway:\n");
}
v86 = v108;
if ( !v44 )
v86 = "none";
v87 = v109;
if ( !v45 )
v87 = "none";
sub_61807C(v4, " CAfile: %s\n CApath: %s\n", v86, v87);
LABEL_117:
if ( v107 )
{
cert_store = SSL_CTX_get_cert_store(*(_DWORD *)(a1 + 24 * a2 + 464));
v47 = X509_LOOKUP_file();
v48 = X509_STORE_add_lookup(cert_store, v47);
if ( !v48 || !X509_load_crl_file(v48, v107, 1) )
{
sub_6180F8(v4, "error loading CRL file: %s", v107);
return 82;
}
sub_61807C(v4, "successfully load CRL file:\n");
v67 = SSL_CTX_get_cert_store(*(_DWORD *)(a1 + 24 * a2 + 464));
X509_STORE_set_flags(v67, 12);
sub_61807C(v4, " CRLfile: %s\n", v107);
}
SSL_CTX_set_verify(*(_DWORD *)(a1 + 24 * a2 + 464), v7, 0);
v68 = *(int (__fastcall **)(size_t, _DWORD, _DWORD))(v4 + 692);
if ( v68 && (v69 = v68(v4, *(_DWORD *)(a1 + 24 * a2 + 464), *(_DWORD *)(v4 + 696))) != 0 )
{
sub_6180F8(v4, "error signaled by ssl ctx callback");
result = v69;
}
else
{
v70 = *(_DWORD *)(a1 + 24 * a2 + 468);
if ( v70 )
SSL_free(v70);
v71 = a1 + 24 * a2;
v72 = SSL_new(*(_DWORD *)(v71 + 464));
*(_DWORD *)(v71 + 468) = v72;
if ( v72 )
{
if ( *(_DWORD *)(a1 + 248) != 2 || *(_DWORD *)(a1 + 24 * (*(_DWORD *)(a1 + 420) != -1) + 504) == 2 )
v73 = *(unsigned __int8 *)(a1 + 554);
else
v73 = *(unsigned __int8 *)(a1 + 586);
if ( v73 )
SSL_ctrl(v72, 65, 1, 0);
SSL_set_connect_state();
*(_DWORD *)(a1 + 24 * a2 + 472) = 0;
if ( !inet_pton(2, cp, buf)
&& !inet_pton(10, cp, buf)
&& !SSL_ctrl(*(_DWORD *)(a1 + 24 * a2 + 468), 55, 0, cp) )
{
sub_61807C(v4, "WARNING: failed to configure server name indication (SNI) TLS extension\n");
}
if ( *(_BYTE *)(v4 + 828) )
{
v117 = 0;
sub_64558C(a1);
if ( !sub_6455B8(a1, &v117, 0, a2) )
{
if ( !SSL_set_session(*(_DWORD *)(a1 + 24 * a2 + 468), v117) )
{
v90 = sub_6455A4(a1);
v91 = ERR_get_error(v90);
v92 = (const char *)ERR_error_string(v91, 0);
sub_6180F8(v4, "SSL: SSL_set_session failed: %s", v92);
return 35;
}
sub_61807C(v4, "SSL re-using session ID\n");
}
sub_6455A4(a1);
}
v74 = a1 + 24 * a2;
if ( *(_BYTE *)(v74 + 500) )
{
v75 = BIO_f_ssl();
v76 = BIO_new(v75);
BIO_ctrl(v76, 109, 0, *(_DWORD *)(v74 + 516));
SSL_set_bio(*(_DWORD *)(v74 + 468), v76, v76);
LABEL_191:
*(_DWORD *)(a1 + 24 * a2 + 460) = 1;
return 0;
}
if ( SSL_set_fd(*(_DWORD *)(v74 + 468), v111) )
goto LABEL_191;
v88 = ERR_get_error(0);
v89 = (const char *)ERR_error_string(v88, 0);
sub_6180F8(v4, "SSL: SSL_set_fd failed: %s", v89);
result = 35;
}
else
{
sub_6180F8(v4, "SSL: couldn't create a context (handle)!");
result = 27;
}
}
break;
}
}
else
{
v41 = ERR_peek_error();
v42 = (const char *)ERR_error_string(v41, 0);
sub_6180F8(v4, "SSL: couldn't create a context: %s", v42);
result = 27;
}
break;
case 2:
sub_6180F8(v4, "OpenSSL was built without SSLv2 support");
return 4;
case 3:
sub_6180F8(v4, "OpenSSL was built without SSLv3 support");
return 4;
default:
sub_6180F8(v4, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
return 35;
}
}
return result;
}