1--TEST--
2openssl_csr_sign() tests
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!defined("OPENSSL_KEYTYPE_DSA")) die("skip DSA disabled");
8?>
9--FILE--
10<?php
11$cert = "file://" . __DIR__ . "/cert.crt";
12$priv = "file://" . __DIR__ . "/private_rsa_1024.key";
13$wrong = "wrong";
14$pub = "file://" . __DIR__ . "/public.key";
15$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf';
16$config_arg = array('config' => $config);
17
18$dn = array(
19    "countryName" => "BR",
20    "stateOrProvinceName" => "Rio Grande do Sul",
21    "localityName" => "Porto Alegre",
22    "commonName" => "Henrique do N. Angelo",
23    "emailAddress" => "hnangelo@php.net"
24);
25
26$args = array(
27    "digest_alg" => "sha256",
28    "private_key_bits" => 2048,
29    "private_key_type" => OPENSSL_KEYTYPE_DSA,
30    "encrypt_key" => true,
31    "config" => $config
32);
33
34$privkey = openssl_pkey_new($config_arg);
35$csr = openssl_csr_new($dn, $privkey, $args);
36
37var_dump(openssl_csr_sign($csr, null, $privkey, 365, $args));
38var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg));
39var_dump(openssl_csr_sign($csr, $cert, $priv, 365, $config_arg));
40var_dump(openssl_csr_sign($csr, openssl_x509_read($cert), $priv, 365, $config_arg));
41var_dump(openssl_csr_sign($csr, $wrong, $privkey, 365));
42var_dump(openssl_csr_sign($csr, null, $wrong, 365));
43var_dump(openssl_csr_sign($wrong, null, $privkey, 365));
44
45try {
46    openssl_csr_sign(array(), null, $privkey, 365);
47} catch (TypeError $exception) {
48    echo $exception->getMessage() . "\n";
49}
50
51try {
52    var_dump(openssl_csr_sign($csr, array(), $privkey, 365));
53} catch (TypeError $exception) {
54    echo $exception->getMessage() . "\n";
55}
56
57try {
58    var_dump(openssl_csr_sign($csr, null, array(), 365));
59} catch (ValueError $exception) {
60    echo $exception->getMessage() . "\n";
61}
62var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg));
63?>
64--EXPECTF--
65object(OpenSSLCertificate)#%d (0) {
66}
67object(OpenSSLCertificate)#%d (0) {
68}
69object(OpenSSLCertificate)#%d (0) {
70}
71object(OpenSSLCertificate)#%d (0) {
72}
73
74Warning: openssl_csr_sign(): X.509 Certificate cannot be retrieved in %s on line %d
75bool(false)
76
77Warning: openssl_csr_sign(): Cannot get private key from parameter 3 in %s on line %d
78bool(false)
79
80Warning: openssl_csr_sign(): X.509 Certificate Signing Request cannot be retrieved in %s on line %d
81bool(false)
82openssl_csr_sign(): Argument #1 ($csr) must be of type OpenSSLCertificateSigningRequest|string, array given
83openssl_csr_sign(): Argument #2 ($ca_certificate) must be of type OpenSSLCertificate|string|null, array given
84Key array must be of the form array(0 => key, 1 => phrase)
85object(OpenSSLCertificate)#%d (0) {
86}
87