A fast, secure, lightweight and cross-platform HTTP proxy written in C++11, based on Boost and OpenSSL。
简介
AHP(Azure Http Proxy)是一款高速、安全、轻量级和跨平台的HTTP代理,使用对称加密算法AES对传输的数据进行加密,使用非对称加密算法RSA传输密钥。
特性
- 一连接一密钥,AHP会对每个连接使用一个随机生成的密钥和初始化向量,避免重复使用同一密钥
- 使用非对称加密算法RSA传输密钥,只需对客户端公开RSA公钥
- 对目标域名的解析在服务端进行,可以解决本地DNS污染的问题
- 服务端同时支持多种数据加密方式,数据加密方式可由客户端任意指定,客户端可以权衡机器性能以及安全需求选择合适的加密方式
- 多线程并发处理,充分利用多处理器的优势,能同时处理成千上万的并发连接
- 多用户支持,允许为每个用户使用独立的帐号和密码
编译和安装
Windows平台可以从 https://github.com/lxrite/azure-http-proxy/releases 下载已经编译好的(win32-binary.zip)-https://github.com/lxrite/azure-http-proxy/releases/download/1.0/ahp-1.0-win32-binary.zip
编译器
AHP使用了部分C++11特性,所以对编译器的版本有较高要求,下面列出了部分已测试过可以用来编译AHP的编译器
- Microsoft Visual Studio >= 2013
- GCC >= 4.8 (参见此文http://briteming.blogspot.com/2016/01/gccv48.html,升级你的gcc到4.8.x版)
- Clang >= 3.2
- MinGW >= 4.8
安装依赖
AHP依赖Boost和OpenSSL库,且要求Boost库版本不低于1.52
绝大多数Linux发行版都可以通过包管理安装Boost和OpenSSL
Ubuntu
$ apt-get install libboost-system-dev
$ apt-get install libboost-regex-dev
$ apt-get install libssl-dev
Fedora
$ yum install boost-devel
$ yum install boost-system
$ yum install boost-regex
$ yum install openssl
$ yum install openssl-devel
Windows则需要自己编译Boost库,而OpenSSL库可以从 https://www.openssl.org/related/binaries.html 下载到编译好的。
编译
AHP使用自动化构建工具CMake来实现跨平台构建
- CMake >= 2.8
Windows下可以使用cmake-gui.exe,Linux或其他类Unix系统可以使用下面的命令编译:
git clone https://github.com/lxrite/azure-http-proxy
git clone https://github.com/lxrite/azure-http-proxy
cd azure-http-proxy
cd src
git submodule update --init
cd ..
cmake .
make
如果编译成功,会在当前目录
(这个生成的客户端程序ahpc在mac下无法使用。只好在mac下,自己去生成ahpc文件:
brew install boost
brew install cmake
然后
git clone https://github.com/lxrite/azure-http-proxy
cd azure-http-proxy
cmake .
make
上面,我运行make这一步时,遇到错误。参考https://github.com/lxrite/azure-http-proxy/issues/10,把CMakeLists.txt文件的第28 - 30行删除,重新运行:
cmake .
make
这次,就能成功生成ahpc这个可执行文件。所以在mac下也能使用azure-http-proxy成功翻墙)
azure-http-proxy下,生成ahpc(客户端)和ahps(服务端)。(这个生成的客户端程序ahpc在mac下无法使用。只好在mac下,自己去生成ahpc文件:
brew install boost
brew install cmake
然后
git clone https://github.com/lxrite/azure-http-proxy
cd azure-http-proxy
cmake .
make
上面,我运行make这一步时,遇到错误。参考https://github.com/lxrite/azure-http-proxy/issues/10,把CMakeLists.txt文件的第28 - 30行删除,重新运行:
cmake .
make
这次,就能成功生成ahpc这个可执行文件。所以在mac下也能使用azure-http-proxy成功翻墙)
配置和运行
注意:不要使用示例配置中的RSA私钥和公钥,因为私钥一公开就是不安全的了。
如果你要运行的是服务端,那么你首先需要生成一对RSA密钥对,AHP支持任意长度不小于1024位的RSA密钥。下面的命令使用openssl生成2048位的私钥和公钥
$ openssl genrsa -out rsa_private_key.pem 2048
$ openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
服务端保留私钥并将公钥告诉客户端。
配置服务端
编辑server.json文件,Windows下应将此文件放到ahps.exe同目录下,Linux或其他类Unix系统将此文件放到~/.ahps/server.json。
{
"bind_address": "0.0.0.0",
"listen_port": 8090,
"rsa_private_key": "-----BEGIN RSA PRIVATE KEY----- ...... -----END RSA PRIVATE KEY-----",
"timeout": 240,
"workers": 4,
"auth": true,
"users": [
{
"username": "username1",
"password": "password1"
},
{
"username": "foobar",
"password": "bazqux"
}
]
}
| 字段名 | 描述 | 是否必选 | 默认值 |
|---|---|---|---|
| bind_address | 服务端绑定的IP地址 | 否 | "0.0.0.0" |
| listen_port | 服务端绑定的端口 | 否 | 8090 |
| rsa_private_key | RSA私钥 | 是 | 无 |
| timeout | 超时时间(秒) | 否 | 240 |
| workers | 并发工作线程数 | 否 | 4 |
| auth | 启用代理身份验证 | 否 | false |
| users | 用户列表 | auth为true时必选 | 无 |
配置客户端
编辑client.json文件,Windows下应将此文件放到ahpc.exe或ahpc-gui.exe同目录下,Linux或其他类Unix系统将此文件放到~/.ahpc/client.json。
{
"proxy_server_address": "127.0.0.1",
"proxy_server_port": 8090,
"bind_address": "127.0.0.1",
"listen_port": 8089,
"rsa_public_key": "-----BEGIN PUBLIC KEY----- ...... -----END PUBLIC KEY-----",
"cipher": "aes-256-ofb",
"timeout": 240,
"workers": 2
}
| 字段名 | 描述 | 是否必选 | 默认值 |
|---|---|---|---|
| proxy_server_address | 服务端的IP地址或域名 | 是 | 无 |
| proxy_server_port | 服务端的端口 | 是 | 无 |
| bind_address | 客户端绑定的IP地址 | 否 | "127.0.0.1" |
| listen_port | 客户端的监听端口 | 否 | 8089 |
| rsa_public_key | RSA公钥 | 是 | 无 |
| cipher | 加密方法 | 否 | "aes-256-ofb" |
| timeout | 超时时间(秒) | 否 | 240 |
| workers | 并发工作线程数 | 否 | 2 |
支持的加密方法
- aes-xyz-cfb
- aes-xyz-cfb8
- aes-xyz-cfb1
- aes-xyz-ofb
- aes-xyz-ctr
中间的xyz可以为128、192或256。
运行
确定配置无误后就可以运行AHP了。
运行服务端
Linux或其他类Unix系统
$ ./ahps
不过./ahps是运行在前台的,容易退出。我们可以利用systemd来把./ahps运行为service:
nano /etc/systemd/system/ahp.service
内容为:
[Unit]
After=network.target
[Service]
WorkingDirectory=/root/azure-http-proxy
ExecStart=/root/azure-http-proxy/ahps
Restart=always
[Install]
WantedBy=multi-user.target
然后运行:
systemctl daemon-reload
systemctl restart ahp
systemctl enable ahp服务器端就搭建好了。
运行客户端
Linux或其他类Unix系统:
$ ./ahpc
Windows
$ ahpc.exe (在解压出来的目录里,新建ahpc.bat文件,其内容为ahpc.exe 。双击ahpc.bat
文件,客户端就启动了.或者不新建ahpc.bat也行,只需运行ahpc-gui.exe。设置浏览器的http代理为127.0.0.1:8089,即可翻墙)
from https://github.com/lxrite/azure-http-proxy
https://github.com/lxrite/azure-http-proxy/issues/10
https://github.com/lxrite/azure-http-proxy/issues/10
https://github.com/lxrite/azure-http-proxy/issues/11
https://github.com/lxrite/azure-http-proxy/issues/15
这个程序的翻墙速度不如goproxy-by-alienero(https://briteming.blogspot.com/2015/11/goproxy.html)快。
这个程序的翻墙速度不如goproxy-by-alienero(https://briteming.blogspot.com/2015/11/goproxy.html)快。