3

当我尝试从 chroot 监狱中建立 ssl 连接时,出现以下错误:

twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion.

我正在使用带有 pyopenssl 的 openssl 0.9.6 来建立 ssl 连接,并且我在 Linux (centos 5.5) 上使用了用于 python 2.4 的扭曲 python 库。

经过一些故障排除后,我发现 openssl 失败是因为它试图读取 /dev/random 文件,而它失败是因为 chroot 中没有 /dev/random。我已经确认,如果我在 chroot 中创建 /dev/random 文件,则连接成功。

  • 我曾考虑在我的 chroot 中安装包含 /dev/random 文件的 devfs 文件系统,但我的应用程序及其系统管理员有一个坏习惯,即在不先卸载所有内容的情况下删除 chroot 的根目录。
  • 我考虑过在执行 chroot 之前从 /dev/random 文件中读取,但我当前的设置是在我的二进制文件启动之前调用 chroot,并且更改 chroot 发生的位置将是应用程序中的一个太大的变化我不确定何时或如何完成。
  • 我曾想过在我的 chroot 监狱之外运行一个程序,它只是从 /dev/random 读取并写入一个名为 /jail/dev/random 的命名文件管道,可以从 chroot 监狱内部访问,但我不喜欢必须运行一个单独的进程只是为了访问随机源。此外,仅初始化 openssl 似乎过于复杂。

如果我无法从我的程序访问 /dev/random,那么初始化 openssl 的正确方法是什么?

4

3 回答 3

4

您可以为 openssl 伪造随机数,例如命令行 openssl:

[root@quilt /]# openssl s_client -h
usage: s_client args
...
 -rand file:file:...
...

无论如何,openssl 需要一个随机源,如果没有随机随机数,它就不可能是安全的,例如来自维基百科:

为了生成用于安全连接的会话密钥,客户端使用服务器的公钥加密一个随机数并将结果发送到服务器。只有服务器应该能够使用其私钥对其进行解密。

如果没有随机性来源,SSL/TLS 很容易被黑客入侵。

如果您担心chroot/dev/会被删除,为什么不只创建chroot/dev/random或不chroot/dev/urandom安装整个开发?

[root@quilt /]# mknod /dev/random c 1 8
[root@quilt /]# mknod /dev/urandom c 1 9

哦,顺便说一句,您还想复制系统 /etc/resolv.conf 以及可能的其他主机、服务、ethers 等...

于 2012-03-20T06:29:36.707 回答
3

也许更好的方法是绑定安装设备文件,如下所示:

# touch chroot/dev/random
# mount --bind /dev/random chroot/dev/random

和 urandom 一样。

于 2014-12-27T11:57:39.217 回答
0

创建 urandom 和 random 后不要忘记 SELinux

cat /var/log/messages | grep "SELinux 正在阻止"

SELinux is preventing /usr/sbin/php-fpm from read access on the chr_file urandom.

If you believe that php-fpm should be allowed read access on the urandom chr_file by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do allow this access for now by executing:

ausearch -c 'php-fpm' --raw

audit2allow -M my-phpfpm

semodule -i my-phpfpm.pp

于 2019-09-17T15:46:40.017 回答