<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.openssl.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.openssl-csr-sign.php',
    1 => 'openssl_csr_sign',
    2 => 'Sign a CSR with another certificate (or itself) and generate a certificate',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'OpenSSL Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.openssl-csr-new.php',
    1 => 'openssl_csr_new',
  ),
  'next' => 
  array (
    0 => 'function.openssl-decrypt.php',
    1 => 'openssl_decrypt',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/openssl/functions/openssl-csr-sign.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.openssl-csr-sign" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_csr_sign</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_csr_sign</span> &mdash; <span class="dc-title">Sign a <abbr title="Certificate Signing Request">CSR</abbr> with another certificate (or itself) and generate a certificate</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-csr-sign-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_csr_sign</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.opensslcertificatesigningrequest.php" class="type OpenSSLCertificateSigningRequest">OpenSSLCertificateSigningRequest</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$csr</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.opensslcertificate.php" class="type OpenSSLCertificate">OpenSSLCertificate</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span> <code class="parameter">$ca_certificate</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="attribute"><a href="class.sensitiveparameter.php">#[\SensitiveParameter]</a> </span><span class="type"><span class="type"><a href="class.opensslasymmetrickey.php" class="type OpenSSLAsymmetricKey">OpenSSLAsymmetricKey</a></span>|<span class="type"><a href="class.opensslcertificate.php" class="type OpenSSLCertificate">OpenSSLCertificate</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$private_key</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$days</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$serial</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$serial_hex</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="class.opensslcertificate.php" class="type OpenSSLCertificate">OpenSSLCertificate</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>openssl_csr_sign()</strong></span> generates an x509 certificate from the given <abbr title="Certificate Signing Request">CSR</abbr>.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
 <span class="simpara">
  Occorre un <var class="filename">openssl.cnf</var> valido installato perché
  questa funzione venga eseguita correttamente.
  Vedere le note nella <a href="openssl.installation.php" class="link">sezione sull&#039;installazione
  </a> per ulteriori informazioni.
 </span>
</p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-csr-sign-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">csr</code></dt>
     <dd>
      <p class="para">
       A <abbr title="Certificate Signing Request">CSR</abbr> previously generated by <span class="function"><a href="function.openssl-csr-new.php" class="function">openssl_csr_new()</a></span>.
       It can also be the path to a <abbr title="Privacy-Enhanced Mail">PEM</abbr> encoded <abbr title="Certificate Signing Request">CSR</abbr> when specified as
       <var class="filename">file://path/to/csr</var> or an exported string generated
       by <span class="function"><a href="function.openssl-csr-export.php" class="function">openssl_csr_export()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">ca_certificate</code></dt>
     <dd>
      <p class="para">
       The generated certificate will be signed by <code class="parameter">ca_certificate</code>.
       If <code class="parameter">ca_certificate</code> is <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, the generated certificate
       will be a self-signed certificate.
      </p>
     </dd>
    
    
     <dt><code class="parameter">private_key</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">private_key</code> is the private key that corresponds to
       <code class="parameter">ca_certificate</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">days</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">days</code> specifies the length of time for which the
       generated certificate will be valid, in days.
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       You can finetune the <abbr title="Certificate Signing Request">CSR</abbr> signing by <code class="parameter">options</code>.
       See <span class="function"><a href="function.openssl-csr-new.php" class="function">openssl_csr_new()</a></span> for more information about
       <code class="parameter">options</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">serial</code></dt>
     <dd>
      <p class="para">
       An optional the serial number of issued certificate. If not specified
       it will default to 0.
      </p>
     </dd>
    
    
     <dt><code class="parameter">serial_hex</code></dt>
     <dd>
      <p class="para">
       An optional hexadecimal string representing the serial number of the
       issued certificate. If set, it takes precedence over the
       <code class="parameter">serial</code> parameter value. If not specified or set
       to <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, the <code class="parameter">serial</code> parameter value is used
       instead.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-csr-sign-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns an <span class="classname"><a href="class.opensslcertificate.php" class="classname">OpenSSLCertificate</a></span> on success, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.openssl-csr-sign-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.4.0</td>
      <td>
       The <code class="parameter">serial_hex</code> parameter is added.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       On success, this function returns an <span class="classname"><a href="class.opensslcertificate.php" class="classname">OpenSSLCertificate</a></span> instance now;
       previously, a <a href="language.types.resource.php" class="link">resource</a> of type <code class="literal">OpenSSL X.509</code> was returned.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">csr</code> accepts an <span class="classname"><a href="class.opensslcertificatesigningrequest.php" class="classname">OpenSSLCertificateSigningRequest</a></span> instance now;
       previously, a <a href="language.types.resource.php" class="link">resource</a> of type <code class="literal">OpenSSL X.509 CSR</code> was accepted.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">ca_certificate</code> accepts an <span class="classname"><a href="class.opensslcertificate.php" class="classname">OpenSSLCertificate</a></span> instance now;
       previously, a <a href="language.types.resource.php" class="link">resource</a> of type <code class="literal">OpenSSL X.509</code> was accepted.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">private_key</code> accepts an <span class="classname"><a href="class.opensslasymmetrickey.php" class="classname">OpenSSLAsymmetricKey</a></span>
       or <span class="classname"><a href="class.opensslcertificate.php" class="classname">OpenSSLCertificate</a></span> instance now;
       previously, a <a href="language.types.resource.php" class="link">resource</a> of type <code class="literal">OpenSSL key</code> or <code class="literal">OpenSSL X.509</code>
       was accepted.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-csr-sign-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>openssl_csr_sign()</strong></span> example - signing a
     <abbr title="Certificate Signing Request">CSR</abbr> (how to implement your own CA)</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Let's assume that this script is set to receive a CSR that has<br />// been pasted into a textarea from another page<br /></span><span style="color: #0000BB">$csrdata </span><span style="color: #007700">= </span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">"CSR"</span><span style="color: #007700">];<br /><br /></span><span style="color: #FF8000">// We will sign the request using our own "certificate authority"<br />// certificate.  You can use any certificate to sign another, but<br />// the process is worthless unless the signing certificate is trusted<br />// by the software/users that will deal with the newly signed certificate<br /><br />// We need our CA cert and its private key<br /></span><span style="color: #0000BB">$cacert </span><span style="color: #007700">= </span><span style="color: #DD0000">"file://path/to/ca.crt"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$privkey </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"file://path/to/ca.key"</span><span style="color: #007700">, </span><span style="color: #DD0000">"your_ca_key_passphrase"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$usercert </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_csr_sign</span><span style="color: #007700">(</span><span style="color: #0000BB">$csrdata</span><span style="color: #007700">, </span><span style="color: #0000BB">$cacert</span><span style="color: #007700">, </span><span style="color: #0000BB">$privkey</span><span style="color: #007700">, </span><span style="color: #0000BB">365</span><span style="color: #007700">, array(</span><span style="color: #DD0000">'digest_alg'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'sha256'</span><span style="color: #007700">) );<br /><br /></span><span style="color: #FF8000">// Now display the generated certificate so that the user can<br />// copy and paste it into their local configuration (such as a file<br />// to hold the certificate for their SSL server)<br /></span><span style="color: #0000BB">openssl_x509_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$usercert</span><span style="color: #007700">, </span><span style="color: #0000BB">$certout</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$certout</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Show any errors that occurred here<br /></span><span style="color: #007700">while ((</span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_error_string</span><span style="color: #007700">()) !== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$e </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


</div><?php manual_footer($setup); ?>