Skip to content

Commit 90a21d9

Browse files
committed
openssl replace use of FILE*
Passing FILE* into libssl on windows does not work without applink compatibility hack. Replace with BIO usage, which moves fopen() into libssl.
1 parent fb915f9 commit 90a21d9

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/ossl.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,19 +387,18 @@ ossl_setup_common(const SSL_METHOD *method, bool ssl_client, const impl::ConfigC
387387
log_debug_printf(_setup, "Read keychain (PKCS12) %s%s\n",
388388
keychain.c_str(), password.empty() ? "" : " w/ password");
389389

390-
std::unique_ptr<FILE> fp(fopen(keychain.c_str(), "rb"));
391-
if(!fp) {
392-
auto err = errno;
393-
throw std::runtime_error(SB()<<"Unable to open \""<<keychain<<"\" : "<<strerror(err));
394-
}
395-
396390
ossl_ptr<PKCS12> p12;
397391
{
398-
if(!d2i_PKCS12_fp(fp.get(), p12.acquire()))
392+
ossl_ptr<BIO> fp(__FILE__, __LINE__, BIO_new(BIO_s_file()));
393+
394+
if(BIO_read_filename(fp.get(), keychain.c_str())<=0)
395+
throw SSLError(SB()<<"Unable to open and read \""<<keychain<<"\"");
396+
397+
if(!d2i_PKCS12_bio(fp.get(), p12.acquire()))
399398
throw SSLError(SB()<<"Unable to read \""<<keychain<<"\"");
400399

401400
if(!p12)
402-
throw std::logic_error("d2i_PKCS12_fp() success without success?!?");
401+
throw std::logic_error("d2i_PKCS12_bio() success without success?!?");
403402
}
404403

405404
ossl_ptr<EVP_PKEY> key;

test/gen_test_certs.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ struct PKCS12Writer {
241241
nullptr, nullptr,
242242
&jdk_trust, nullptr));
243243

244+
245+
owned_ptr<BIO> fp(BIO_new(BIO_s_file()));
246+
244247
std::string outpath(SB()<<outdir<<fname<<".p12");
245-
std::unique_ptr<FILE, ssl_delete<FILE>> out(fopen(outpath.c_str(), "wb"));
246-
if(!out) {
247-
auto err = errno;
248-
throw std::runtime_error(SB()<<"Error opening for write : "<<outpath<<" : "<<strerror(err));
249-
}
248+
if(BIO_write_filename(fp.get(), (void*)outpath.c_str())<=0)
249+
throw SSLError(SB()<<"BIO_write_filename() : "<<outpath);
250250

251-
MUST(1, i2d_PKCS12_fp(out.get(), p12.get()));
251+
MUST(1, i2d_PKCS12_bio(fp.get(), p12.get()));
252252
}
253253
};
254254

0 commit comments

Comments
 (0)