2013-05-10 81 views
7

我正在嘗試使用UTF-8主題生成證書籤名請求。如何在openssl中使用utf8主題創建CSR?

$ 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: 

終端編碼是UTF-8,I得到了同樣的問題,當我使用命令行受試者 (...) -subj /C=PL/ST=zażółć\ gęślą\ jaźń/O=my-company/CN=ThisIsMeForSure

當我跳過-utf8開關,CSR與替換所有的非ASCII字符產生用十六進制符號(例如ó變成\xC3\xB3)。這樣的CSR無法用php(openss_x509_parse)正確讀取 - 原始的ó被讀爲四個字節,代表兩個奇怪的字符...

我在做什麼錯?

+0

使用'openssl req' * *沒有*自定義conf文件意味着服務器名稱將在'CN'中。 IETF和CA/B論壇都不贊成這種做法。相反,你應該確保服務器名稱(和IP地址)在'SAN'中。例如,請參閱[如何使用openssl創建自簽名證書?](http://stackoverflow.com/a/27931596)(答案用於簽署請求和自簽名證書)。並且在配置文件中設置了'string_mask = utf8only'。 – jww 2015-04-15 12:07:56

回答

1

嘗試使用string_mask選項:

string_mask

此選項屏蔽了使用在某些領域某些字符串類型的。大多數用戶不需要改變這個選項。

它可以設置爲幾個默認值,如果使用pkix值則默認選項使用PrintableStrings,T61Strings和BMPStrings,則只使用PrintableStrings和BMPStrings。這遵循RFC2459中的PKIX建議。 如果使用utf8only選項,那麼只會使用UTF8Strings:這是2003年後RFC2459中的PKIX推薦。最後,nombstr選項只使用PrintableStrings和T61Strings:某些軟件在BMPStrings和UTF8Strings方面存在問題:特別是Netscape。

+2

顯然這(string_mask)是不夠的。 (這實際上給字符提供了UTF-8編碼,但在許多工具中顯示時不會以這種方式處理它們)。 '-utf8'或'utf8 = yes'是要走的路。 (經驗檢查)。 – Cromax 2017-08-08 11:23:42

+0

@Cromax你是對的。你能從評論中回答嗎? – 2017-11-15 16:14:05

+0

@Vlastimil最高評分的答案已經包括'-utf8'開關,所以我不確定是否需要這個。它只是增加了額外的澄清,但沒有什麼重要的。謝謝,你。 – Cromax 2017-11-17 09:09:05

0

任何unicode爲我工作,從PHP文件。

<? shell_exec('openssl req -new -md5 -utf8 -key C:/Temp/1.key -out C:/Temp/1.csr -subj "/C=MD/ST=ff/O=Religie/OU=Cen/CN=中國/[email protected]" -config C:/Temp/openssl.cnf'); ?> 
9

我已經成功地使用命令

openssl req -new -utf8 -nameopt multiline,utf8 -config example.com.cnf -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr 

example.com.cnf是UTF-8的配置文件:

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

[dn] 
CN = Описание сайта    # Site description 
emailAddress = [email protected] 
O = Моя компания     # My company 
OU = Моё подразделение    # My dept 
L = Москва       # Moscow 
C = RU 

[ext] 
subjectAltName = DNS:example.com,DNS:*.example.com 

在Chrome,Firefox和Safari中正確顯示。

+4

實際上,在這種情況下,-nameopt multiline,utf8選項是無用的。只有-utf8正在發揮作用。用戶仍然可以避免使用適當的配置文件在命令行上設置此選項。只需在[req]部分添加utf8 = yes即可。這應該是更喜歡的方式,因爲在命令行上忘記-utf8選項可能會導致不期望的結果。 當顯示證書時,需要使用-nameopt utf8選項,-nameopt multiline,utf8選項使得我忽略utf8的值。 OpenSSL版本1.0.2h。 – Achille 2016-05-29 19:17:53

+2

我確認'-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! – hnakamur 2016-10-24 08:03:22

+0

你沒有給非英語的電子郵件。你有任何具體的理由爲@ Envek? – 2017-04-19 04:36:32