|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
SSL/TLS上下文管理类 更多...
#include <ssl_context.hpp>
Public 成员函数 | |
| ssl_context (ssl_method method=ssl_method::TLS_SERVER) | |
| 构造函数 | |
| bool | load_certificate (const string &cert_file, const string &key_file) |
| 加载证书和私钥(从文件) | |
| void | load_certificate_from_memory (const string &cert_pem, const string &key_pem) |
| 加载证书和私钥(从内存) | |
| bool | load_verify_locations (const string &ca_file, const string &ca_path="") |
| 加载CA证书用于验证 | |
| void | set_options (long options) |
| 设置SSL选项 | |
| void | set_verify_mode (int mode) |
| 设置验证模式 | |
| void | require_client_certificate () |
| 要求客户端提供证书 | |
| void | set_cipher_list (const string &ciphers) |
| 设置密码套件列表(TLS 1.2及以下) | |
| void | set_ciphersuites (const string &ciphersuites) |
| 设置密码套件列表(TLS 1.3) | |
| void | set_default_options () |
| 设置安全的默认选项 | |
| void | set_session_cache_size (long size) |
| 设置会话缓存大小 | |
| void | set_timeout (long seconds) |
| 设置会话超时时间 | |
| void | set_alpn_protos (const vector< string > &protocols) |
| 设置ALPN协议列表 | |
| NEFORCE_NODISCARD::SSL_CTX * | native_handle () const noexcept |
| 获取原生SSL_CTX句柄 | |
| operator bool () const noexcept | |
| 布尔转换运算符 | |
| NEFORCE_NODISCARD bool | is_valid () const noexcept |
| 检查上下文是否有效 | |
SSL/TLS上下文管理类
封装OpenSSL的SSL_CTX对象,提供SSL连接的配置和管理功能。 支持证书加载、验证配置、密码套件设置等。
主要功能:
在文件 ssl_context.hpp 第 60 行定义.
|
explicit |
构造函数
| method | SSL/TLS方法类型(默认为TLS服务器) |
| ssl_exception | SSL上下文创建失败时抛出 |
创建SSL上下文并设置基本选项:
引用了 ssl_context() , 以及 TLS_SERVER.
被这些函数引用 ssl_context().
|
inlinenoexcept |
加载证书和私钥(从文件)
| cert_file | 证书文件路径(PEM格式) |
| key_file | 私钥文件路径(PEM格式) |
加载服务器或客户端的证书和对应的私钥。 会自动检查私钥是否与证书匹配。
加载证书和私钥(从内存)
| cert_pem | 证书PEM数据 |
| key_pem | 私钥PEM数据 |
| ssl_exception | SSL上下文为空或解析、设置失败时抛出 |
| value_exception | 证书或密钥数据为空时抛出 |
从内存中的PEM数据加载证书和私钥,适用于嵌入式证书。
加载CA证书用于验证
| ca_file | CA证书文件路径 |
| ca_path | CA证书目录路径(可选) |
设置用于验证对等方证书的CA证书。 可以指定单个文件或目录(目录中的证书会被自动加载)。
|
inlinenoexcept |
|
inlineexplicitnoexcept |
| void ssl_context::require_client_certificate | ( | ) |
设置ALPN协议列表
| protocols | 协议名称列表 |
| ssl_exception | SSL上下文为空或设置失败时抛出 |
| value_exception | 协议名称长度无效时抛出 |
设置应用层协议协商(ALPN)支持的协议列表。 用于在TLS握手时协商应用层协议(如HTTP/2)。
| void ssl_context::set_cipher_list | ( | const string & | ciphers | ) |
设置密码套件列表(TLS 1.2及以下)
| ciphers | OpenSSL密码套件字符串 |
| ssl_exception | SSL上下文为空或设置失败时抛出 |
设置可用的密码套件列表,格式为OpenSSL密码套件字符串。 例如:"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384"
| void ssl_context::set_ciphersuites | ( | const string & | ciphersuites | ) |
设置密码套件列表(TLS 1.3)
| ciphersuites | OpenSSL TLS 1.3密码套件字符串 |
| ssl_exception | SSL上下文为空或设置失败时抛出 |
设置TLS 1.3的密码套件列表。 例如:"TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256"
| void ssl_context::set_default_options | ( | ) |
设置安全的默认选项
| ssl_exception | SSL上下文为空时抛出 |
配置推荐的现代安全选项:
| void ssl_context::set_options | ( | long | options | ) |
| void ssl_context::set_session_cache_size | ( | long | size | ) |
| void ssl_context::set_timeout | ( | long | seconds | ) |
| void ssl_context::set_verify_mode | ( | int | mode | ) |
设置验证模式
| mode | OpenSSL SSL_VERIFY_*模式 |
| ssl_exception | SSL上下文为空时抛出 |
设置对等方证书的验证模式。 常用模式: