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