美文网首页
openssl 3.0与FIPS

openssl 3.0与FIPS

作者: CodingCode | 来源:发表于2023-09-22 03:28 被阅读0次

openssl配置的几个概念

openssl.conf

.include /path/to/fipsmodule.cnf

[openssl_init]
providers = provider_sect
alg_section = alg_sect

[provider_sect]
default = default_sect
fips = fips_sect

[default_sect]
activate = 0

[alg_sect]
default_properties = fips=yes

/path/to/fipemodule.cnf

[fips_sect]
activate = 1
conditional-errors = 1
security-checks = 1
module-mac = 12:F1:...:67:03

一个概念provider,和algrithm:

  1. 一个provider是一组algrithm的合集,也包括一些provider内属性。
  2. 例子里有两个provider:default和fips
  3. fips这个provider自动具有"fips=yes"的属性,但是default这个provider自动具有的属性是”fips=no"。
    3.1 也可以通过程序OSSL_PROVIDER_load/OSSL_PROVIDER_unload来加载和卸载一个provider。
  4. provider的属性activate=1表示是否可以用available。即OSSL_PROVIDER_available()返回true或者false。
    4.1:但是default这个provider的activate属性无效,它总是available的。
  5. alg_sect里的default_properties表示algritmh的缺省查找provider属性,其中前缀default_表示缺省的意思,不是表示default这个provider。
    5.1 简单的说,就是用户要查找一个algrithm时,如果没有指定从哪个provider里面查找(通过提供provider属性的方法),那么就使用这里定义的属性来表示从哪一个provider里面查找。

给一个程序例子

    char * providernames[] = {"default", "fips"};
    for (int i = 0; i < 2; i++) {
        printf("Provider %s: %s\n", providernames[i], OSSL_PROVIDER_available(NULL, providernames[i]) == 1 ? "available" : "unavailable");
    }

判断一个provider是否可用,如果在配置文件里activate=1表示可用,activate=0表示不可用。
当然default这个provider除外,它总是可以,不管activate的值。

    OSSL_PROVIDER* provider = OSSL_PROVIDER_load(NULL, "fips");
    if (provider == NULL) {
        printf("Load provider '%s' failed\n", providername);
    } else {
        printf("Load provider '%s' succes\n", providername);
    }

    ...
    OSSL_PROVIDER_unload(provider);

加载和卸载一个provider。

    int fips_default_enable = EVP_default_properties_is_fips_enabled(NULL);
    printf("FIPS default enabled=%d/%s\n", fips_default_enable, fips_default_enable == 1 ? "true": "false");

检查FIPS defaut enable属性,这个值就是配置文件里的[alg_sect]节下的default_properties = fips=yes属性值。这个值也可以通过程序修改:

    if (!EVP_default_properties_enable_fips(NULL, 1)) {
        printf("Failed to sett default fips enable\n");
    }

下面获取algrithim

        md = EVP_MD_fetch(NULL, "SHA256", NULL);
        if (md == NULL) {
            printf("Provider is %s\n", "NULL");
        } else {
            printf("Provider is %s\n", OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(md)));
        }

这个地方能获取是从那个provider里面取得algrithm,比如'default', 还是'fips'。

举例来说:

ID [alg_sect]default_properties = fips=no [alg_sect]default_properties = fips=yes
EVP_MD_fetch(NULL, "MD5", NULL) default NULL
EVP_MD_fetch(NULL, "SHA256", NULL) default fips
EVP_MD_fetch(NULL, "MD5", "fips=no") default default
EVP_MD_fetch(NULL, "SHA256", "fips=no") default default
EVP_MD_fetch(NULL, "MD5", "fips=yes") NULL NULL
EVP_MD_fetch(NULL, "SHA256", "fips=yes") fips FIPS

结论:
EVP_MD_fetch如果参数指定了provider属性(fips=yes)那么具有高优先权。

  • fips=no那么就从default这个provider里面取,因为default这个provider的fips=no。
  • fips=yes那么就从fips这个provider里面取,因为fips这个provider的fips=yes。
  • fips没指定,那么从algrithm指定的属性里面查询:
    • default_properties = fips=no,表示缺省找default这个provider
    • default_properties = fips=yes, 表示缺省找fips这个provider。

相关文章

网友评论

      本文标题:openssl 3.0与FIPS

      本文链接:https://www.haomeiwen.com/subject/qsftbdtx.html