如何在openssl中使用utf8主题创建CSR?

SWi*_*ilk 13 openssl utf-8 csr

我正在尝试使用UTF-8主题生成证书签名请求.

$ openssl req  -utf8 -nodes -newkey rsa:2048 -keyout my.private_key.pem -out my.csr.pem -text
Generating a 2048 bit RSA private key
......................................................................................................................................................................+++
......+++
writing new private key to 'my.private_key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [PL]:
State or Province Name (full name) []:Za?ó?? g??l? ja??
problems making Certificate Request
12376:error:0D07A07C:asn1 encoding routines:ASN1_mbstring_ncopy:illegal characters:a_mbstr.c:162:
Run Code Online (Sandbox Code Playgroud)

终端编码是UTF-8,当我使用命令行主题时,我遇到同样的问题 (...) -subj /C=PL/ST=za?ó??\ g??l?\ ja??/O=my-company/CN=ThisIsMeForSure

当我跳过-utf8开关时,生成CSR时所有非ascii字符都用十六进制表示法替换(例如ó变为\xC3\xB3).使用php(openss_x509_parse)无法正确读取此类CSR - 原始内容ó被读取为四个字节,代表两个奇怪的字符......

我究竟做错了什么?

Env*_*vek 19

我在命令方面取得了成功

openssl req -new -utf8 -nameopt multiline,utf8 -config example.com.cnf -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr
Run Code Online (Sandbox Code Playgroud)

example.com.cnfUTF-8中的配置文件在哪里:

[req]
prompt = no
distinguished_name = dn
req_extensions = ext

[dn]
CN = ???????? ?????                # Site description
emailAddress = envek@envek.name
O = ??? ????????                   # My company
OU = ??? ?????????????             # My dept
L = ??????                         # Moscow
C = RU

[ext]
subjectAltName = DNS:example.com,DNS:*.example.com
Run Code Online (Sandbox Code Playgroud)

在Chrome,Firefox和Safari中正确显示.

  • 实际上,-nameopt multiline,utf8选项在此上下文中是无用的.只有-utf8才有所作为.用户仍然可以使用正确的配置文件避免在命令行上设置此选项.只需在[req]部分添加utf8 = yes即可.这应该是首选方法,因为忘记命令行上的-utf8选项可能会导致意外结果.显示证书时,需要使用-nameopt utf8选项,-nameopt multiline,utf8选项使我忽略utf8值.OpenSSL版本1.0.2h. (5认同)
  • 我单独确认`-utf8`选项就足够了.`openssl req -new -newkey rsa:2048 -sha256 -nodes -utf8 -subj"/ C = JP/ST =大阪府/ L =大阪市/ O =架空の会社名の例/ OU =あ/ CN = www .example.jp"-out ./clients/$client_domain/$client_domain.csr.pem -keyout./ clients/$ client_domain/$ client_domain.key.pem`` $ dpkg-query -W -f ='$ {Version } \n'openssl` 1.0.2g-1ubuntu4.5谢谢,Achille! (3认同)

ele*_*gin 2

尝试使用 string_mask 选项:

字符串掩码

此选项屏蔽某些字段中某些字符串类型的使用。大多数用户不需要更改此选项。

它可以设置为多个值,默认值也是默认选项使用 PrintableStrings、T61Strings 和 BMPStrings,如果使用 pkix 值,则仅使用 PrintableStrings 和 BMPStrings。这遵循 RFC2459 中的 PKIX 建议。如果使用 utf8only 选项,则仅使用 UTF8Strings:这是 2003 年之后 RFC2459 中的 PKIX 建议。最后,nombstr 选项仅使用 PrintableStrings 和 T61Strings:某些软件在使用 BMPStrings 和 UTF8Strings 时存在问题:特别是 Netscape。

  • 显然这个 (string_mask) 是不够的。(这实际上为字符提供了 UTF-8 代码,但在许多工具中显示时并不以这种方式处理它们)。`-utf8` 或 `utf8 = yes` 是正确的选择。(凭经验检查)。 (2认同)