Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Aug 15, 2024
1 parent 5f39e78 commit 69cf374
Showing 1 changed file with 56 additions and 20 deletions.
76 changes: 56 additions & 20 deletions source/unix/openssl_platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,34 +493,70 @@ static enum aws_libcrypto_version s_resolve_libcrypto_symbols(enum aws_libcrypto
return found_version;
}

static enum aws_libcrypto_version s_resolve_libcrypto_lib(void) {
const char *libcrypto_102 = "libcrypto.so.1.0.0";
const char *libcrypto_111 = "libcrypto.so.1.1";
static enum aws_libcrypto_version s_resolve_libcrypto_compile_version(){
// TODO: only assert on major and minor?
if(strcmp(OPENSSL_VERSION_STR, "1.1.1") == 0) {
return AWS_LIBCRYPTO_1_1_1;
}
if(strcmp(OPENSSL_VERSION_STR, "1.0.2") == 0) {
return AWS_LIBCRYPTO_1_0_2;
}
// TODO: FatalAssert?
return AWS_LIBCRYPTO_NONE;
}

AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "loading libcrypto 1.0.2");
void *module = dlopen(libcrypto_102, RTLD_NOW);
if (module) {
AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "resolving against libcrypto 1.0.2");
enum aws_libcrypto_version result = s_resolve_libcrypto_symbols(AWS_LIBCRYPTO_1_0_2, module);
if (result == AWS_LIBCRYPTO_1_0_2) {
return result;
}
dlclose(module);
} else {
AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "libcrypto 1.0.2 not found");
static char *s_resolve_libcrypto_path_from_enum(enum aws_libcrypto_version version) {
switch(version) {
case AWS_LIBCRYPTO_1_0_2:
return "libcrypto.so.1.0.0";
case AWS_LIBCRYPTO_1_1_1:
return "libcrypto.so.1.1";
case default:
return "libcrypto.so";
}
}

static enum aws_libcrypto_version s_resolve_libcrypto_lib_impl(enum aws_libcrypto_version version) {
const char *libcrypto_version = s_resolve_libcrypto_path_from_enum(version);

AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "loading libcrypto 1.1.1");
module = dlopen(libcrypto_111, RTLD_NOW);
AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "loading %s",libcrypto_version);
void *module = dlopen(libcrypto_version, RTLD_NOW);
if (module) {
AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "resolving against libcrypto 1.1.1");
enum aws_libcrypto_version result = s_resolve_libcrypto_symbols(AWS_LIBCRYPTO_1_1_1, module);
if (result == AWS_LIBCRYPTO_1_1_1) {
AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "resolving against %s", libcrypto_version);
enum aws_libcrypto_version result = s_resolve_libcrypto_symbols(version, module);
if (result == version) {
return result;
}
dlclose(module);
} else {
AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "libcrypto 1.1.1 not found");
AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "%s not found", libcrypto_version);
}

return AWS_LIBCRYPTO_NONE;
}

static enum aws_libcrypto_version s_resolve_libcrypto_lib(void) {

const enum aws_libcrypto_version compiled_version = s_resolve_libcrypto_compile_version();
if(compiled_version != AWS_LIBCRYPTO_NONE) {
enum aws_libcrypto_version result = s_resolve_libcrypto_lib_impl(compiled_version);
if(result == compiled_version) {
return result;
}
}

if(compiled_version != AWS_LIBCRYPTO_1_0_2) {
enum aws_libcrypto_version result = s_resolve_libcrypto_lib_impl(AWS_LIBCRYPTO_1_0_2);
if(result == AWS_LIBCRYPTO_1_0_2) {
return result;
}
}

if(compiled_version != AWS_LIBCRYPTO_1_1_1) {
enum aws_libcrypto_version result = s_resolve_libcrypto_lib_impl(AWS_LIBCRYPTO_1_1_1);
if(result == AWS_LIBCRYPTO_1_1_1) {
return result;
}
}

AWS_LOGF_DEBUG(AWS_LS_CAL_LIBCRYPTO_RESOLVE, "loading libcrypto.so");
Expand Down

0 comments on commit 69cf374

Please sign in to comment.