-
Notifications
You must be signed in to change notification settings - Fork 788
/
Copy pathopenssl-csr-new.xml
334 lines (316 loc) · 11.4 KB
/
openssl-csr-new.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.openssl-csr-new" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>openssl_csr_new</refname>
<refpurpose>Generates a <acronym>CSR</acronym></refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>OpenSSLCertificateSigningRequest</type><type>bool</type></type><methodname>openssl_csr_new</methodname>
<methodparam><type>array</type><parameter>distinguished_names</parameter></methodparam>
<methodparam><modifier role="attribute">#[\SensitiveParameter]</modifier><type class="union"><type>OpenSSLAsymmetricKey</type><type>null</type></type><parameter role="reference">private_key</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>options</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>extra_attributes</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
<function>openssl_csr_new</function> generates a new <acronym>CSR</acronym>
based on the information provided by <parameter>distinguished_names</parameter>.
</para>
¬e.openssl.cnf;
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>distinguished_names</parameter></term>
<listitem>
<para>
The Distinguished Name or subject fields to be included in the
certificate. The <parameter>distinguished_names</parameter> is an
associative array where the keys represent the attribute names of
Distinguished Names and the values can either be strings (for single
value) or arrays (if multiple values need to be set).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>private_key</parameter></term>
<listitem>
<para>
<parameter>private_key</parameter> should be set to a private key that
was previously generated by <function>openssl_pkey_new</function> (or
otherwise obtained from the other openssl_pkey family of functions), or
&null; variable. If its value is &null; variable, a new private key is
generated based on the supplied <parameter>options</parameter> and
assigned to supplied variable. The corresponding public portion of the
key will be used to sign the <acronym>CSR</acronym>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
By default, the information in your system <literal>openssl.conf</literal>
is used to initialize the request; you can specify a configuration file
section by setting the <literal>config_section_section</literal> key in
<parameter>options</parameter>. You can also specify an alternative
OpenSSL configuration file by setting the value of the
<literal>config</literal> key to the path of the file you want to use.
The following keys, if present in <parameter>options</parameter>
behave as their equivalents in the <literal>openssl.conf</literal>, as
listed in the table below.
<table>
<title>Configuration overrides</title>
<tgroup cols="3">
<thead>
<row>
<entry><parameter>options</parameter> key</entry>
<entry>type</entry>
<entry><literal>openssl.conf</literal> equivalent</entry>
<entry>description</entry>
</row>
</thead>
<tbody>
<row>
<entry>digest_alg</entry>
<entry><type>string</type></entry>
<entry>default_md</entry>
<entry>Digest method or signature hash, usually one of <function>openssl_get_md_methods</function></entry>
</row>
<row>
<entry>x509_extensions</entry>
<entry><type>string</type></entry>
<entry>x509_extensions</entry>
<entry>Selects which extensions should be used when creating an x509
certificate</entry>
</row>
<row>
<entry>req_extensions</entry>
<entry><type>string</type></entry>
<entry>req_extensions</entry>
<entry>Selects which extensions should be used when creating a <acronym>CSR</acronym></entry>
</row>
<row>
<entry>private_key_bits</entry>
<entry><type>int</type></entry>
<entry>default_bits</entry>
<entry>Specifies how many bits should be used to generate a private key</entry>
</row>
<row>
<entry>private_key_type</entry>
<entry><type>int</type></entry>
<entry>none</entry>
<entry>Specifies the type of private key to create. This can be one
of <constant>OPENSSL_KEYTYPE_DSA</constant>,
<constant>OPENSSL_KEYTYPE_DH</constant>,
<constant>OPENSSL_KEYTYPE_RSA</constant> or
<constant>OPENSSL_KEYTYPE_EC</constant>.
The default value is <constant>OPENSSL_KEYTYPE_RSA</constant>.
</entry>
</row>
<row>
<entry>encrypt_key</entry>
<entry><type>bool</type></entry>
<entry>encrypt_key</entry>
<entry>Should an exported key (with passphrase) be encrypted?</entry>
</row>
<row>
<entry>encrypt_key_cipher</entry>
<entry><type>int</type></entry>
<entry>none</entry>
<entry>
One of <link linkend="openssl.ciphers">cipher constants</link>.
</entry>
</row>
<row>
<entry>curve_name</entry>
<entry><type>string</type></entry>
<entry>none</entry>
<entry>
One of <function>openssl_get_curve_names</function>.
</entry>
</row>
<row>
<entry>config</entry>
<entry><type>string</type></entry>
<entry>N/A</entry>
<entry>
Path to your own alternative openssl.conf file.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>extra_attributes</parameter></term>
<listitem>
<para>
<parameter>extra_attributes</parameter> is used to specify additional
attributes for the <acronym>CSR</acronym>. It is an associative arrays
where the keys are converted to OIDs and applied as
<acronym>CSR</acronym> attributes.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the <acronym>CSR</acronym> on success, &true; if
<acronym>CSR</acronym> creation is successful but signing
fails&return.falseforfailure;.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
The <parameter>distinguished_names</parameter> associative array now supports arrays as values,
allowing multiple values to be specified for a single attribute.
</entry>
</row>
<row>
<entry>8.4.0</entry>
<entry>
The <parameter>extra_attributes</parameter> parameter now correctly sets the CSR attributes,
rather than modifying the subject's Distinguished Name as it previously did incorrectly.
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
On success, this function returns an <classname>OpenSSLCertificateSigningRequest</classname> instance now;
previously, a &resource; of type <literal>OpenSSL X.509 CSR</literal> was returned.
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>private_key</parameter> accepts an <classname>OpenSSLAsymmetricKey</classname> instance now;
previously, a &resource; of type <literal>OpenSSL key</literal> was accepted.
</entry>
</row>
<row>
<entry>7.1.0</entry>
<entry>
<parameter>options</parameter> now also supports <literal>curve_name</literal>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Creating a self-signed certificate</title>
<programlisting role="php">
<![CDATA[
<?php
// for SSL server certificates the commonName is the domain name to be secured
// for S/MIME email certificates the commonName is the owner of the email address
// location and identification fields refer to the owner of domain or email subject to be secured
$dn = array(
"countryName" => "GB",
"stateOrProvinceName" => "Somerset",
"localityName" => "Glastonbury",
"organizationName" => "The Brain Room Limited",
"organizationalUnitName" => "PHP Documentation Team",
"commonName" => "Wez Furlong",
"emailAddress" => "[email protected]"
);
// Generate a new private (and public) key pair
$privkey = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
));
// Generate a certificate signing request
$csr = openssl_csr_new($dn, $privkey, array('digest_alg' => 'sha256'));
// Generate a self-signed cert, valid for 365 days
$x509 = openssl_csr_sign($csr, null, $privkey, $days=365, array('digest_alg' => 'sha256'));
// Save your private key, CSR and self-signed cert for later use
openssl_csr_export($csr, $csrout) and var_dump($csrout);
openssl_x509_export($x509, $certout) and var_dump($certout);
openssl_pkey_export($privkey, $pkeyout, "mypassword") and var_dump($pkeyout);
// Show any errors that occurred here
while (($e = openssl_error_string()) !== false) {
echo $e . "\n";
}
?>
]]>
</programlisting>
</example>
<example>
<title>Creating a self-signed ECC certificate (as of PHP 7.1.0)</title>
<programlisting role="php">
<![CDATA[
<?php
$subject = array(
"commonName" => "docs.php.net",
);
// Generate a new private (and public) key pair
$private_key = openssl_pkey_new(array(
"private_key_type" => OPENSSL_KEYTYPE_EC,
"curve_name" => 'prime256v1',
));
// Generate a certificate signing request
$csr = openssl_csr_new($subject, $private_key, array('digest_alg' => 'sha384'));
// Generate self-signed EC cert
$x509 = openssl_csr_sign($csr, null, $private_key, $days=365, array('digest_alg' => 'sha384'));
openssl_x509_export_to_file($x509, 'ecc-cert.pem');
openssl_pkey_export_to_file($private_key, 'ecc-private.key');
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>openssl_csr_sign</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->