1--TEST--
2openssl_spki_verify() tests for valid signature
3--INI--
4error_reporting=0
5--SKIPIF--
6<?php
7if (!extension_loaded("openssl")) die("skip");
8?>
9--FILE--
10<?php
11
12/* array of private key sizes to test */
13$key_sizes = array(1024, 2048, 4096);
14$pkeys = array();
15foreach ($key_sizes as $key_size) {
16    $key_file = "file://" . dirname(__FILE__) . "/private_rsa_" . $key_size . ".key";
17    $pkeys[] = openssl_pkey_get_private($key_file);
18}
19
20
21/* array of available hashings to test */
22$algo = array(
23    OPENSSL_ALGO_SHA1,
24    OPENSSL_ALGO_SHA224,
25    OPENSSL_ALGO_SHA256,
26    OPENSSL_ALGO_SHA384,
27    OPENSSL_ALGO_SHA512,
28    OPENSSL_ALGO_RMD160
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_verify(preg_replace('/SPKAC=/', '', $spkac)));
38        var_dump(openssl_spki_verify($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--EXPECT--
53bool(true)
54bool(false)
55bool(true)
56bool(false)
57bool(true)
58bool(false)
59bool(true)
60bool(false)
61bool(true)
62bool(false)
63bool(true)
64bool(false)
65bool(true)
66bool(false)
67bool(true)
68bool(false)
69bool(true)
70bool(false)
71bool(true)
72bool(false)
73bool(true)
74bool(false)
75bool(true)
76bool(false)
77bool(true)
78bool(false)
79bool(true)
80bool(false)
81bool(true)
82bool(false)
83bool(true)
84bool(false)
85bool(true)
86bool(false)
87bool(true)
88bool(false)
89