2022-08-20 19:31:37 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "../acl_cpp_define.hpp"
|
|
|
|
|
#include <vector>
|
2022-08-22 17:13:39 +08:00
|
|
|
|
#include "../stdlib/thread_mutex.hpp"
|
2022-08-21 17:34:05 +08:00
|
|
|
|
#include "../stdlib/string.hpp"
|
2022-08-20 19:31:37 +08:00
|
|
|
|
#include "sslbase_conf.hpp"
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class openssl_io;
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API openssl_conf : public sslbase_conf {
|
|
|
|
|
public:
|
|
|
|
|
openssl_conf(bool server_side = false);
|
|
|
|
|
~openssl_conf(void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
bool load_ca(const char* ca_file, const char* ca_path);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
2022-08-20 21:32:08 +08:00
|
|
|
|
bool add_cert(const char* crt_file, const char* key_file,
|
2022-08-20 19:31:37 +08:00
|
|
|
|
const char* key_pass = NULL);
|
|
|
|
|
|
2022-08-21 17:34:05 +08:00
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @deprecate use add_cert(const char*, const char*, const char*)
|
|
|
|
|
*/
|
|
|
|
|
bool add_cert(const char* crt_file);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @deprecate use add_cert(const char*, const char*, const char*)
|
|
|
|
|
*/
|
|
|
|
|
bool set_key(const char* key_file, const char* key_pass);
|
|
|
|
|
|
2022-08-20 19:31:37 +08:00
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
|
|
|
|
void enable_cache(bool on);
|
|
|
|
|
|
2022-08-22 17:13:39 +08:00
|
|
|
|
public:
|
|
|
|
|
/**
|
2022-08-22 22:32:23 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ·<EFBFBD><EFBFBD>
|
|
|
|
|
* @param libcrypto {const char*} libcrypto.so <EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ·<EFBFBD><EFBFBD>
|
|
|
|
|
* @param libssl {const char*} libssl.so <EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ·<EFBFBD><EFBFBD>
|
2022-08-22 17:13:39 +08:00
|
|
|
|
*/
|
2022-08-22 22:03:38 +08:00
|
|
|
|
static void set_libpath(const char* libcrypto, const char* libssl);
|
2022-08-22 17:13:39 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2022-08-22 22:32:23 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD> libssl.so <EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2022-08-22 17:13:39 +08:00
|
|
|
|
*/
|
|
|
|
|
static bool load(void);
|
|
|
|
|
|
2022-08-20 19:31:37 +08:00
|
|
|
|
public:
|
|
|
|
|
// @override sslbase_conf
|
|
|
|
|
sslbase_io* create(bool nblock);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool setup_certs(void* ssl);
|
|
|
|
|
|
|
|
|
|
bool is_server_side(void) const
|
|
|
|
|
{
|
|
|
|
|
return server_side_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* get_ssl_ctx(void) const
|
|
|
|
|
{
|
|
|
|
|
return ssl_ctx_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
friend class openssl_io;
|
|
|
|
|
|
2022-08-21 17:34:05 +08:00
|
|
|
|
bool server_side_;
|
|
|
|
|
void* ssl_ctx_;
|
|
|
|
|
string crt_file_;
|
2022-08-22 17:13:39 +08:00
|
|
|
|
unsigned init_status_;
|
|
|
|
|
thread_mutex lock_;
|
|
|
|
|
|
|
|
|
|
bool init_once(void);
|
2022-08-20 19:31:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|