Skip to content

Commit 54b677f

Browse files
committed
找到bug
1 parent d8af78a commit 54b677f

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/hcpp-cfg.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"host_":"avatars.githubusercontent.com",
2828
"svc_":"443",
2929
"url_":"",
30-
"mitm_":true,
30+
"mitm_":false,
3131
"doh_":true,
3232
"sni_host_":"www.baidu.com",
3333
"close_sni_":false
@@ -36,7 +36,7 @@
3636
"host_":"github.githubassets.com",
3737
"svc_":"443",
3838
"url_":"",
39-
"mitm_":true,
39+
"mitm_":false,
4040
"doh_":true,
4141
"sni_host_":"www.baidu.com",
4242
"close_sni_":false

src/http/httpclient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ namespace hcpp
5050

5151
virtual http_request make_request() const;
5252

53+
virtual void init(){};
54+
5355
protected:
5456
std::shared_ptr<memory> mem_;
5557
};

src/https/mitm_svc.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace hcpp
8282
// X509_NAME_oneline(X509_get_subject_name(cert), subject_name, sizeof(subject_name)); });
8383
};
8484
}
85+
8586
awaitable<void> mitm_svc::make_memory(std::string svc_host, std::string svc_service)
8687
{
8788
try
@@ -98,14 +99,14 @@ namespace hcpp
9899
{
99100
ssl_m->set_sni(sni_host_);
100101
}
101-
//XXX 这里不能用shared_from_this,因为回调会一直保持当前对象的智能指针,不释放
102-
auto verify_fun = [verify_fun_=verify_fun_, host = svc_host](bool preverified, auto &v_ctx)
102+
// XXX 这里不能用shared_from_this,因为回调会一直保持当前对象的智能指针,不释放
103+
auto verify_fun = [verify_fun_ = verify_fun_, host = svc_host](bool preverified, auto &v_ctx)
103104
{
104105
if (ssl::host_name_verification(host)(preverified, v_ctx))
105106
{
106107
if (verify_fun_)
107108
{
108-
log::info("mitm_svc::make_memory: 校验{}开始",host);
109+
log::info("mitm_svc::make_memory: 校验{}开始", host);
109110
return verify_fun_(preverified, v_ctx);
110111
}
111112
return true;
@@ -116,6 +117,7 @@ namespace hcpp
116117
}
117118
};
118119
ssl_m->set_verify_callback(verify_fun);
120+
//XXX 这里的async_handshake会阻塞住线程,因此要在单独的协程里再进行.所以当前函数不能调用在监听连接的时候
119121
co_await ssl_m->async_handshake();
120122
m_ = ssl_m;
121123
co_return;
@@ -186,7 +188,6 @@ namespace hcpp
186188
chc_->service_ = service;
187189
m->check(*this);
188190
co_await channel_->async_send(asio::error_code{}, chc_);
189-
log::error("channel_tunnel::make_tunnel: 建立channel tunnel {}", host);
190191
}
191192

192193
void channel_tunnel::make(std::unique_ptr<tcp_socket> sock)
@@ -209,6 +210,11 @@ namespace hcpp
209210
return hr;
210211
}
211212

213+
void https_client::init()
214+
{
215+
//TODO 在这里实现创建假证书
216+
}
217+
212218
awaitable<std::shared_ptr<memory>> channel_client::make(subject_identify si) &&
213219
{
214220
auto e = co_await this_coro::executor;

src/https/mitm_svc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace hcpp
3939
{
4040
virtual http_request make_request() const override;
4141

42+
virtual void init() override;
43+
4244
void set_mem(std::shared_ptr<memory> m)
4345
{
4446
mem_ = m;

src/httpserver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace hcpp
1919

2020
awaitable<void> http_do(std::unique_ptr<http_client> client, std::shared_ptr<service_keeper> sk)
2121
{
22+
client->init();
2223
while (true)
2324
{
2425
auto ss = client->get_memory();
@@ -210,6 +211,7 @@ namespace hcpp
210211
try
211212
{
212213
std::shared_ptr<channel_client> cc = co_await c->async_receive();
214+
//BUG 这里以下部分需要放到协程执行,因为一些操作会阻塞住线程
213215
auto hsc = std::make_unique<https_client>();
214216
hsc->host_ = cc->host_;
215217
hsc->service_ = cc->service_;
@@ -249,7 +251,6 @@ namespace hcpp
249251

250252
hsc->set_mem(co_await std::move(*cc).make(std::move(si)));
251253

252-
log::error("开始http_do {}", hsc->host_);
253254
co_spawn(executor, http_do(std::move(hsc), std::move(sk)), detached);
254255
}
255256
catch (const std::exception &e)
@@ -287,7 +288,7 @@ namespace hcpp
287288
executor.stop();
288289
delete p; });
289290

290-
co_await co_spawn(executor,https_listener(),use_awaitable);
291+
co_await co_spawn(executor, https_listener(), use_awaitable);
291292
// co_await https_listener();
292293
co_return;
293294
}

0 commit comments

Comments
 (0)