使用stunnel双向证书认证加密samba的数据传输
2016-12-02 23:45
232 查看
服务端ubuntu server 14.04
客户端windows 7
interfaces = eth1 127.0.0.0/8
bind interfaces only = yes
sudo apt-get install stunnel4
把文件/etc/default/stunnel4中的
ENABLED=1设置为1使能自动启动
准备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
对客户端证书同样操作得到以哈希值命名的证书文件
用于服务端与客户端进行相互的证书认证
内容如下:
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下哈希值命名的证书)来验证对端的证书
手动选择 -> 网络适配器
Microsoft -> Microsoft Loopback Adapter
添加完成后
打开网络和各项中心 -> 更改适配器设置 -> 右击Loopback接口 -> 属性
使用的项目只保留IPv4 -> 进入该项的高级设置 -> 禁用NetBIOS
设置Loopback接口IP为10.0.0.1
关闭共享服务
控制面板 -> 管理工具 -> 服务
禁用server服务
以便stunnel可以监听445端口
重启电脑
下载installer.exe安装
内容如下:
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 the peer against a locally installed certificate.
不但会使用CA验证对端证书的有效性(同level2,可以有效避免中间人攻击)
还会验证CApath是否存在一份对端证书的拷贝(避免证书滥用,因为CA颁发的证书中不一定都是用来连接stunnel的)
双方都使用verify = 3进行互相认证
参考
https://www.stunnel.org/static/stunnel.html https://www.stunnel.org/pipermail/stunnel-users/2013-September/004337.html https://www.stunnel.org/downloads.html http://blog.csdn.net/zahuopuboss/article/details/8664446 https://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-ubuntu https://wiki.netbsd.org/tutorials/how_to_secure_samba_with_stunnel/
客户端windows 7
服务端ubuntu
以下在ubuntu server上操作samba的设置
在配置文件中限制只服务内网接口和lointerfaces = eth1 127.0.0.0/8
bind interfaces only = yes
stunnel的安装
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 = 3Verify the peer against a locally installed certificate.
不但会使用CA验证对端证书的有效性(同level2,可以有效避免中间人攻击)
还会验证CApath是否存在一份对端证书的拷贝(避免证书滥用,因为CA颁发的证书中不一定都是用来连接stunnel的)
双方都使用verify = 3进行互相认证
参考
https://www.stunnel.org/static/stunnel.html https://www.stunnel.org/pipermail/stunnel-users/2013-September/004337.html https://www.stunnel.org/downloads.html http://blog.csdn.net/zahuopuboss/article/details/8664446 https://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-ubuntu https://wiki.netbsd.org/tutorials/how_to_secure_samba_with_stunnel/
相关文章推荐
- 使用数字证书技术来保证WCF传输中的数据加密
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
- 使用X.509数字证书加密解密实务(二)-- 使用RSA证书加密敏感数据
- 邮件传输代理程序sendmail-基本配置 证书 邮件加密 认证 推荐
- 最适合加密敏感数据的算法。每次传输的数据都不一样,即使黑客都头疼额。使用了md5加密。
- SSL使用windows证书库中证书实现双向认证
- 使用X.509数字证书加密解密实务(二)-- 使用RSA证书加密敏感数据
- SSL使用windows证书库中证书实现双向认证
- 使用X.509数字证书加密解密实务(二)-- 使用RSA证书加密敏感数据
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据(转)
- 通过双向证书认证使用 gSOAP 访问 web services
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据(转)
- 使用X.509数字证书加密解密实务(二)-- 使用RSA证书加密敏感数据
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
- 不制作证书是否能加密SQLSERVER与客户端之间传输的数据?
- 使用X.509数字证书加密解密实务(二)-- 使用RSA证书加密敏感数据(转)
- 《Apache数据传输加密、证书的制作》——涉及HTTPS协议