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
|
|
|
|
2021-06-18 21:47:16 -04:00
|
|
|
have_func("rb_io_maybe_wait") # Ruby 3.1
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2020-08-04 10:14:44 -04:00
|
|
|
Logging::message "=== Checking for required stuff... ===\n"
|
|
|
|
pkg_config_found = pkg_config("openssl") && have_header("openssl/ssl.h")
|
|
|
|
|
|
|
|
if !pkg_config_found && !find_openssl_library
|
|
|
|
Logging::message "=== Checking for required stuff failed. ===\n"
|
|
|
|
Logging::message "Makefile wasn't created. Fix the errors above.\n"
|
|
|
|
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."
|
|
|
|
end
|
|
|
|
|
|
|
|
version_ok = if have_macro("LIBRESSL_VERSION_NUMBER", "openssl/opensslv.h")
|
|
|
|
is_libressl = true
|
|
|
|
checking_for("LibreSSL version >= 3.1.0") {
|
|
|
|
try_static_assert("LIBRESSL_VERSION_NUMBER >= 0x30100000L", "openssl/opensslv.h") }
|
|
|
|
else
|
|
|
|
checking_for("OpenSSL version >= 1.0.2") {
|
|
|
|
try_static_assert("OPENSSL_VERSION_NUMBER >= 0x10002000L", "openssl/opensslv.h") }
|
|
|
|
end
|
|
|
|
unless version_ok
|
|
|
|
raise "OpenSSL >= 1.0.2 or LibreSSL >= 3.1.0 is required"
|
2003-07-24 13:58:56 -04:00
|
|
|
end
|
|
|
|
|
2020-08-04 10:14:44 -04:00
|
|
|
# Prevent wincrypt.h from being included, which defines conflicting macro with openssl/x509.h
|
|
|
|
if is_libressl && ($mswin || $mingw)
|
|
|
|
$defs.push("-DNOCRYPT")
|
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
|
|
|
}
|
|
|
|
|
|
|
|
# added in 1.1.0
|
2020-08-04 10:14:44 -04:00
|
|
|
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") || is_libressl
|
2018-05-12 03:33:53 -04:00
|
|
|
$defs.push("-DHAVE_OPAQUE_OPENSSL")
|
|
|
|
end
|
2016-06-05 11:35:12 -04:00
|
|
|
have_func("EVP_MD_CTX_new")
|
|
|
|
have_func("EVP_MD_CTX_free")
|
2020-05-18 03:15:07 -04:00
|
|
|
have_func("EVP_MD_CTX_pkey_ctx")
|
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_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
|
|
|
|
2020-07-10 01:34:51 -04:00
|
|
|
# added in 1.1.1
|
|
|
|
have_func("EVP_PKEY_check")
|
|
|
|
|
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"
|