Merge branch 'gitee-master' into gitlab-upstream

This commit is contained in:
zhengshuxin 2024-05-27 09:23:26 +08:00
commit 9f119ff075
3 changed files with 32 additions and 2 deletions

View File

@ -71,6 +71,20 @@ public:
return has_sni_; return has_sni_;
} }
/**
* SSL IO 便
* @param ctx {void*}
*/
void set_ctx(void* ctx);
/**
* set_ctx()
* @return {void*}
*/
void* get_ctx() const {
return ctx_;
}
protected: protected:
sslbase_conf& base_conf_; sslbase_conf& base_conf_;
bool server_side_; bool server_side_;
@ -80,6 +94,7 @@ protected:
ACL_VSTREAM* stream_; ACL_VSTREAM* stream_;
string sni_host_; // Just for client to set SNI. string sni_host_; // Just for client to set SNI.
bool has_sni_; // Just for server to check SNI. bool has_sni_; // Just for server to check SNI.
void* ctx_; // The context for every SSL IO.
}; };
} // namespace acl } // namespace acl

View File

@ -16,12 +16,19 @@ public:
bool check(acl::sslbase_io* io, const char* sni, acl::string& host) { bool check(acl::sslbase_io* io, const char* sni, acl::string& host) {
if (io) { if (io) {
io->set_has_sni(true); io->set_has_sni(true);
acl::sslbase_io* me = (acl::sslbase_io*) io->get_ctx();
if (io != me) {
printf("Invalid io=%p, me=%p\r\n", io, me);
return false;
}
printf("ssl_sni_checker::check: sslbase_io=%p\r\n", io);
} else {
printf("ssl_sni_checker::check: sslbase_io=NULL\r\n");
} }
printf("ssl_sni_checker::check: sslbase_io=%p\n", io);
if (sni == NULL || *sni == 0) { if (sni == NULL || *sni == 0) {
printf("Invalid SNI\r\n"); printf("Invalid SNI=%p\r\n", sni);
return false; return false;
} }
@ -74,6 +81,9 @@ private:
bool non_block = false; bool non_block = false;
acl::sslbase_io* ssl = ssl_conf_.create(non_block); acl::sslbase_io* ssl = ssl_conf_.create(non_block);
// 设置私有对象,在 ssl_sni_checker::check() 中检查
ssl->set_ctx(ssl);
// 对于使用 SSL 方式的流对象,需要将 SSL IO 流对象注册至网络 // 对于使用 SSL 方式的流对象,需要将 SSL IO 流对象注册至网络
// 连接流对象中,即用 ssl io 替换 stream 中默认的底层 IO 过程 // 连接流对象中,即用 ssl io 替换 stream 中默认的底层 IO 过程
if (conn_->setup_hook(ssl) == ssl) { if (conn_->setup_hook(ssl) == ssl) {

View File

@ -17,6 +17,7 @@ sslbase_io::sslbase_io(sslbase_conf& conf, bool server_side,
, handshake_ok_(false) , handshake_ok_(false)
, stream_(NULL) , stream_(NULL)
, has_sni_(false) , has_sni_(false)
, ctx_(NULL)
{ {
refers_ = NEW atomic_long(0); refers_ = NEW atomic_long(0);
} }
@ -53,4 +54,8 @@ void sslbase_io::set_has_sni(bool yes) {
has_sni_ = yes; has_sni_ = yes;
} }
void sslbase_io::set_ctx(void *ctx) {
ctx_ = ctx;
}
} // namespace acl } // namespace acl