1--TEST-- 2openssl_csr_export_to_file() tests 3--EXTENSIONS-- 4openssl 5--SKIPIF-- 6<?php 7if (!defined("OPENSSL_KEYTYPE_DSA")) die("skip DSA disabled"); 8?> 9--FILE-- 10<?php 11$csrfile = __DIR__ . "/openssl_csr_export_to_file_csr.tmp"; 12$wrong = "wrong"; 13$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'; 14$phex = 'dcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61e' . 15 'f75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d268370557' . 16 '7d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e382' . 17 '6634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22c583ab'; 18$dh_details = array('p' => $phex, 'g' => '2'); 19$dh = openssl_pkey_new(array( 20 'dh'=> array('p' => hex2bin($phex), 'g' => '2')) 21); 22 23$dn = array( 24 "countryName" => "BR", 25 "stateOrProvinceName" => "Rio Grande do Sul", 26 "localityName" => "Porto Alegre", 27 "commonName" => "Henrique do N. Angelo", 28 "emailAddress" => "hnangelo@php.net" 29); 30 31$args = array( 32 "digest_alg" => "sha256", 33 "private_key_bits" => 2048, 34 "private_key_type" => OPENSSL_KEYTYPE_DSA, 35 "encrypt_key" => true, 36 "config" => $config, 37); 38 39$privkey_file = 'file://' . __DIR__ . '/private_rsa_2048.key'; 40$csr = openssl_csr_new($dn, $privkey_file, $args); 41var_dump(openssl_csr_export_to_file($csr, $csrfile)); 42var_dump(file_get_contents($csrfile)); 43 44var_dump(openssl_csr_export_to_file($wrong, $csrfile)); 45 46try { 47 openssl_csr_export_to_file($dh, $csrfile); 48} catch (TypeError $e) { 49 echo $e->getMessage(), "\n"; 50} 51var_dump(openssl_csr_export_to_file($csr, $csrfile, false)); 52?> 53--CLEAN-- 54<?php 55$csrfile = __DIR__ . "/openssl_csr_export_to_file_csr.tmp"; 56if (file_exists($csrfile)) { 57 unlink($csrfile); 58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0/eHrKvG9wBZu28FdS54xoWGeD1NGraW24 79-----END CERTIFICATE REQUEST----- 80" 81 82Warning: openssl_csr_export_to_file(): X.509 Certificate Signing Request cannot be retrieved in %s on line %d 83bool(false) 84openssl_csr_export_to_file(): Argument #1 ($csr) must be of type OpenSSLCertificateSigningRequest|string, OpenSSLAsymmetricKey given 85bool(true) 86