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