1--TEST--
2openssl_spki_export_challenge() tests for exporting challenge
3--INI--
4error_reporting=0
5--SKIPIF--
6<?php
7if (!extension_loaded("openssl")) die("skip");
8if (!@openssl_pkey_new()) die("skip cannot create private key");
9?>
10--FILE--
11<?php
12
13/* array of private key sizes to test */
14$key_sizes = array(1024, 2048, 4096);
15$pkeys = array();
16foreach ($key_sizes as $key_size) {
17    $key_file = "file://" . __DIR__ . "/private_rsa_" . $key_size . ".key";
18    $pkeys[] = openssl_pkey_get_private($key_file);
19}
20
21
22/* array of available hashings to test */
23$algo = array(
24    OPENSSL_ALGO_MD4,
25    OPENSSL_ALGO_MD5,
26    OPENSSL_ALGO_SHA1,
27    OPENSSL_ALGO_SHA224,
28    OPENSSL_ALGO_SHA256,
29    OPENSSL_ALGO_SHA384,
30    OPENSSL_ALGO_SHA512,
31    OPENSSL_ALGO_RMD160
32);
33
34/* loop over key sizes for test */
35foreach ($pkeys as $pkey) {
36
37    /* loop to create and verify results */
38    foreach ($algo as $value) {
39        $spkac = openssl_spki_new($pkey, _uuid(), $value);
40        var_dump(openssl_spki_export_challenge(preg_replace('/SPKAC=/', '', $spkac)));
41        var_dump(openssl_spki_export_challenge($spkac  . 'Make it fail'));
42    }
43}
44
45/* generate a random challenge */
46function _uuid() {
47    return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff),
48        mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000,
49        mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff),
50        mt_rand(0, 0xffff), mt_rand(0, 0xffff));
51}
52
53
54?>
55--EXPECTREGEX--
56string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
57bool\(false\)
58string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
59bool\(false\)
60string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
61bool\(false\)
62string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
63bool\(false\)
64string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
65bool\(false\)
66string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
67bool\(false\)
68string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
69bool\(false\)
70string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
71bool\(false\)
72string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
73bool\(false\)
74string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
75bool\(false\)
76string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
77bool\(false\)
78string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
79bool\(false\)
80string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
81bool\(false\)
82string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
83bool\(false\)
84string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
85bool\(false\)
86string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
87bool\(false\)
88string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
89bool\(false\)
90string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
91bool\(false\)
92string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
93bool\(false\)
94string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
95bool\(false\)
96string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
97bool\(false\)
98string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
99bool\(false\)
100string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
101bool\(false\)
102string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\"
103bool\(false\)
104