xref: /PHP-5.4/ext/openssl/tests/bug55646.phpt (revision 428ef230)
1--TEST--
2Bug #55646: textual input in openssl_csr_new() is not expected in UTF-8
3--SKIPIF--
4<?php
5if (!function_exists('openssl_csr_new'))
6	die('skip no openssl extension');
7--FILE--
8<?php
9function stringAsHex($string){$unpacked = unpack("H*", $string);return implode(" ", str_split($unpacked[1],2));}
10
11$config = array("digest_alg" => "sha1","x509_extensions" => "v3_ca","req_extensions" => "v3_req","private_key_bits" => 2048,"private_key_type" => OPENSSL_KEYTYPE_RSA,"encrypt_key" => false,);
12$csr_info = array(
13  "countryName" => "US",
14  "stateOrProvinceName" => "Utah",
15  "localityName" => "Lindon",
16  "organizationName" => "Chinese",
17  "organizationalUnitName" => "IT \xe4\xba\x92",
18  "commonName" => "www.example.com",);
19$private = openssl_pkey_new($config);
20while (openssl_error_string()) {}
21$csr_res = openssl_csr_new($csr_info, $private,
22	['config' => __DIR__."/openssl.cnf"]);
23if (!$csr_res) {
24	while ($e = openssl_error_string()) { $err = $e; }
25	die("Failed; last error: $err");
26}
27openssl_csr_export($csr_res, $csr);
28$output = openssl_csr_get_subject($csr);
29
30echo "A: ".$csr_info["organizationalUnitName"]."\n";
31echo "B: ".stringAsHex($csr_info["organizationalUnitName"])."\n";
32echo "C: ".$output['OU']."\n";
33echo "D: ".stringAsHex($output['OU'])."\n";
34--EXPECT--
35A: IT 互
36B: 49 54 20 e4 ba 92
37C: IT 互
38D: 49 54 20 e4 ba 92
39