目录
1. Stunnel 笔记
1.1. Stunnel 是什么
- stunnel 是一个开源跨平台进行通信加密的软件。它可以对原生不支持加密通信的服务(如 FTP, Telnet 等)在上层提供加密功能, 而无须修改这些服务的代码。
- Stunnel 是一个可以用 SSL 对任意 TCP 连接加密的程序。它可以运行在多种 UNIX 和 Windows 上, 它是基于 OpenSSL 的, 所以它要求已经安装了 OpenSSL, 并进行了正确的配置。
- 由于 Stunnel 使用加密过的连接, 因此没有人能看到服务器端和客户端传送的数据。
- stunnel 是一个开源跨平台进行通信加密的软件。它可以对原生不支持加密通信的服务(如 FTP, Telnet 等)在上层提供加密功能, 而无须修改这些服务的代码。
- Stunnel 是一款全局加密传输软件 (https://www.stunnel.org/), 工作在 Unix 和 Windows 平台上, 作为代理, 可以将应用程序发送的明文 TCP 流量加密, 而无需重新配置应用程序本身。明文数据的例子包括 POP3、IMAP、SMTP 以及 HTTP 应用程序生成的任何内容。一旦将 stunnel 配置为加密数据隧道, 通过该端口发送的任何内容都将使用 SSL 加密。两端都需要安装 Stunnel, 以便在传递到适当的应用程序之前将流量返回到明文。
1.2. Stunnel 安装
sudo apt-get install stunnel4
1.3. Stunnel/SSH
1.3.1. Overview
------------------------------------------------------- -------------------------------------------------------
| terminal, ssh client --> (port 3333) stunnel client | --> | (port 2222) stunnel server --> (port 22) ssh server |
------------------------------------------------------- -------------------------------------------------------
local remote server
1.3.2. Setting up client
# client config,
# will ssh directly to local port 3333
# ssh -p 3333 root@localhost
# stunnel client connects to remote stunnel server at IP A.B.C.D over external port 2222
output = /var/log/stunnel4/stunnel.log
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
pid = /var/run/stunnel4/stunnel.pid
client = yes
[ssh]
accept = 127.0.0.1:3333
connect = A.B.C.D:2222 # A.B.C.D is the remote server address.
1.3.3. Setting up server
# server config,
# stunnel server will listen for stunnel clients connecting on port 2222
# traffic will be decrypted and forwarded to local port 22
output = /var/log/stunnel4/stunnel.log
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
pid = /var/run/stunnel4/stunnel.pid
client = no
[ssh]
accept = 2222
connect = 127.0.0.1:22
1.3.4. Testing
[client] $ ssh -p 2222 root@localhost
<enter root password for the remote server>
[remote] $ whoami
root
[remote] $
1.3.5. MacOS settings
brew install stunnel
1.3.6. 参考
1.4. 问题排查
1.4.1. You should check that you have specified the pid= in you configuration file
这个错误信息可能会让你误以为是配置出现了错误, 但通过查看 log 会发现, 原来错误原因是端口已经被占用了。
1.4.2. SSL: EE_KEY_TOO_SMALL
原因是使用的私钥长度太短了, 需要高于 1024 位, 需要再重新生成一个 2048 位的密钥和证书。
1.4.3. 生成证书
这里只留作参阅,操作起来太麻烦了,推荐一键式的: 使用 OpenSSL 生成 HTTPS 证书
openssl genrsa 2048 > stunnel.key
openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt
cat stunnel.crt stunnel.key > stunnel.pem
参考自这里