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