[DO-978] openssl package (!8)
Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/8
This commit is contained in:
44
recipes/openssl/3.x.x/test_v1_package/CMakeLists.txt
Normal file
44
recipes/openssl/3.x.x/test_v1_package/CMakeLists.txt
Normal file
@@ -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()
|
||||
40
recipes/openssl/3.x.x/test_v1_package/conanfile.py
Normal file
40
recipes/openssl/3.x.x/test_v1_package/conanfile.py
Normal file
@@ -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))
|
||||
73
recipes/openssl/3.x.x/test_v1_package/digest.c
Normal file
73
recipes/openssl/3.x.x/test_v1_package/digest.c
Normal file
@@ -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;
|
||||
}
|
||||
148
recipes/openssl/3.x.x/test_v1_package/digest_legacy.c
Normal file
148
recipes/openssl/3.x.x/test_v1_package/digest_legacy.c
Normal file
@@ -0,0 +1,148 @@
|
||||
#include <openssl/evp.h>
|
||||
#if OPENSSL_WITH_MD4
|
||||
#include <openssl/md4.h> // MD4 needs legacy provider
|
||||
#endif
|
||||
#if OPENSSL_WITH_RIPEMD160
|
||||
#include <openssl/ripemd.h> // RIPEMD160 needs legacy provider
|
||||
#endif
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/provider.h>
|
||||
#include <openssl/err.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
|
||||
|
||||
int MDx_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");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(EVP_DigestInit_ex(mdctx, type, NULL) != 1)
|
||||
{
|
||||
printf("EVP_DigestInit_ex error!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(EVP_DigestUpdate(mdctx, message, message_len) != 1)
|
||||
{
|
||||
printf("EVP_DigestUpdate error!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(EVP_DigestFinal_ex(mdctx, digest, digest_len) != 1)
|
||||
{
|
||||
printf("EVP_DigestFinal_ex error!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
EVP_MD_CTX_destroy(mdctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned int digest_len;
|
||||
unsigned char md5_digest[MD5_DIGEST_LENGTH];
|
||||
unsigned char md5_digest2[MD5_DIGEST_LENGTH];
|
||||
char md5_string[MD5_DIGEST_LENGTH*2+1] = {0};
|
||||
char md5_string2[MD5_DIGEST_LENGTH*2+1] = {0};
|
||||
char string[] = "happy";
|
||||
|
||||
MD5((unsigned char*)&string, strlen(string), (unsigned char*)&md5_digest);
|
||||
if (MDx_hash(EVP_md5(), (unsigned char*)&string, strlen(string), (unsigned char*)&md5_digest2, &digest_len))
|
||||
return 1;
|
||||
|
||||
for(int i = 0; i < MD5_DIGEST_LENGTH; i++) {
|
||||
snprintf(&md5_string[i*2], sizeof(md5_string)-i*2, "%02x", (unsigned int)md5_digest[i]);
|
||||
snprintf(&md5_string2[i*2], sizeof(md5_string2)-i*2, "%02x", (unsigned int)md5_digest2[i]);
|
||||
}
|
||||
|
||||
// MD4 needs the legacy provider
|
||||
OSSL_LIB_CTX* context = OSSL_LIB_CTX_new();
|
||||
// From https://wiki.openssl.org/index.php/OpenSSL_3.0
|
||||
/* Load Multiple providers into the default (nullptr) library context */
|
||||
OSSL_PROVIDER* legacy = OSSL_PROVIDER_load(context, "legacy");
|
||||
if (0 == legacy) {
|
||||
const char* error_string = ERR_error_string(ERR_get_error(), 0);
|
||||
fprintf(stderr, "Loading legacy provider failed with this error:\n");
|
||||
fprintf(stderr, "\t%s\n", error_string);
|
||||
return 1;
|
||||
}
|
||||
OSSL_LIB_CTX* oldcontex = OSSL_LIB_CTX_set0_default(context);
|
||||
printf("Legacy provider successfully loaded.\n");
|
||||
|
||||
#if OPENSSL_WITH_MD4
|
||||
unsigned char md4_digest[MD4_DIGEST_LENGTH];
|
||||
unsigned char md4_digest2[MD4_DIGEST_LENGTH];
|
||||
char md4_string[MD4_DIGEST_LENGTH*2+1] = {0};
|
||||
char md4_string2[MD4_DIGEST_LENGTH*2+1] = {0};
|
||||
|
||||
MD4((unsigned char*)&string, strlen(string), (unsigned char*)&md4_digest);
|
||||
if (MDx_hash(EVP_md4(), (unsigned char*)&string, strlen(string), (unsigned char*)&md4_digest2, &digest_len)) {
|
||||
const char* error_string = ERR_error_string(ERR_get_error(), 0);
|
||||
fprintf(stderr, "MD4 calculation failed with this error:\n");
|
||||
fprintf(stderr, "\t%s\n", error_string);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < MD4_DIGEST_LENGTH; i++) {
|
||||
snprintf(&md4_string[i*2], sizeof(md4_string)-i*2, "%02x", (unsigned int)md4_digest[i]);
|
||||
snprintf(&md4_string2[i*2], sizeof(md4_string2)-i*2, "%02x", (unsigned int)md4_digest2[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENSSL_WITH_RIPEMD160
|
||||
unsigned char ripemd160_digest[RIPEMD160_DIGEST_LENGTH];
|
||||
unsigned char ripemd160_digest2[RIPEMD160_DIGEST_LENGTH];
|
||||
char ripemd160_string[RIPEMD160_DIGEST_LENGTH*2+1] = {0};
|
||||
char ripemd160_string2[RIPEMD160_DIGEST_LENGTH*2+1] = {0};
|
||||
|
||||
RIPEMD160((unsigned char*)&string, strlen(string), (unsigned char*)&ripemd160_digest);
|
||||
if (MDx_hash(EVP_ripemd160(), (unsigned char*)&string, strlen(string), (unsigned char*)&ripemd160_digest2, &digest_len)) {
|
||||
const char* error_string = ERR_error_string(ERR_get_error(), 0);
|
||||
fprintf(stderr, "RIPEMD160 calculation failed with this error:\n");
|
||||
fprintf(stderr, "\t%s\n", error_string);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < RIPEMD160_DIGEST_LENGTH; i++) {
|
||||
snprintf(&ripemd160_string[i*2], sizeof(ripemd160_string)-i*2, "%02x", (unsigned int)ripemd160_digest[i]);
|
||||
snprintf(&ripemd160_string2[i*2], sizeof(ripemd160_string2)-i*2, "%02x", (unsigned int)ripemd160_digest2[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
OSSL_LIB_CTX_set0_default(oldcontex);
|
||||
OSSL_PROVIDER_unload(legacy);
|
||||
OSSL_LIB_CTX_free(context);
|
||||
|
||||
printf("MD5 digest: %s\n", md5_string);
|
||||
printf("MD5 digest (variant 2): %s\n", md5_string2);
|
||||
#if OPENSSL_WITH_MD4
|
||||
printf("MD4 digest: %s\n", md4_string);
|
||||
printf("MD4 digest (variant 2): %s\n", md4_string2);
|
||||
#endif
|
||||
#if OPENSSL_WITH_RIPEMD160
|
||||
printf("RIPEMD160 digest: %s\n", ripemd160_string);
|
||||
printf("RIPEMD160 digest (variant 2): %s\n", ripemd160_string2);
|
||||
#endif
|
||||
printf("OpenSSL version: %s\n", OpenSSL_version(OPENSSL_VERSION));
|
||||
#if defined(WITH_ZLIB)
|
||||
printf("ZLIB version: %s\n", ZLIB_VERSION);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user