Skip to content

Commit

Permalink
fix D build, with D lang openssl 2.0.3
Browse files Browse the repository at this point in the history
Client: d
Patch: mingwugmail <mingwu@gmail.com>

This closes #2397
  • Loading branch information
mw66 authored and Jens-G committed May 27, 2021
1 parent 9a4802a commit 4abc5cf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
25 changes: 21 additions & 4 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@
"dependencies": {
"libevent": {
"version": "~>2.0.2"
},
"openssl": {
"version": ">=1.1.6"
}
},
"systemDependencies": "On systems with native openssl 1.0.x use dub package openssl~>1.1, on systems with native openssl 1.1.x use dub package openssl~>2.0",
"systemDependencies": "On systems with native openssl 1.0.x use dub package openssl~>1.1, on systems with native openssl 1.1.x use dub package openssl~>2.0.3 (with build bug fix: https://github.com/D-Programming-Deimos/openssl/issues/63)",
"configurations": [
{
"name": "use_openssl_1_0",
"versions": ["use_openssl_1_0_x"],
"dependencies": {
"openssl": {
"version": "~>1.1.6"
}
}
},
{
"name": "use_openssl_1_1",
"versions": ["use_openssl_1_1_x"],
"dependencies": {
"openssl": {
"version": "~>2.0.3"
}
}
}
],
"targetType": "library",
"sourcePaths": [
"lib/d/src"
Expand Down
4 changes: 2 additions & 2 deletions lib/d/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ d_main_modules = $(filter-out $(d_libevent_dependent_modules) \
$(d_openssl_dependent_modules),$(d_modules))


d_lib_flags = -w -wi -Isrc -lib
d_lib_flags = -w -wi -Isrc -lib -version=use_openssl_1_0_x
all_targets =

#
Expand Down Expand Up @@ -153,7 +153,7 @@ clean-local:
#
# Unit tests (built both in debug and release mode).
#
d_test_flags = -unittest -w -wi -I$(top_srcdir)/lib/d/src
d_test_flags = -unittest -w -wi -I$(top_srcdir)/lib/d/src -version=use_openssl_1_0_x

# There just must be some way to reassign a variable without warnings in
# Automake...
Expand Down
19 changes: 17 additions & 2 deletions lib/d/src/thrift/internal/ssl.d
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ void authorize(SSL* ssl, TAccessManager accessManager,
// Check subjectAltName(s), if present.
auto alternatives = cast(STACK_OF!(GENERAL_NAME)*)
X509_get_ext_d2i(cert, NID_subject_alt_name, null, null);

version(use_openssl_1_0_x) {
enum _GEN_DNS = GENERAL_NAME.GEN_DNS;
enum _GEN_IPADD = GENERAL_NAME.GEN_IPADD;
} else version(use_openssl_1_1_x) {
enum _GEN_DNS = GEN_DNS;
enum _GEN_IPADD = GEN_IPADD;
} else {
static assert(false, `Must have version either use_openssl_1_0_x or use_openssl_1_1_x defined, e.g.
"subConfigurations": {
"apache-thrift": "use_openssl_1_0"
}`);
}

if (alternatives != null) {
auto count = sk_GENERAL_NAME_num(alternatives);
for (int i = 0; decision == Decision.SKIP && i < count; i++) {
Expand All @@ -98,11 +112,12 @@ void authorize(SSL* ssl, TAccessManager accessManager,
}
auto data = ASN1_STRING_data(name.d.ia5);
auto length = ASN1_STRING_length(name.d.ia5);

switch (name.type) {
case GENERAL_NAME.GEN_DNS:
case _GEN_DNS:
decision = accessManager.verify(hostName, cast(char[])data[0 .. length]);
break;
case GENERAL_NAME.GEN_IPADD:
case _GEN_IPADD:
decision = accessManager.verify(peerAddress, data[0 .. length]);
break;
default:
Expand Down

0 comments on commit 4abc5cf

Please sign in to comment.