-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2122a6c
commit 11f3ca3
Showing
4 changed files
with
77 additions
and
10 deletions.
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
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 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2024 Chilledheart */ | ||
|
||
#ifndef H_NET_ASIO_SSL_INTERNAL | ||
#define H_NET_ASIO_SSL_INTERNAL | ||
|
||
#include "net/asio.hpp" | ||
|
||
#include <string_view> | ||
|
||
#ifdef HAVE_BUILTIN_CA_BUNDLE_CRT | ||
|
||
extern "C" const char _binary_ca_bundle_crt_start[]; | ||
extern "C" const char _binary_ca_bundle_crt_end[]; | ||
|
||
#endif | ||
|
||
extern "C" const char _binary_supplementary_ca_bundle_crt_start[]; | ||
extern "C" const char _binary_supplementary_ca_bundle_crt_end[]; | ||
|
||
int load_ca_to_ssl_ctx_from_mem(SSL_CTX* ssl_ctx, std::string_view cadata); | ||
int load_ca_to_ssl_ctx_system(SSL_CTX* ssl_ctx); | ||
|
||
#endif // H_NET_ASIO_SSL_INTERNAL |
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,48 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2024 Chilledheart */ | ||
|
||
#include <build/build_config.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include "core/utils.hpp" | ||
#include "net/asio_ssl_internal.hpp" | ||
|
||
#ifdef HAVE_BUILTIN_CA_BUNDLE_CRT | ||
TEST(SSL_TEST, LoadBuiltinCaBundle) { | ||
bssl::UniquePtr<SSL_CTX> ssl_ctx; | ||
ssl_ctx.reset(::SSL_CTX_new(::TLS_client_method())); | ||
std::string_view ca_bundle_content(_binary_ca_bundle_crt_start, | ||
_binary_ca_bundle_crt_end - _binary_ca_bundle_crt_start); | ||
ASSERT_FALSE(ca_bundle_content.empty()); | ||
int result = load_ca_to_ssl_ctx_from_mem(ssl_ctx.get(), ca_bundle_content); | ||
ASSERT_NE(result, 0); | ||
} | ||
#endif | ||
|
||
TEST(SSL_TEST, LoadSupplementaryCaBundle) { | ||
bssl::UniquePtr<SSL_CTX> ssl_ctx; | ||
ssl_ctx.reset(::SSL_CTX_new(::TLS_client_method())); | ||
std::string_view ca_content(_binary_supplementary_ca_bundle_crt_start, | ||
_binary_supplementary_ca_bundle_crt_end - _binary_supplementary_ca_bundle_crt_start); | ||
ASSERT_FALSE(ca_content.empty()); | ||
int result = load_ca_to_ssl_ctx_from_mem(ssl_ctx.get(), ca_content); | ||
ASSERT_NE(result, 0); | ||
} | ||
|
||
TEST(SSL_TEST, LoadSystemCa) { | ||
bssl::UniquePtr<SSL_CTX> ssl_ctx; | ||
ssl_ctx.reset(::SSL_CTX_new(::TLS_client_method())); | ||
int result = load_ca_to_ssl_ctx_system(ssl_ctx.get()); | ||
#ifdef _WIN32 | ||
if (IsWindowsVersionBNOrGreater(6, 3, 0)) { | ||
ASSERT_NE(result, 0); | ||
} else { | ||
GTEST_SKIP() << "skipped as system version is too low"; | ||
} | ||
#elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_OHOS) || !defined(HAVE_BUILTIN_CA_BUNDLE_CRT) | ||
ASSERT_NE(result, 0); | ||
#else | ||
// we don't test on openwrt | ||
GTEST_SKIP() << "skipped as system is not supported"; | ||
#endif | ||
} |