1--TEST--
2openssl_csr_sign() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$cert = "file://" . __DIR__ . "/cert.crt";
8$priv = "file://" . __DIR__ . "/private_rsa_1024.key";
9$wrong = "wrong";
10$pub = "file://" . __DIR__ . "/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);
32
33var_dump(openssl_csr_sign($csr, null, $privkey, 365, $args));
34var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg));
35var_dump(openssl_csr_sign($csr, $cert, $priv, 365, $config_arg));
36var_dump(openssl_csr_sign($csr, openssl_x509_read($cert), $priv, 365, $config_arg));
37var_dump(openssl_csr_sign($csr, $wrong, $privkey, 365));
38var_dump(openssl_csr_sign($csr, null, $wrong, 365));
39var_dump(openssl_csr_sign($wrong, null, $privkey, 365));
40
41try {
42    openssl_csr_sign(array(), null, $privkey, 365);
43} catch (TypeError $exception) {
44    echo $exception->getMessage() . "\n";
45}
46
47try {
48    var_dump(openssl_csr_sign($csr, array(), $privkey, 365));
49} catch (TypeError $exception) {
50    echo $exception->getMessage() . "\n";
51}
52
53try {
54    var_dump(openssl_csr_sign($csr, null, array(), 365));
55} catch (ValueError $exception) {
56    echo $exception->getMessage() . "\n";
57}
58var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg));
59?>
60--EXPECTF--
61object(OpenSSLCertificate)#%d (0) {
62}
63object(OpenSSLCertificate)#%d (0) {
64}
65object(OpenSSLCertificate)#%d (0) {
66}
67object(OpenSSLCertificate)#%d (0) {
68}
69
70Warning: openssl_csr_sign(): X.509 Certificate cannot be retrieved in %s on line %d
71bool(false)
72
73Warning: openssl_csr_sign(): Cannot get private key from parameter 3 in %s on line %d
74bool(false)
75
76Warning: openssl_csr_sign(): X.509 Certificate Signing Request cannot be retrieved in %s on line %d
77bool(false)
78openssl_csr_sign(): Argument #1 ($csr) must be of type OpenSSLCertificateSigningRequest|string, array given
79openssl_csr_sign(): Argument #2 ($ca_certificate) must be of type OpenSSLCertificate|string|null, array given
80Key array must be of the form array(0 => key, 1 => phrase)
81object(OpenSSLCertificate)#%d (0) {
82}
83