Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么PythonMD5在FIPS模式下可用?_Python_Python 3.x_Openssl_Fips - Fatal编程技术网

为什么PythonMD5在FIPS模式下可用?

为什么PythonMD5在FIPS模式下可用?,python,python-3.x,openssl,fips,Python,Python 3.x,Openssl,Fips,首先,我验证我的openssl是否正确(使用FIPS支持编译) 在正常模式下: # echo -n 123456 | openssl md5 (stdin)= e10adc3949ba59abbe56e057f20f883e 在FIPS模式下: # echo -n 123456 | OPENSSL_FIPS=1 openssl md5 Error setting digest md5 139993634896640:error:060A80A3:digital envelope routine

首先,我验证我的openssl是否正确(使用FIPS支持编译)

在正常模式下:

# echo -n 123456 | openssl md5
(stdin)= e10adc3949ba59abbe56e057f20f883e
在FIPS模式下:

# echo -n 123456 | OPENSSL_FIPS=1 openssl md5
Error setting digest md5
139993634896640:error:060A80A3:digital envelope routines:FIPS_DIGESTINIT:disabled for fips:fips_md.c:180:
>>> import ssl
>>> ssl.FIPS_mode_set(1)
>>> ssl.FIPS_mode()
1
>>> import hashlib
>>> 
>>> m = hashlib.md5()
>>> m.update(b"Nobody inspects")
>>> m.digest()
b'>\xf7)\xcc\xf0\xccV\x07\x9c\xa5F\xd5\x80\x83\xdc\x12'
正如所料

现在我想验证python的行为是否也符合预期

我使用FIPS模式支持编译了python 3.6:

# ./python 
Python 3.6.8 (tags/v3.6.8-dirty:3c6b436a57, Apr 11 2019, 08:44:38) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.2q-fips  20 Nov 2018'
我将其设置为FIPS模式:

# echo -n 123456 | OPENSSL_FIPS=1 openssl md5
Error setting digest md5
139993634896640:error:060A80A3:digital envelope routines:FIPS_DIGESTINIT:disabled for fips:fips_md.c:180:
>>> import ssl
>>> ssl.FIPS_mode_set(1)
>>> ssl.FIPS_mode()
1
>>> import hashlib
>>> 
>>> m = hashlib.md5()
>>> m.update(b"Nobody inspects")
>>> m.digest()
b'>\xf7)\xcc\xf0\xccV\x07\x9c\xa5F\xd5\x80\x83\xdc\x12'
现在我尝试验证它是否在FIPS模式下运行:

# echo -n 123456 | OPENSSL_FIPS=1 openssl md5
Error setting digest md5
139993634896640:error:060A80A3:digital envelope routines:FIPS_DIGESTINIT:disabled for fips:fips_md.c:180:
>>> import ssl
>>> ssl.FIPS_mode_set(1)
>>> ssl.FIPS_mode()
1
>>> import hashlib
>>> 
>>> m = hashlib.md5()
>>> m.update(b"Nobody inspects")
>>> m.digest()
b'>\xf7)\xcc\xf0\xccV\x07\x9c\xa5F\xd5\x80\x83\xdc\x12'
为什么在FIPS模式下允许使用
md5

编辑 我已经验证了python正在使用
openssl
实现:

>>> hashlib.md5
<built-in function openssl_md5>
hashlib.md5
我找到了解决方案。我对Python补丁做了一些更改

问题是,hashlib要求OpenSSL提供所要求的算法。它拒绝md5。然后,它切换到md5的默认实现。我为此做了一个python补丁

见GitHub要点。

另一个问题是,即使你这样做。另一个开发人员可以安装加密模块,该模块公开直接与Openssl通信的低级库。 需要专门为此构建加密模块


请参阅

“因为
hashlib
ssl
没有什么关系……?
md5()
通常也可用,但如果您使用的是一种罕见的“符合FIPS标准”的Python构建,它可能会丢失。”您不能使用运行时设置切换“FIPS兼容版本”。@deceze hashlib使用openssl实现(如果可用,在我的系统中就是这样)。在FIPS模式下运行时,openssl将拒绝执行md5。因此,python md5也应该失败。@deceze下面是相关的代码:但是,
md5
\u始终支持的
列表中,似乎不依赖于任何
ssl
运行时设置…