-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenSSL 3.x: fixes to support Conan 2.0 #16658
Merged
conan-center-bot
merged 18 commits into
conan-io:master
from
jcar87:lcc/maintenance/openssl3c2
Mar 23, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
514cbd9
openssl3: add a layout
jcar87 d32758c
openssl3: remove obsolete recipe methods
jcar87 24bcdd5
openssl3: use rm_safe instead of deletions
jcar87 ae2a5c4
openssl3: remove exporting non-existant patches
jcar87 e75a923
openssl: generate target file during generate() method, wip
jcar87 3efb56b
openssl3: more changes
jcar87 561807e
openssl3: windows fixes
jcar87 0eca3cf
openssl3: add CMake variables to match CMake's find module
jcar87 039aea3
openssl3: test package, WIP
jcar87 c06e115
openssl3: windows fixes
jcar87 85aad18
openssl3: fix apple install names and add new version
jcar87 9942daf
openssl3: remove unused function
jcar87 c57e455
openssl3: remove unused method
jcar87 15cb5da
openssl3: remove dead code
jcar87 b01705c
openssl3: fixes
jcar87 ae83eeb
fix typo
jcar87 641375d
fix indentation
jcar87 684931a
openssl3: unify test package in a single executable
jcar87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package C) | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package LANGUAGES C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
option(OPENSSL_WITH_ZLIB "OpenSSL with zlib support" ON) | ||
option(OPENSSL_WITH_LEGACY "OpenSSL with support for the legacy provider" ON) | ||
option(OPENSSL_WITH_MD4 "OpenSSL with MD4 support (needs legacy provider)" ON) | ||
option(OPENSSL_WITH_RIPEMD160 "OpenSSL with RIPEMD16 support (needs legacy provider)" ON) | ||
|
||
set(OpenSSL_DEBUG 1) | ||
find_package(OpenSSL REQUIRED) | ||
|
||
message("OPENSSL_FOUND: ${OPENSSL_FOUND}") | ||
message("OPENSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}") | ||
message("OPENSSL_CRYPTO_LIBRARY: ${OPENSSL_CRYPTO_LIBRARY}") | ||
message("OPENSSL_CRYPTO_LIBRARIES: ${OPENSSL_CRYPTO_LIBRARIES}") | ||
message("OPENSSL_SSL_LIBRARY: ${OPENSSL_SSL_LIBRARY}") | ||
message("OPENSSL_SSL_LIBRARIES: ${OPENSSL_SSL_LIBRARIES}") | ||
message("OPENSSL_LIBRARIES: ${OPENSSL_LIBRARIES}") | ||
message("OPENSSL_VERSION: ${OPENSSL_VERSION}") | ||
# Test whether variables from https://cmake.org/cmake/help/latest/module/FindOpenSSL.html | ||
# are properly defined in conan generators | ||
set(_custom_vars | ||
OPENSSL_FOUND | ||
OPENSSL_INCLUDE_DIR | ||
OPENSSL_CRYPTO_LIBRARY | ||
OPENSSL_CRYPTO_LIBRARIES | ||
OPENSSL_SSL_LIBRARY | ||
OPENSSL_SSL_LIBRARIES | ||
OPENSSL_LIBRARIES | ||
OPENSSL_VERSION | ||
) | ||
foreach(_custom_var ${_custom_vars}) | ||
if(DEFINED ${_custom_var}) | ||
message(STATUS "${_custom_var}: ${${_custom_var}}") | ||
else() | ||
message(FATAL_ERROR "${_custom_var} not defined") | ||
endif() | ||
endforeach() | ||
|
||
add_executable(digest digest.c) | ||
if(OPENSSL_WITH_ZLIB) | ||
target_compile_definitions(digest PRIVATE WITH_ZLIB) | ||
endif() | ||
target_link_libraries(digest OpenSSL::Crypto) | ||
add_executable(test_package test_package.c digest.c) | ||
target_link_libraries(test_package PRIVATE OpenSSL::SSL OpenSSL::Crypto) | ||
|
||
if(OPENSSL_WITH_LEGACY) | ||
add_executable(digest_legacy digest_legacy.c) | ||
target_sources(test_package PRIVATE digest_legacy.c) | ||
# do now show deperecation warnings | ||
target_compile_definitions(digest_legacy PRIVATE OPENSSL_SUPPRESS_DEPRECATED) | ||
target_compile_definitions(test_package PRIVATE OPENSSL_SUPPRESS_DEPRECATED TEST_OPENSSL_LEGACY) | ||
if(OPENSSL_WITH_MD4) | ||
target_compile_definitions(digest_legacy PRIVATE OPENSSL_WITH_MD4) | ||
target_compile_definitions(test_package PRIVATE OPENSSL_WITH_MD4) | ||
endif() | ||
if(OPENSSL_WITH_RIPEMD160) | ||
target_compile_definitions(digest_legacy PRIVATE OPENSSL_WITH_RIPEMD160) | ||
endif() | ||
if(OPENSSL_WITH_ZLIB) | ||
target_compile_definitions(digest_legacy PRIVATE WITH_ZLIB) | ||
target_compile_definitions(test_package PRIVATE OPENSSL_WITH_RIPEMD160) | ||
endif() | ||
target_link_libraries(digest_legacy OpenSSL::Crypto) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
from conans import CMake, tools, ConanFile | ||
from conan.tools.build import cross_building | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "arch", "build_type" | ||
generators = "cmake", "cmake_find_package", "pkg_config" | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def _with_legacy(self): | ||
return (not self.options["openssl"].no_legacy and | ||
((not self.options["openssl"].no_md4) or | ||
(not self.options["openssl"].no_rmd160))) | ||
return (not self.dependencies["openssl"].options.no_legacy and | ||
((not self.dependencies["openssl"].options.no_md4) or | ||
(not self.dependencies["openssl"].options.no_rmd160))) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.cache_variables["OPENSSL_WITH_LEGACY"] = self._with_legacy() | ||
tc.cache_variables["OPENSSL_WITH_MD4"] = not self.dependencies["openssl"].options.no_md4 | ||
tc.cache_variables["OPENSSL_WITH_RIPEMD160"] = not self.dependencies["openssl"].options.no_rmd160 | ||
tc.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.definitions["OPENSSL_WITH_ZLIB"] = not self.options["openssl"].no_zlib | ||
cmake.definitions["OPENSSL_WITH_LEGACY"] = self._with_legacy() | ||
cmake.definitions["OPENSSL_WITH_MD4"] = not self.options["openssl"].no_md4 | ||
cmake.definitions["OPENSSL_WITH_RIPEMD160"] = not self.options["openssl"].no_rmd160 | ||
if self.settings.os == "Android": | ||
cmake.definitions["CONAN_LIBCXX"] = "" | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not cross_building(self): | ||
bin_path = os.path.join("bin", "digest") | ||
self.run(bin_path, run_environment=True) | ||
|
||
if not self.options["openssl"].no_legacy: | ||
bin_legacy_path = os.path.join("bin", "digest_legacy") | ||
self.run(bin_legacy_path, run_environment=True) | ||
|
||
if not self.options["openssl"].no_stdio: | ||
self.run("openssl version", run_environment=True) | ||
assert os.path.exists(os.path.join(self.deps_cpp_info["openssl"].rootpath, "licenses", "LICENSE.txt")) | ||
|
||
for fn in ("libcrypto.pc", "libssl.pc", "openssl.pc",): | ||
assert os.path.isfile(os.path.join(self.build_folder, fn)) | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdio.h> | ||
#include <openssl/ssl.h> | ||
|
||
void digest(); | ||
int digest_legacy(); | ||
|
||
int main() | ||
{ | ||
int legacy_result = 0; | ||
OPENSSL_init_ssl(0, NULL); | ||
printf("OpenSSL version: %s\n", OpenSSL_version(OPENSSL_VERSION)); | ||
|
||
digest(); | ||
|
||
#if defined(TEST_OPENSSL_LEGACY) | ||
legacy_result = digest_legacy(); | ||
if (legacy_result != 0) { | ||
printf("Error testing the digest_legacy() function\n"); | ||
return 1; | ||
} | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
option(OPENSSL_WITH_ZLIB "OpenSSL with zlib support" ON) | ||
option(OPENSSL_WITH_LEGACY "OpenSSL with support for the legacy provider" ON) | ||
option(OPENSSL_WITH_MD4 "OpenSSL with MD4 support (needs legacy provider)" ON) | ||
option(OPENSSL_WITH_RIPEMD160 "OpenSSL with RIPEMD16 support (needs legacy provider)" ON) | ||
|
||
set(OpenSSL_DEBUG 1) | ||
find_package(OpenSSL REQUIRED) | ||
|
||
message("OPENSSL_FOUND: ${OPENSSL_FOUND}") | ||
message("OPENSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}") | ||
message("OPENSSL_CRYPTO_LIBRARY: ${OPENSSL_CRYPTO_LIBRARY}") | ||
message("OPENSSL_CRYPTO_LIBRARIES: ${OPENSSL_CRYPTO_LIBRARIES}") | ||
message("OPENSSL_SSL_LIBRARY: ${OPENSSL_SSL_LIBRARY}") | ||
message("OPENSSL_SSL_LIBRARIES: ${OPENSSL_SSL_LIBRARIES}") | ||
message("OPENSSL_LIBRARIES: ${OPENSSL_LIBRARIES}") | ||
message("OPENSSL_VERSION: ${OPENSSL_VERSION}") | ||
|
||
add_executable(digest digest.c) | ||
if(OPENSSL_WITH_ZLIB) | ||
target_compile_definitions(digest PRIVATE WITH_ZLIB) | ||
endif() | ||
target_link_libraries(digest OpenSSL::Crypto) | ||
|
||
if(OPENSSL_WITH_LEGACY) | ||
add_executable(digest_legacy digest_legacy.c) | ||
# do now show deperecation warnings | ||
target_compile_definitions(digest_legacy PRIVATE OPENSSL_SUPPRESS_DEPRECATED) | ||
if(OPENSSL_WITH_MD4) | ||
target_compile_definitions(digest_legacy PRIVATE OPENSSL_WITH_MD4) | ||
endif() | ||
if(OPENSSL_WITH_RIPEMD160) | ||
target_compile_definitions(digest_legacy PRIVATE OPENSSL_WITH_RIPEMD160) | ||
endif() | ||
if(OPENSSL_WITH_ZLIB) | ||
target_compile_definitions(digest_legacy PRIVATE WITH_ZLIB) | ||
endif() | ||
target_link_libraries(digest_legacy OpenSSL::Crypto) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from conans import CMake, tools, ConanFile | ||
from conan.tools.build import cross_building | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "arch", "build_type" | ||
generators = "cmake", "cmake_find_package", "pkg_config" | ||
|
||
def _with_legacy(self): | ||
return (not self.options["openssl"].no_legacy and | ||
((not self.options["openssl"].no_md4) or | ||
(not self.options["openssl"].no_rmd160))) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.definitions["OPENSSL_WITH_ZLIB"] = not self.options["openssl"].no_zlib | ||
cmake.definitions["OPENSSL_WITH_LEGACY"] = self._with_legacy() | ||
cmake.definitions["OPENSSL_WITH_MD4"] = not self.options["openssl"].no_md4 | ||
cmake.definitions["OPENSSL_WITH_RIPEMD160"] = not self.options["openssl"].no_rmd160 | ||
if self.settings.os == "Android": | ||
cmake.definitions["CONAN_LIBCXX"] = "" | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not cross_building(self): | ||
bin_path = os.path.join("bin", "digest") | ||
self.run(bin_path, run_environment=True) | ||
|
||
if not self.options["openssl"].no_legacy: | ||
bin_legacy_path = os.path.join("bin", "digest_legacy") | ||
self.run(bin_legacy_path, run_environment=True) | ||
|
||
if not self.options["openssl"].no_stdio: | ||
self.run("openssl version", run_environment=True) | ||
assert os.path.exists(os.path.join(self.deps_cpp_info["openssl"].rootpath, "licenses", "LICENSE.txt")) | ||
|
||
for fn in ("libcrypto.pc", "libssl.pc", "openssl.pc",): | ||
assert os.path.isfile(os.path.join(self.build_folder, fn)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <openssl/evp.h> | ||
#include <openssl/sha.h> | ||
#include <openssl/crypto.h> | ||
#include <openssl/ssl.h> | ||
#if defined(WITH_ZLIB) | ||
#include <zlib.h> | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#if defined(_MSC_VER) && _MSC_VER < 1900 | ||
#define snprintf _snprintf | ||
#endif | ||
|
||
void SHA3_hash(const EVP_MD *type, const unsigned char *message, size_t message_len, unsigned char *digest, unsigned int *digest_len) { | ||
EVP_MD_CTX *mdctx; | ||
|
||
if((mdctx = EVP_MD_CTX_create()) == NULL) | ||
printf("EVP_MD_CTX_create error!\n"); | ||
|
||
if(EVP_DigestInit_ex(mdctx, type, NULL) != 1) | ||
printf("EVP_DigestInit_ex error!\n"); | ||
|
||
if(EVP_DigestUpdate(mdctx, message, message_len) != 1) | ||
printf("EVP_DigestUpdate error!\n"); | ||
|
||
if(EVP_DigestFinal_ex(mdctx, digest, digest_len) != 1) | ||
printf("EVP_DigestFinal_ex error!\n"); | ||
|
||
EVP_MD_CTX_destroy(mdctx); | ||
} | ||
|
||
int main() | ||
{ | ||
unsigned int digest_len; | ||
unsigned char sha256_digest[SHA256_DIGEST_LENGTH], | ||
sha512_digest[SHA512_DIGEST_LENGTH], | ||
sha3_256_digest[SHA256_DIGEST_LENGTH], | ||
sha3_512_digest[SHA512_DIGEST_LENGTH]; | ||
char sha256_string[SHA256_DIGEST_LENGTH*2+1] = {0}, | ||
sha512_string[SHA512_DIGEST_LENGTH*2+1] = {0}, | ||
sha3_256_string[SHA256_DIGEST_LENGTH*2+1] = {0}, | ||
sha3_512_string[SHA512_DIGEST_LENGTH*2+1] = {0}; | ||
char string[] = "happy"; | ||
|
||
SHA256((unsigned char*)&string, strlen(string), (unsigned char*)&sha256_digest); | ||
SHA512((unsigned char*)&string, strlen(string), (unsigned char*)&sha512_digest); | ||
SHA3_hash(EVP_sha3_256(), (unsigned char*)&string, strlen(string), (unsigned char*)&sha3_256_digest, &digest_len); | ||
SHA3_hash(EVP_sha3_512(), (unsigned char*)&string, strlen(string), (unsigned char*)&sha3_512_digest, &digest_len); | ||
|
||
for(int i = 0; i < SHA256_DIGEST_LENGTH; i++) { | ||
snprintf(&sha256_string[i*2], sizeof(sha256_string)-i*2, "%02x", (unsigned int)sha256_digest[i]); | ||
snprintf(&sha3_256_string[i*2], sizeof(sha3_256_string)-i*2, "%02x", (unsigned int)sha3_256_digest[i]); | ||
} | ||
|
||
for(int i = 0; i < SHA512_DIGEST_LENGTH; i++) { | ||
snprintf(&sha512_string[i*2], sizeof(sha512_string)-i*2, "%02x", (unsigned int)sha512_digest[i]); | ||
snprintf(&sha3_512_string[i*2], sizeof(sha3_512_string)-i*2, "%02x", (unsigned int)sha3_512_digest[i]); | ||
} | ||
|
||
printf("sha256 digest: %s\n", sha256_string); | ||
printf("sha512 digest: %s\n", sha512_string); | ||
printf("sha3 256 digest: %s\n", sha3_256_string); | ||
printf("sha3 512 digest: %s\n", sha3_512_string); | ||
printf("OpenSSL version: %s\n", OpenSSL_version(OPENSSL_VERSION)); | ||
#if defined(WITH_ZLIB) | ||
printf("ZLIB version: %s\n", ZLIB_VERSION); | ||
#endif | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice way to validate it!