ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python-如何将质询密码编码为证书请求

2019-11-20 08:51:15  阅读:313  来源: 互联网

标签:openssl c-3 linux python


我正在使用linux版本openssl req生成带有质询密码的csr,一切正常,除非它无法打印此属性:

# openssl req -new -key private.key -out server.csr 
# openssl req -in server.csr -noout -text
  Certificate Request: ...
         Attributes:
             challengePassword        :unable to print attribute ...

我在fedora中使用OpenSSL 1.0.1j进行了测试,而在ubuntu中使用OpenSSL 1.0.1进行了测试,两者都无法将ChallengePassword写入csr文件.

但是如果我使用Windows版本,它可以工作:

# openssl req -in test.csr -noout -text
  Certificate Request:
  ...
        Attributes:
            challengePassword        :00F7FC7937B5366F2231AC891472998C


我正在使用SCEP tool的64位openssl:

然后我搜索了openssl文件,发现了这句话:

attributes

this specifies the section containing any request attributes: its
format is the same as distinguished_name. Typically these may contain
the
challengePassword or unstructuredName types. They are currently ignored by OpenSSL’s request signing utilities but some CAs might want
them
.

是的,某些CA可能需要它们.我正在使用NDES Windows 2008 R2,它需要质询密码,看起来它不能由openssl req应用程序生成,我可以使用openssl C API还是python / perl?还是我需要修复openssl代码?

我还在sscep问题列表上问了这个问题,他们告诉我我需要将质询密码编码为BMPString.但是我不知道如何编码.有人可以给我指导吗?

解决方法:

让我自己回答我的问题.

要在CSR中启用质询密码属性,我们需要编写ASN可打印字符串,但是默认情况下,openssl req实用程序将写入MBSTRING_ASC字符串,因此它始终返回“:unable to print attribute …”.

这是C代码示例:

将MBSTRING_ASC字符串转换为ASN1_PRINTABLESTRING:

ASN1_STRING *tmp_os = M_ASN1_PRINTABLESTRING_new();
tmp_os->type = V_ASN1_PRINTABLESTRING;
int password_length = strlen(challenge_password);
ASN1_STRING_set(tmp_os, (const unsigned char *)challenge_password, password_length);

向请求添加属性:

X509_REQ_add1_attr_by_NID(req, NID_pkcs9_challengePassword, tmp_os->type, tmp_os->data, password_length);

标签:openssl,c-3,linux,python
来源: https://codeday.me/bug/20191120/2042887.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有