2012-11-26 19:58:52 -05:00
|
|
|
# -*- coding: us-ascii -*-
|
2020-02-16 01:21:29 -05:00
|
|
|
# frozen_string_literal: true
|
2003-07-23 12:12:24 -04:00
|
|
|
=begin
|
|
|
|
= Info
|
|
|
|
'OpenSSL for Ruby 2' project
|
|
|
|
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
= Licence
|
2015-04-19 23:55:09 -04:00
|
|
|
This program is licensed under the same licence as Ruby.
|
2003-07-23 12:12:24 -04:00
|
|
|
(See the file 'LICENCE'.)
|
|
|
|
=end
|
|
|
|
|
|
|
|
require "mkmf"
|
|
|
|
|
2003-07-23 22:10:04 -04:00
|
|
|
dir_config("openssl")
|
2003-07-27 08:19:18 -04:00
|
|
|
dir_config("kerberos")
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message "=== OpenSSL for Ruby configurator ===\n"
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
##
|
2011-10-26 19:43:04 -04:00
|
|
|
# Adds -DOSSL_DEBUG for compilation and some more targets when GCC is used
|
2003-07-23 12:12:24 -04:00
|
|
|
# To turn it on, use: --with-debug or --enable-debug
|
|
|
|
#
|
|
|
|
if with_config("debug") or enable_config("debug")
|
2016-05-25 04:50:03 -04:00
|
|
|
$defs.push("-DOSSL_DEBUG")
|
2011-10-26 19:43:04 -04:00
|
|
|
end
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message "=== Checking for system dependent stuff... ===\n"
|
2003-07-24 13:58:56 -04:00
|
|
|
have_library("nsl", "t_open")
|
|
|
|
have_library("socket", "socket")
|
2018-03-02 09:45:28 -05:00
|
|
|
if $mswin || $mingw
|
|
|
|
have_library("ws2_32")
|
|
|
|
end
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message "=== Checking for required stuff... ===\n"
|
2010-12-10 12:24:30 -05:00
|
|
|
result = pkg_config("openssl") && have_header("openssl/ssl.h")
|
2017-05-16 04:03:53 -04:00
|
|
|
|
2020-02-16 01:21:29 -05:00
|
|
|
if $mingw
|
|
|
|
append_cflags '-D_FORTIFY_SOURCE=2'
|
|
|
|
append_ldflags '-fstack-protector'
|
|
|
|
have_library 'ssp'
|
|
|
|
end
|
|
|
|
|
2017-05-16 04:03:53 -04:00
|
|
|
def find_openssl_library
|
2017-01-31 05:08:22 -05:00
|
|
|
if $mswin || $mingw
|
|
|
|
# required for static OpenSSL libraries
|
|
|
|
have_library("gdi32") # OpenSSL <= 1.0.2 (for RAND_screen())
|
|
|
|
have_library("crypt32")
|
|
|
|
end
|
|
|
|
|
2017-05-16 04:03:53 -04:00
|
|
|
return false unless have_header("openssl/ssl.h")
|
|
|
|
|
2017-06-14 05:49:09 -04:00
|
|
|
ret = have_library("crypto", "CRYPTO_malloc") &&
|
|
|
|
have_library("ssl", "SSL_new")
|
|
|
|
return ret if ret
|
2017-05-16 04:03:53 -04:00
|
|
|
|
2017-06-14 05:49:09 -04:00
|
|
|
if $mswin
|
|
|
|
# OpenSSL >= 1.1.0: libcrypto.lib and libssl.lib.
|
|
|
|
if have_library("libcrypto", "CRYPTO_malloc") &&
|
|
|
|
have_library("libssl", "SSL_new")
|
|
|
|
return true
|
2017-05-16 04:03:53 -04:00
|
|
|
end
|
2017-06-14 05:49:09 -04:00
|
|
|
|
|
|
|
# OpenSSL <= 1.0.2: libeay32.lib and ssleay32.lib.
|
|
|
|
if have_library("libeay32", "CRYPTO_malloc") &&
|
|
|
|
have_library("ssleay32", "SSL_new")
|
|
|
|
return true
|
2017-05-16 04:03:53 -04:00
|
|
|
end
|
|
|
|
|
2017-06-14 05:49:09 -04:00
|
|
|
# LibreSSL: libcrypto-##.lib and libssl-##.lib, where ## is the ABI version
|
|
|
|
# number. We have to find the version number out by scanning libpath.
|
|
|
|
libpath = $LIBPATH.dup
|
|
|
|
libpath |= ENV["LIB"].split(File::PATH_SEPARATOR)
|
|
|
|
libpath.map! { |d| d.tr(File::ALT_SEPARATOR, File::SEPARATOR) }
|
|
|
|
|
|
|
|
ret = [
|
|
|
|
["crypto", "CRYPTO_malloc"],
|
|
|
|
["ssl", "SSL_new"]
|
|
|
|
].all? do |base, func|
|
|
|
|
result = false
|
|
|
|
libs = ["lib#{base}-[0-9][0-9]", "lib#{base}-[0-9][0-9][0-9]"]
|
2017-05-16 04:03:53 -04:00
|
|
|
libs = Dir.glob(libs.map{|l| libpath.map{|d| File.join(d, l + ".*")}}.flatten).map{|path| File.basename(path, ".*")}.uniq
|
2017-06-14 05:49:09 -04:00
|
|
|
libs.each do |lib|
|
|
|
|
result = have_library(lib, func)
|
|
|
|
break if result
|
|
|
|
end
|
|
|
|
result
|
2017-05-16 04:03:53 -04:00
|
|
|
end
|
2017-06-14 05:49:09 -04:00
|
|
|
return ret if ret
|
2017-05-16 04:03:53 -04:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
unless result
|
|
|
|
unless find_openssl_library
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message "=== Checking for required stuff failed. ===\n"
|
|
|
|
Logging::message "Makefile wasn't created. Fix the errors above.\n"
|
2017-09-03 08:35:27 -04:00
|
|
|
raise "OpenSSL library could not be found. You might want to use " \
|
|
|
|
"--with-openssl-dir=<dir> option to specify the prefix where OpenSSL " \
|
|
|
|
"is installed."
|
2003-07-24 13:58:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
unless checking_for("OpenSSL version is 1.0.1 or later") {
|
|
|
|
try_static_assert("OPENSSL_VERSION_NUMBER >= 0x10001000L", "openssl/opensslv.h") }
|
|
|
|
raise "OpenSSL >= 1.0.1 or LibreSSL is required"
|
2012-04-22 08:39:55 -04:00
|
|
|
end
|
2004-01-19 12:55:18 -05:00
|
|
|
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message "=== Checking for OpenSSL features... ===\n"
|
2016-05-25 04:50:03 -04:00
|
|
|
# compile options
|
|
|
|
have_func("RAND_egd")
|
2020-03-09 05:26:19 -04:00
|
|
|
engines = %w{dynamic 4758cca aep atalla chil
|
|
|
|
cswift nuron sureware ubsec padlock capi gmp gost cryptodev}
|
2016-05-25 04:50:03 -04:00
|
|
|
engines.each { |name|
|
2020-03-09 05:26:19 -04:00
|
|
|
have_func("ENGINE_load_#{name}()", "openssl/engine.h")
|
2016-05-25 04:50:03 -04:00
|
|
|
}
|
|
|
|
|
2018-08-08 11:36:28 -04:00
|
|
|
if ($mswin || $mingw) && have_macro("LIBRESSL_VERSION_NUMBER", "openssl/opensslv.h")
|
2018-07-29 04:13:05 -04:00
|
|
|
$defs.push("-DNOCRYPT")
|
|
|
|
end
|
|
|
|
|
2016-05-25 04:50:03 -04:00
|
|
|
# added in 1.0.2
|
2016-05-30 05:30:38 -04:00
|
|
|
have_func("EC_curve_nist2nid")
|
2016-05-25 04:50:03 -04:00
|
|
|
have_func("X509_REVOKED_dup")
|
2016-06-05 11:35:12 -04:00
|
|
|
have_func("X509_STORE_CTX_get0_store")
|
2016-05-25 04:50:03 -04:00
|
|
|
have_func("SSL_CTX_set_alpn_select_cb")
|
2020-03-09 05:26:19 -04:00
|
|
|
have_func("SSL_CTX_set1_curves_list(NULL, NULL)", "openssl/ssl.h")
|
|
|
|
have_func("SSL_CTX_set_ecdh_auto(NULL, 0)", "openssl/ssl.h")
|
|
|
|
have_func("SSL_get_server_tmp_key(NULL, NULL)", "openssl/ssl.h")
|
2016-06-05 12:36:39 -04:00
|
|
|
have_func("SSL_is_server")
|
2016-05-25 04:50:03 -04:00
|
|
|
|
|
|
|
# added in 1.1.0
|
2018-05-12 03:33:53 -04:00
|
|
|
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") ||
|
|
|
|
try_static_assert("LIBRESSL_VERSION_NUMBER >= 0x2070000fL", "openssl/opensslv.h")
|
|
|
|
$defs.push("-DHAVE_OPAQUE_OPENSSL")
|
|
|
|
end
|
2016-06-05 08:46:05 -04:00
|
|
|
have_func("CRYPTO_lock") || $defs.push("-DHAVE_OPENSSL_110_THREADING_API")
|
2016-06-05 11:35:12 -04:00
|
|
|
have_func("BN_GENCB_new")
|
|
|
|
have_func("BN_GENCB_free")
|
|
|
|
have_func("BN_GENCB_get_arg")
|
|
|
|
have_func("EVP_MD_CTX_new")
|
|
|
|
have_func("EVP_MD_CTX_free")
|
|
|
|
have_func("HMAC_CTX_new")
|
|
|
|
have_func("HMAC_CTX_free")
|
2016-05-25 04:50:03 -04:00
|
|
|
have_func("X509_STORE_get_ex_data")
|
|
|
|
have_func("X509_STORE_set_ex_data")
|
2020-02-16 01:21:29 -05:00
|
|
|
have_func("X509_STORE_get_ex_new_index")
|
2016-06-05 11:35:12 -04:00
|
|
|
have_func("X509_CRL_get0_signature")
|
|
|
|
have_func("X509_REQ_get0_signature")
|
|
|
|
have_func("X509_REVOKED_get0_serialNumber")
|
|
|
|
have_func("X509_REVOKED_get0_revocationDate")
|
|
|
|
have_func("X509_get0_tbs_sigalg")
|
|
|
|
have_func("X509_STORE_CTX_get0_untrusted")
|
|
|
|
have_func("X509_STORE_CTX_get0_cert")
|
|
|
|
have_func("X509_STORE_CTX_get0_chain")
|
|
|
|
have_func("OCSP_SINGLERESP_get0_id")
|
|
|
|
have_func("SSL_CTX_get_ciphers")
|
2016-06-05 08:46:05 -04:00
|
|
|
have_func("X509_up_ref")
|
|
|
|
have_func("X509_CRL_up_ref")
|
|
|
|
have_func("X509_STORE_up_ref")
|
|
|
|
have_func("SSL_SESSION_up_ref")
|
|
|
|
have_func("EVP_PKEY_up_ref")
|
2020-03-09 05:26:19 -04:00
|
|
|
have_func("SSL_CTX_set_tmp_ecdh_callback(NULL, NULL)", "openssl/ssl.h") # removed
|
|
|
|
have_func("SSL_CTX_set_min_proto_version(NULL, 0)", "openssl/ssl.h")
|
2016-06-07 03:52:24 -04:00
|
|
|
have_func("SSL_CTX_get_security_level")
|
2016-08-29 01:47:09 -04:00
|
|
|
have_func("X509_get0_notBefore")
|
2016-12-21 20:43:41 -05:00
|
|
|
have_func("SSL_SESSION_get_protocol_version")
|
2020-02-16 01:21:29 -05:00
|
|
|
have_func("TS_STATUS_INFO_get0_status")
|
|
|
|
have_func("TS_STATUS_INFO_get0_text")
|
|
|
|
have_func("TS_STATUS_INFO_get0_failure_info")
|
|
|
|
have_func("TS_VERIFY_CTS_set_certs")
|
|
|
|
have_func("TS_VERIFY_CTX_set_store")
|
|
|
|
have_func("TS_VERIFY_CTX_add_flags")
|
|
|
|
have_func("TS_RESP_CTX_set_time_cb")
|
2017-09-03 08:35:27 -04:00
|
|
|
have_func("EVP_PBE_scrypt")
|
2020-02-16 01:21:29 -05:00
|
|
|
have_func("SSL_CTX_set_post_handshake_auth")
|
2016-05-25 04:50:03 -04:00
|
|
|
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message "=== Checking done. ===\n"
|
2006-06-02 06:03:16 -04:00
|
|
|
|
|
|
|
create_header
|
2016-09-07 21:09:19 -04:00
|
|
|
create_makefile("openssl")
|
2012-05-18 15:51:58 -04:00
|
|
|
Logging::message "Done.\n"
|