bug55646.phpt 1.3 KB

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