我是 openssl 的新手,我从 openssl 下载了 openssl-fips-2.0.1 代码,但是,我无法跟踪文档和安全策略中所述的 FIPS_mode_set() 的定义。然而,我确实在 fips.c 中找到了 fips_set_mode() ,但它们并不是指同一个,对吗?
定义在哪里? 请给我建议。
最佳答案
FIPS_mode_set() code not found in openssl package
你必须知道如何提问...
openssl-1.0.1f$ grep -R FIPS_mode_set *
apps/openssl.c: if (!FIPS_mode_set(1)) {
CHANGES: *) Functions FIPS_mode_set() and FIPS_mode() which call the underlying
crypto/cpt_err.c:{ERR_FUNC(CRYPTO_F_FIPS_MODE_SET), "FIPS_mode_set"},
crypto/evp/evp_cnf.c: if (!FIPS_mode() && !FIPS_mode_set(1))
crypto/crypto.h:int FIPS_mode_set(int r);
crypto/o_fips.c:int FIPS_mode_set(int r)
Binary file fips_premain_dso matches
ssl/ssltest.c: if(!FIPS_mode_set(1))
util/libeay.num:FIPS_mode_set 3253 EXIST::FUNCTION:
openssl-1.0.1f$
声明位于crypto/crypto.h
中,定义位于crypto/o_fips.c
中。以下来自 o_fips.c
:
int FIPS_mode_set(int r)
{
OPENSSL_init();
#ifdef OPENSSL_FIPS
#ifndef FIPS_AUTH_USER_PASS
#define FIPS_AUTH_USER_PASS "Default FIPS Crypto User Password"
#endif
if (!FIPS_module_mode_set(r, FIPS_AUTH_USER_PASS))
return 0;
if (r)
RAND_set_rand_method(FIPS_rand_get_method());
else
RAND_set_rand_method(NULL);
return 1;
#else
if (r == 0)
return 1;
CRYPTOerr(CRYPTO_F_FIPS_MODE_SET, CRYPTO_R_FIPS_MODE_NOT_SUPPORTED);
return 0;
#endif
}
<小时/>
如果您正在寻找 FIPS_mode_set
通过特殊设置进入“FIPS 模式”或切换某些算法,则此步骤不会发生这种情况。
链接时会更早发生。在幕后发生的事情是,fipsld
是您的编译器,它会查找 LD
的调用。如果LD
没有被调用,那么fipsld
只会调用你的常规编译器(可能是/usr/bin/gcc
) 。如果它看到LD
的调用,那么它会做三件事。
首先,它编译fips_premin.c
。然后,它调用真正的 ld 来执行与所有目标文件及其生成的 fips_premain.o 的最终链接。最后,它调用incore
交换FIPS对象模块,计算相关text
和data
的签名(相关是指FIPS代码和数据),然后将签名嵌入到可执行文件中。
签名是使用 HMAC 生成的, key 嵌入在可执行文件中。它没有什么特别的,并且它在世界各地的所有可执行文件中都是不变的。这是使用的 key :etaonrishdlcupfm
。
如果您在构建可执行文件时没有采取特殊步骤,那么您可能会遗漏一些步骤。以下是使用 fipsld
和 incore
的步骤:
$ export CC=`find /usr/local -name fipsld`
$ echo $CC
/usr/local/ssl/fips-2.0/bin/fipsld
$ export FIPSLD_CC=`find /usr/bin -name gcc`
$ echo $FIPSLD_CC
/usr/bin/gcc
现在,进行标准的config
和make
。有时您必须执行config
,然后调整CC
和FIPSLD_CC
,然后运行make
,因为某些 config
文件在安排上令人窒息。有时您必须在 config
之后打开 Makefile
并将 CC
更改为 /usr/local/ssl/fips-2.0/bin/fipsld
。有很多方法可以解决特定的包装问题。
如果您根据安全策略构建 FIPS 对象模块,I downloaded openssl-fips-2.0.1 codes from openssl, however, I was not able to trace to the definition of FIPS_mode_set()
openssl-fips-NNN
会提供 FIPS 验证的加密。您可以找到OpenSSL FIPS 1402- Security Policy at here .
如果您所做的只是下载并构建 openssl-fips-NNN
,那么您可能没有使用 FIPS 验证的加密技术。有一个程序需要遵循,其中包括获取源代码的“可信”副本。您可以下载并验证签名,但需要一个经过 FIPS 验证的签名检查器,这会产生先有鸡还是先有蛋的问题,因为您无法从源代码构建它。因此,实际的解决方案是从 OpenSSL 基金会订购 CD。这很奇怪,但却是事实。例如,参见 OpenSSL FIPS User Guide或OpenSSL FIPS Security Policy ,附录 B,受控分发文件指纹。
构建并安装 FIPS 对象模块后,您可以构建该库的支持 FIPS 的版本。支持 FIPS 的 OpenSSL 将使用 FIPS 对象模块(如果可用)。将其视为“可插入”架构。
该库的支持 FIPS 的版本就是 openssl-NNN
,例如 openssl-1.0.1e
和 openssl-1.0.1f
。这是您所了解和喜爱的。
您还可以考虑使用诸如 ctags
这样的源代码浏览器来帮助您查找内容并跳转。请参阅Exuberant Ctags在 Sourceforge 上。
关于c - 在 openssl 包中找不到 FIPS_mode_set() 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20689732/