墨少离 - 个人小站,分享一些资源以及心得~ - stunnel
https://www.msl.la/tag/stunnel/
-
使用stunnel双向证书认证加密samba的数据传输
https://www.msl.la/archives/469/
2021-11-06T19:57:28+08:00
服务端ubuntu server 14.04客户端windows 7服务端ubuntu以下在ubuntu server上操作samba的设置在配置文件中限制只服务内网接口和lointerfaces = eth1 127.0.0.0/8
bind interfaces only = yesstunnel的安装ubuntu上使用stunnel4做服务端sudo apt-get install stunnel4把文件/etc/default/stunnel4中的ENABLED=1设置为1使能自动启动证书准备参考http://blog.csdn.net/zahuopuboss/article/details/8664446准备CA证书,并使用CA签发2份证书1份给服务端使用,1份给客户端使用如果有多个客户端,则签发多份例如:cacert.pem,serverprivkey.pem,servercert.pem,clientprivkey.pem,clientcert.pem使用命令openssl x509 -hash -in servercert.pem -noout得到证书的哈希值XXXXXXXX以XXXXXXXX.0为名称复制servercert.pem对客户端证书同样操作得到以哈希值命名的证书文件用于服务端与客户端进行相互的证书认证服务端stunnel配置配置文件/etc/stunnel/stunnel.conf内容如下:chroot = /var/lib/stunnel4/
setuid = stunnel4
setgid = stunnel4
pid = /stunnel4.pid
debug = 7
output = /stunnel.log
ciphers = DHE-RSA-AES256-SHA256
client = no
cert = /etc/stunnel/servercert.pem
key = /etc/stunnel/serverprivkey.pem
verify = 3
CApath = /certs
CAfile = /etc/stunnel/cacert.pem
[smb]
accept = 9999
connect = 445
CApath是相对chroot路径的,在chroot路径下建立certs目录把以哈希值命名的客户端证书放置在CApath路径下验证方式verify设置为3,使用本地保存的证书(CApath下哈希值命名的证书)来验证对端的证书客户端win7以下在windows上操作添加loop接口控制面板 -> 设备管理器 -> 菜单操作 -> 添加过时硬件手动选择 -> 网络适配器Microsoft -> Microsoft Loopback Adapter添加完成后打开网络和各项中心 -> 更改适配器设置 -> 右击Loopback接口 -> 属性使用的项目只保留IPv4 -> 进入该项的高级设置 -> 禁用NetBIOS设置Loopback接口IP为10.0.0.1关闭共享服务控制面板 -> 管理工具 -> 服务禁用server服务以便stunnel可以监听445端口重启电脑客户端stunnel下载https://www.stunnel.org/downloads.html下载installer.exe安装stunnel设置右击状态栏图标,点击edit configration内容如下:debug = 7
client = yes
[smb]
accept = 10.0.0.1:445
connect = serveripordomain:9999
CAfile = cacert.pem
verify = 3
cert = clientcert.pem
key = clientprivkey.pem
CApath = ./certs/在安装路径下的config目录内建立certs目录把以哈希值命名的服务端证书放到cert目录内验证方式verify设置为3,以便验证服务端点击reload configration使用\10.0.0.1\xxx访问samba服务验证方式说明verify = 3
Verify the peer against a locally installed certificate.不但会使用CA验证对端证书的有效性(同level2,可以有效避免中间人攻击)还会验证CApath是否存在一份对端证书的拷贝(避免证书滥用,因为CA颁发的证书中不一定都是用来连接stunnel的)双方都使用verify = 3进行互相认证参考https://www.stunnel.org/static/stunnel.htmlhttps://www.stunnel.org/pipermail/stunnel-users/2013-September/004337.htmlhttps://www.stunnel.org/downloads.htmlhttp://blog.csdn.net/zahuopuboss/article/details/8664446https://gigacog.com/blog/2016/02/cifs-over-ssl-with-stunnel-and-windows-client/https://www.digitalocean.com/community/tutorials/how-to-set-up-an-ssl-tunnel-using-stunnel-on-ubuntuhttps://wiki.netbsd.org/tutorials/how_to_secure_samba_with_stunnel/————————————————版权声明:本文为CSDN博主「雜貨鋪老闆」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/zahuopuboss/article/details/53439670