Skip to content

Commit

Permalink
Revert "Fixed OpenSSL bindings to recognize LibreSSL (#5676)" (#6062)
Browse files Browse the repository at this point in the history
This reverts commit 72ce28f.
  • Loading branch information
RX14 committed May 5, 2018
1 parent 5e518f9 commit 6c3fc2b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 33 deletions.
3 changes: 1 addition & 2 deletions bin/ci
Expand Up @@ -84,7 +84,7 @@ prepare_build() {

on_linux docker pull "jhass/crystal-build-$ARCH"

on_osx brew install crystal-lang pkg-config
on_osx brew install crystal-lang

# Make sure binaries from llvm are available in PATH
on_osx brew install jq
Expand Down Expand Up @@ -123,7 +123,6 @@ with_build_env() {
on_osx sudo systemsetup -settimezone $TZ
on_osx PATH="/usr/local/opt/llvm/bin:\$PATH" \
CRYSTAL_CACHE_DIR="/tmp/crystal" \
PKG_CONFIG_PATH="$(brew --prefix)/opt/openssl/lib/pkgconfig:$PKG_CONFIG_PATH" \
/bin/sh -c "'$command'"

}
Expand Down
18 changes: 3 additions & 15 deletions src/openssl/lib_crypto.cr
@@ -1,23 +1,11 @@
{% begin %}
lib LibCrypto
# An extra zero is appended to the output of LIBRESSL_VERSION to make it 0 when LibreSSL does not exist on the system.
# Any comparisons to it should be affixed with an extra zero as well e.g. `(LIBRESSL_VERSION_NUMBER >= 0x2050500F0)`.
LIBRESSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER\" | " +
(env("CC") || "cc") + " " + `pkg-config --cflags --silence-errors libssl || true`.chomp.stringify + " -E - 2>&1 > /dev/null || echo ''").chomp.split('\n').last.split('L').first.id + "0" }}
OPENSSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nOPENSSL_VERSION_NUMBER\" | " +
(env("CC") || "cc") + " " + `pkg-config --cflags --silence-errors libssl || true`.chomp.stringify + " -E - 2>&1 > /dev/null || echo ''").chomp.split('\n').last.split('L').first.id + "0" }}
OPENSSL_110 = {{ `command -v pkg-config > /dev/null && pkg-config --atleast-version=1.1.0 libcrypto || printf %s false`.stringify != "false" }}
OPENSSL_102 = {{ `command -v pkg-config > /dev/null && pkg-config --atleast-version=1.0.2 libcrypto || printf %s false`.stringify != "false" }}
end
{% end %}

{% begin %}
lib LibCrypto
OPENSSL_110 = {{ (LibCrypto::LIBRESSL_VERSION == 0) && (LibCrypto::OPENSSL_VERSION >= 0x10100000) }}
OPENSSL_102 = {{ (LibCrypto::LIBRESSL_VERSION == 0) && (LibCrypto::OPENSSL_VERSION >= 0x10002000) }}
LIBRESSL_250 = {{ LibCrypto::LIBRESSL_VERSION >= 0x205000000 }}
end
{% end %}

@[Link(ldflags: "`command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s ' -lcrypto'`")]
@[Link(ldflags: "`command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'`")]
lib LibCrypto
alias Char = LibC::Char
alias Int = LibC::Int
Expand Down
15 changes: 5 additions & 10 deletions src/openssl/lib_ssl.cr
Expand Up @@ -2,9 +2,8 @@ require "./lib_crypto"

{% begin %}
lib LibSSL
OPENSSL_110 = {{ LibCrypto::OPENSSL_110 }}
OPENSSL_102 = {{ LibCrypto::OPENSSL_102 }}
LIBRESSL_250 = {{ LibCrypto::LIBRESSL_250 }}
OPENSSL_110 = {{ `command -v pkg-config > /dev/null && pkg-config --atleast-version=1.1.0 libssl || printf %s false`.stringify != "false" }}
OPENSSL_102 = {{ `command -v pkg-config > /dev/null && pkg-config --atleast-version=1.0.2 libssl || printf %s false`.stringify != "false" }}
end
{% end %}

Expand Down Expand Up @@ -199,17 +198,13 @@ lib LibSSL
fun sslv23_method = SSLv23_method : SSLMethod
{% end %}

{% if OPENSSL_102 || LIBRESSL_250 %}
alias ALPNCallback = (SSL, Char**, Char*, Char*, Int, Void*) -> Int

fun ssl_get0_alpn_selected = SSL_get0_alpn_selected(handle : SSL, data : Char**, len : LibC::UInt*) : Void
fun ssl_ctx_set_alpn_select_cb = SSL_CTX_set_alpn_select_cb(ctx : SSLContext, cb : ALPNCallback, arg : Void*) : Void
{% end %}

{% if OPENSSL_102 %}
alias ALPNCallback = (SSL, Char**, Char*, Char*, Int, Void*) -> Int
alias X509VerifyParam = LibCrypto::X509VerifyParam

fun ssl_get0_param = SSL_get0_param(handle : SSL) : X509VerifyParam
fun ssl_get0_alpn_selected = SSL_get0_alpn_selected(handle : SSL, data : Char**, len : LibC::UInt*) : Void
fun ssl_ctx_set_alpn_select_cb = SSL_CTX_set_alpn_select_cb(ctx : SSLContext, cb : ALPNCallback, arg : Void*) : Void
fun ssl_ctx_get0_param = SSL_CTX_get0_param(ctx : SSLContext) : X509VerifyParam
fun ssl_ctx_set1_param = SSL_CTX_set1_param(ctx : SSLContext, param : X509VerifyParam) : Int
{% end %}
Expand Down
6 changes: 1 addition & 5 deletions src/openssl/ssl/context.cr
Expand Up @@ -305,7 +305,7 @@ abstract class OpenSSL::SSL::Context
LibSSL.ssl_ctx_set_verify(@handle, mode, nil)
end

{% if LibSSL::OPENSSL_102 || LibSSL::LIBRESSL_250 %}
{% if LibSSL::OPENSSL_102 %}

@alpn_protocol : Pointer(Void)?

Expand Down Expand Up @@ -338,10 +338,6 @@ abstract class OpenSSL::SSL::Context
LibSSL.ssl_ctx_set_alpn_select_cb(@handle, alpn_cb, alpn_protocol)
end

{% end %}

{% if LibSSL::OPENSSL_102 %}

# Set this context verify param to the default one of the given name.
#
# Depending on the OpenSSL version, the available defaults are
Expand Down
2 changes: 1 addition & 1 deletion src/openssl/ssl/socket.cr
Expand Up @@ -119,7 +119,7 @@ abstract class OpenSSL::SSL::Socket < IO
@bio.io.flush
end

{% if LibSSL::OPENSSL_102 || LibSSL::LIBRESSL_250 %}
{% if LibSSL::OPENSSL_102 %}
# Returns the negotiated ALPN protocol (eg: `"h2"`) of `nil` if no protocol was
# negotiated.
def alpn_protocol
Expand Down

0 comments on commit 6c3fc2b

Please sign in to comment.