1--TEST--
2openssl_csr_sign() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$cert = "file://" . dirname(__FILE__) . "/cert.crt";
8$priv = "file://" . dirname(__FILE__) . "/private_rsa_1024.key";
9$wrong = "wrong";
10$pub = "file://" . dirname(__FILE__) . "/public.key";
11$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf';
12$config_arg = array('config' => $config);
13
14$dn = array(
15    "countryName" => "BR",
16    "stateOrProvinceName" => "Rio Grande do Sul",
17    "localityName" => "Porto Alegre",
18    "commonName" => "Henrique do N. Angelo",
19    "emailAddress" => "hnangelo@php.net"
20);
21
22$args = array(
23    "digest_alg" => "sha1",
24    "private_key_bits" => 2048,
25    "private_key_type" => OPENSSL_KEYTYPE_DSA,
26    "encrypt_key" => true,
27    "config" => $config
28);
29
30$privkey = openssl_pkey_new($config_arg);
31$csr = openssl_csr_new($dn, $privkey, $args);
32var_dump(openssl_csr_sign($csr, null, $privkey, 365, $args));
33var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg));
34var_dump(openssl_csr_sign($csr, $cert, $priv, 365, $config_arg));
35var_dump(openssl_csr_sign($csr, openssl_x509_read($cert), $priv, 365, $config_arg));
36var_dump(openssl_csr_sign($csr, $wrong, $privkey, 365));
37var_dump(openssl_csr_sign($csr, null, $wrong, 365));
38var_dump(openssl_csr_sign($csr, null, $privkey, $wrong));
39var_dump(openssl_csr_sign($csr, null, $privkey, 365, $wrong));
40var_dump(openssl_csr_sign($wrong, null, $privkey, 365));
41var_dump(openssl_csr_sign(array(), null, $privkey, 365));
42var_dump(openssl_csr_sign($csr, array(), $privkey, 365));
43var_dump(openssl_csr_sign($csr, null, array(), 365));
44var_dump(openssl_csr_sign($csr, null, $privkey, array()));
45var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg));
46?>
47--EXPECTF--
48resource(%d) of type (OpenSSL X.509)
49resource(%d) of type (OpenSSL X.509)
50resource(%d) of type (OpenSSL X.509)
51resource(%d) of type (OpenSSL X.509)
52
53Warning: openssl_csr_sign(): cannot get cert from parameter 2 in %s on line %d
54bool(false)
55
56Warning: openssl_csr_sign(): cannot get private key from parameter 3 in %s on line %d
57bool(false)
58
59Warning: openssl_csr_sign() expects parameter 4 to be int, string given in %s on line %d
60NULL
61
62Warning: openssl_csr_sign() expects parameter 5 to be array, string given in %s on line %d
63NULL
64
65Warning: openssl_csr_sign(): cannot get CSR from parameter 1 in %s on line %d
66bool(false)
67
68Warning: openssl_csr_sign(): cannot get CSR from parameter 1 in %s on line %d
69bool(false)
70
71Warning: openssl_csr_sign(): cannot get cert from parameter 2 in %s on line %d
72bool(false)
73
74Warning: openssl_csr_sign(): key array must be of the form array(0 => key, 1 => phrase) in %s on line %d
75
76Warning: openssl_csr_sign(): cannot get private key from parameter 3 in %s on line %d
77bool(false)
78
79Warning: openssl_csr_sign() expects parameter 4 to be int, array given in %s on line %d
80NULL
81resource(%d) of type (OpenSSL X.509)
82