Skip to content

Commit

Permalink
Merge pull request #111 from WebFreak001/fix-osx
Browse files Browse the repository at this point in the history
fix SSL on OSX 10.15
  • Loading branch information
ikod authored Nov 14, 2019
2 parents 2bbcffc + 2b2653f commit 5e7a994
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 19 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on: [push]

jobs:
test:
strategy:
matrix:
os: [macOS-latest]
dc: [dmd-latest, ldc-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1

- name: D Compiler Installation
uses: mihails-strasuns/[email protected]
with:
compiler: ${{ matrix.dc }}

- name: Test
run: dub test --config=std
58 changes: 39 additions & 19 deletions source/requests/ssl_adapter.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,45 +49,65 @@ immutable static OpenSSL openssl;

shared static this() {
version(OSX) {
openssl._libssl = cast(typeof(openssl._libssl))dlopen("libssl.dylib", RTLD_LAZY);
openssl._libcrypto = cast(typeof(openssl._libcrypto))dlopen("libcrypto.dylib", RTLD_LAZY);
enum loadFunction = "dlopen(lib.ptr, RTLD_LAZY)";
immutable string[] libsslname = [
"libssl.46.dylib",
"libssl.44.dylib",
"libssl.43.dylib",
"libssl.35.dylib",
"libssl.dylib",
];
immutable string[] libcryptoname = [
"libcrypto.44.dylib",
"libcrypto.42.dylib",
"libcrypto.41.dylib",
"libcrypto.35.dylib",
"libcrypto.dylib",
];
} else
version(linux) {
enum loadFunction = "dlopen(lib.ptr, RTLD_LAZY)";
immutable string[] libsslname = [
"libssl.so",
"libssl.so.1.1",
"libssl.so.1.0.2",
"libssl.so.1.0.1",
"libssl.so.1.0.0"
"libssl.so.1.0.0",
"libssl.so",
];
immutable string[] libcryptoname = [
"libcrypto.so.1.1",
"libcrypto.so.1.0.2",
"libcrypto.so.1.0.1",
"libcrypto.so.1.0.0",
"libcrypto.so",
];
} else
version(Windows) {
enum loadFunction = "LoadLibrary(lib.ptr)";
immutable wstring[] libsslname = ["libssl32.dll"w];
immutable wstring[] libcryptoname = ["libeay32.dll"w];
} else {
debug(requests) trace("error loading openssl: unsupported system - first access over https will fail");
return;
}

static if (is(typeof(loadFunction))) {
foreach(lib; libsslname) {
openssl._libssl = cast(typeof(openssl._libssl))dlopen(lib.ptr, RTLD_LAZY);
openssl._libssl = cast(typeof(openssl._libssl))mixin(loadFunction);
if ( openssl._libssl !is null ) {
debug(requests) tracef("will use %s".format(lib));
break;
}
}
immutable string[] libcryptoname = [
"libcrypto.so",
"libcrypto.so.1.1",
"libcrypto.so.1.0.2",
"libcrypto.so.1.0.1",
"libcrypto.so.1.0.0"
];
foreach(lib; libcryptoname) {
openssl._libcrypto = cast(typeof(openssl._libcrypto))dlopen(lib.ptr, RTLD_LAZY);
openssl._libcrypto = cast(typeof(openssl._libcrypto))mixin(loadFunction);
if ( openssl._libcrypto !is null ) {
debug(requests) tracef("will use %s".format(lib));
break;
}
}
} else
version(Windows) {
openssl._libssl = cast(typeof(openssl._libssl))LoadLibrary("libssl32.dll");
openssl._libcrypto = cast(typeof(openssl._libcrypto))LoadLibrary("libeay32.dll");
} else {
throw new Exception("loading openssl: unsupported system");
}

if ( openssl._libssl is null ) {
debug(requests) trace("warning: failed to load libssl - first access over https will fail");
return;
Expand Down
21 changes: 21 additions & 0 deletions tests/https.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module https;

import requests;
import std.experimental.logger;

version(vibeD) {
}
else {
unittest {
globalLogLevel(LogLevel.info);
auto rq = Request();
rq.keepAlive = false;
info("Testing https using google.com");
auto rs = rq.get("https://google.com");
assert(rs.responseBody.length > 0);
}
}

version(unittest_fakemain) {
void main () {}
}

0 comments on commit 5e7a994

Please sign in to comment.