gpt4 book ai didi

ssl - 从 RSA key 生成 PKCS#12 key 的问题

转载 作者:行者123 更新时间:2023-12-04 22:41:15 25 4
gpt4 key购买 nike

我有一组用于测试的 RSA key 。我正在对 PKCS#12 进行增强。现有的 RSA key 都有密码,比如说“mypass”。我想生成三种类型的 PKCS#12 key :

  • PKCS#12 信封上没有密码(如果您阅读 this 实际上是空字符串),
  • 内的 RSA key 上没有密码
  • PKCS#12 信封上的密码,
  • 内的 RSA key 上没有密码
  • PKCS#12 信封和
  • 内的 RSA key 上的密码

    我在使用第一个选项类别时遇到问题

    在这里,我将 PEM 格式的源 key 复制到我的工作区并创建一个以字母 d 为前缀的解密版本. $tkey是 PEM 格式的输入键。
    echo RSA keys PEM formatted
    key=${name}.priv.rsa.pem
    dkey=d${name}.priv.rsa.pem
    pubkey=${name}.pub.rsa.pem
    cp $tkey ./${key}
    openssl rsa -in $key -passin pass:mypass -out $dkey -outform pem -passout pass:

    我认为解密的 key 上没有密码,因为当我使用它来签署一些数据时,openssl 不会提示我输入密码。

    我执行以下操作来生成我的 PKCS#12 key (其中 $tcert 是输入 key 证书的路径)。
    tcert=`dirname $tkey`/${name}.crt
    key=${name}.priv.p12
    echo PKCS#12 envelope without password and unencrypted RSA key
    openssl pkcs12 -export -inkey $dkey -in $tcert -out d$key -name d$name -passout pass:
    echo PKCS#12 envelope with password and unencrypted RSA key
    openssl pkcs12 -export -inkey $dkey -in $tcert -out x$key -name $name -passout pass:mypass
    echo PKCS#12 envelope with password and password protected RSA key
    openssl pkcs12 -export -inkey $tkey -in $tcert -out $key -name $name -passout pass:mypass -passin pass:mypass

    然后我检查每个键执行以下操作(根据需要添加 mypass)。当我去显示 d key ,它要求我输入 RSA key 的密码。如果我输入“mypass”,它会转储 key 。
    openssl pkcs12 -info -in $dkey -passin pass:

    由于上面是脚本,我让脚本回显这些行,以便我可以确定它使用的是正确的文件等。

    我显然做错了什么,但我没有看到。

    最佳答案

    我错了需要输入我的旧密码。输入的任何四个字符都有效。这使我查看了在默认 PEM 回调中发现硬编码的 4 个字符要求的代码。

    crypto/pem/pem_lib.c
    #define MIN_LENGTH 4

    int PEM_def_callback(char *buf, int num, int rwflag, void *userdata)
    {
    int i, min_len;
    const char *prompt;

    /* We assume that the user passes a default password as userdata */
    if (userdata) {
    i = strlen(userdata);
    i = (i > num) ? num : i;
    memcpy(buf, userdata, i);
    return i;
    }

    prompt = EVP_get_pw_prompt();
    if (prompt == NULL)
    prompt = "Enter PEM pass phrase:";

    /*
    * rwflag == 0 means decryption
    * rwflag == 1 means encryption
    *
    * We assume that for encryption, we want a minimum length, while for
    * decryption, we cannot know any minimum length, so we assume zero.
    */
    min_len = rwflag ? MIN_LENGTH : 0;

    i = EVP_read_pw_string_min(buf, min_len, num, prompt, rwflag);
    if (i != 0) {
    PEMerr(PEM_F_PEM_DEF_CALLBACK, PEM_R_PROBLEMS_GETTING_PASSWORD);
    memset(buf, 0, (unsigned int)num);
    return -1;
    }
    return strlen(buf);
    }

    如果我注意错误消息,我会看到“您必须输入 4 到 1024 个字符”。
    Enter PEM pass phrase:
    Error outputting keys and certificates
    139783395758528:error:28078065:UI routines:UI_set_result_ex:result too small:../crypto/ui/ui_lib.c:903:You must type in 4 to 1024 characters
    139783395758528:error:2807106B:UI routines:UI_process:processing error:../crypto/ui/ui_lib.c:543:while reading strings
    139783395758528:error:0906406D:PEM routines:PEM_def_callback:problems getting password:../crypto/pem/pem_lib.c:59:
    139783395758528:error:0907E06F:PEM routines:do_pk8pkey:read key:../crypto/pem/pem_pk8.c:83:

    因此, key 不受密码保护,但调用的回调函数需要四个字符的输入。

    关于ssl - 从 RSA key 生成 PKCS#12 key 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62074281/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com