]> granicus.if.org Git - php/commitdiff
Add openssl_csr_get_public_key test
authorJakub Zelenka <bukka@php.net>
Mon, 30 Oct 2017 14:28:18 +0000 (14:28 +0000)
committerJakub Zelenka <bukka@php.net>
Mon, 30 Oct 2017 16:40:56 +0000 (16:40 +0000)
ext/openssl/tests/openssl_csr_get_public_key_basic.phpt [new file with mode: 0644]

diff --git a/ext/openssl/tests/openssl_csr_get_public_key_basic.phpt b/ext/openssl/tests/openssl_csr_get_public_key_basic.phpt
new file mode 100644 (file)
index 0000000..e8a9b7a
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+openssl_csr_get_public_key() tests
+--SKIPIF--
+<?php
+if (!extension_loaded("openssl")) die("skip");
+?>
+--FILE--
+<?php
+$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf';
+$phex = 'dcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61e' .
+               'f75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d268370557' .
+               '7d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e382' .
+               '6634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22c583ab';
+$dh_details = array('p' => $phex, 'g' => '2');
+$dh = openssl_pkey_new(array(
+       'dh'=> array('p' => hex2bin($phex), 'g' => '2'))
+);
+
+$dn = array(
+       "countryName" => "BR",
+       "stateOrProvinceName" => "Rio Grande do Sul",
+       "localityName" => "Porto Alegre",
+       "commonName" => "Henrique do N. Angelo",
+       "emailAddress" => "hnangelo@php.net"
+);
+
+$args = array(
+       "digest_alg" => "sha1",
+       "private_key_bits" => 2048,
+       "private_key_type" => OPENSSL_KEYTYPE_DSA,
+       "encrypt_key" => true,
+       "config" => $config,
+);
+
+$privkey_file = 'file://' . dirname(__FILE__) . '/private_rsa_2048.key';
+$csr = openssl_csr_new($dn, $privkey_file, $args);
+$csr_file = file_get_contents(dirname(__FILE__) . '/cert.csr');
+
+var_dump(openssl_csr_get_public_key($csr));
+var_dump(openssl_csr_get_public_key($csr_file));
+?>
+--EXPECTF--
+resource(%d) of type (OpenSSL key)
+resource(%d) of type (OpenSSL key)