Skip to content

Commit

Permalink
Remove program option socks_userid and socks_passwd.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed Oct 30, 2023
1 parent c38aefc commit 4eb1076
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 51 deletions.
4 changes: 2 additions & 2 deletions example/nested_proxy/nested_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ net::awaitable<void> start_proxy_server(net::io_context& ioc, server_ptr& server
10800);

proxy_server_option opt;
opt.usrdid_ = "jack";
opt.passwd_ = "1111";

opt.auth_users_.emplace_back("jack", "1111");

auto executor = ioc.get_executor();
server = proxy_server::make(
Expand Down
58 changes: 17 additions & 41 deletions proxy/include/proxy/proxy_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ namespace proxy {
// proxy server 参数选项.
struct proxy_server_option
{
// 指定当前proxy server认证用户id名称.
std::string usrdid_;
// 指定当前proxy server认证密码.
std::string passwd_;

// 授权信息.
using auth_users = std::tuple<std::string, std::string>;
std::vector<auth_users> auth_users_;
Expand Down Expand Up @@ -452,7 +447,7 @@ namespace proxy {
}

// 服务端是否需要认证.
auto auth_required = !m_option.usrdid_.empty();
auto auth_required = !m_option.auth_users_.empty();

// 循环读取客户端支持的代理方式.
p = net::buffer_cast<const char*>(m_local_buffer.data());
Expand Down Expand Up @@ -1127,19 +1122,14 @@ namespace proxy {
<< (socks4a ? hostname : dst_endpoint.address().to_string());

// 用户认证逻辑.
bool verify_passed = m_option.usrdid_ == userid;
bool verify_passed = m_option.auth_users_.empty();

if (!verify_passed || userid.empty())
for (auto [user, pwd] : m_option.auth_users_)
{
verify_passed = false;

for (auto [user, pwd] : m_option.auth_users_)
if (user == userid)
{
if (user == userid)
{
verify_passed = true;
break;
}
verify_passed = true;
break;
}
}

Expand Down Expand Up @@ -1258,7 +1248,7 @@ namespace proxy {

inline bool http_proxy_authorization(std::string_view pa)
{
if (m_option.usrdid_.empty() && m_option.auth_users_.empty())
if (m_option.auth_users_.empty())
return true;

if (pa.empty())
Expand Down Expand Up @@ -1307,21 +1297,14 @@ namespace proxy {
std::string uname = userinfo.substr(0, pos);
std::string passwd = userinfo.substr(pos + 1);

bool verify_passed =
m_option.usrdid_ == uname &&
m_option.passwd_ == passwd;
bool verify_passed = m_option.auth_users_.empty();

if (!verify_passed || uname.empty())
for (auto [user, pwd] : m_option.auth_users_)
{
verify_passed = false;

for (auto [user, pwd] : m_option.auth_users_)
if (uname == user && passwd == pwd)
{
if (uname == user && passwd == pwd)
{
verify_passed = true;
break;
}
verify_passed = true;
break;
}
}

Expand Down Expand Up @@ -1641,21 +1624,14 @@ namespace proxy {
client += ":" + std::to_string(endp.port());

// 用户认证逻辑.
bool verify_passed =
m_option.usrdid_ == uname &&
m_option.passwd_ == passwd;
bool verify_passed = m_option.auth_users_.empty();

if (!verify_passed || uname.empty())
for (auto [user, pwd] : m_option.auth_users_)
{
verify_passed = false;

for (auto [user, pwd] : m_option.auth_users_)
if (uname == user && passwd == pwd)
{
if (uname == user && passwd == pwd)
{
verify_passed = true;
break;
}
verify_passed = true;
break;
}
}

Expand Down
8 changes: 0 additions & 8 deletions server/proxy_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ using server_ptr = std::shared_ptr<proxy_server>;

//////////////////////////////////////////////////////////////////////////

std::string socks_userid;
std::string socks_passwd;
std::vector<std::string> auth_users;
std::string proxy_pass;
bool proxy_pass_ssl = false;
Expand Down Expand Up @@ -83,9 +81,6 @@ start_proxy_server(net::io_context& ioc, server_ptr& server)

proxy_server_option opt;

opt.usrdid_ = socks_userid;
opt.passwd_ = socks_passwd;

for (const auto& user : auth_users)
{
if (user.empty())
Expand Down Expand Up @@ -214,9 +209,6 @@ int main(int argc, char** argv)
("happyeyeballs", po::value<bool>(&happyeyeballs)->default_value(true), "Enable Happy Eyeballs algorithm for TCP connections.")
("local_ip", po::value<std::string>(&local_ip), "Specify local IP for client TCP connection to server.")

("socks_userid", po::value<std::string>(&socks_userid)->default_value("jack")->value_name("userid"), "Authentication user ID (Deprecated).")
("socks_passwd", po::value<std::string>(&socks_passwd)->default_value("1111")->value_name("passwd"), "Authentication password (Deprecated).")

("auth_users", po::value<std::vector<std::string>>(&auth_users)->multitoken()->value_name("user:passwd"), "List of authorized users (e.g: user:passwd).")

("proxy_pass", po::value<std::string>(&proxy_pass)->default_value("")->value_name(""), "Specify next proxy pass (e.g: socks5://user:passwd@ip:port).")
Expand Down

0 comments on commit 4eb1076

Please sign in to comment.