title: Create CA certificate with PHP function openssl_csr_sign
body: <p>I'm trying to create a CA csr following the scheme</p>
  <p><a href="https://www.noirsolutions.net/wp-content/uploads/2021/12/CA-CERTIFICATE-AUTHORITY.jpg?w=678&amp;ssl=1" rel="nofollow noreferrer">https://www.noirsolutions.net/wp-content/uploads/2021/12/CA-CERTIFICATE-AUTHORITY.jpg?w=678&amp;ssl=1</a></p>
  <p>I m using library PHP openssl the code is this</p>
  <pre><code>$dn = array(
      &quot;countryName&quot; =&gt; &quot;GB&quot;,
      &quot;stateOrProvinceName&quot; =&gt; &quot;Somerset&quot;,
      &quot;localityName&quot; =&gt; &quot;Glastonbury&quot;,
      &quot;organizationName&quot; =&gt; &quot;The Brain Room Limited&quot;,
      &quot;organizationalUnitName&quot; =&gt; &quot;PHP Documentation Team&quot;,
      &quot;commonName&quot; =&gt; &quot;Wez Furlong&quot;,
      &quot;emailAddress&quot; =&gt; &quot;wez@example.com&quot;
  );
  
  $today = date(&quot;m.d.y&quot;) + rand(1,10000);
  
  $cerpath = &quot;client.crt&quot;;
  $keypath = &quot;server&quot;.$today.&quot;.key&quot;;
  $requestpath = &quot;a&quot;.$today.&quot;.csr&quot;;
  
  $privkey = openssl_pkey_new();
  
  openssl_pkey_export_to_file($privkey, $keypath);
  $csr = openssl_csr_new($dn, $privkey);
  openssl_csr_export_to_file($csr, $requestpath);
  $sscert = openssl_csr_sign($csr, null, $privkey, 365);
  openssl_x509_export_to_file($sscert, $cerpath);
  $src = getcwd();
  $dest = '/usr/local/lxlabs/kloxo/ext/lxhttpd/conf';
  /////////////////////////////////////////////
  /////////////////////////////////////////////
  
  // CERTIFICATE CA//
      
  $dn1 = array(
      &quot;countryName&quot; =&gt; &quot;IT&quot;,
      &quot;stateOrProvinceName&quot; =&gt; &quot;PIPPALANDt&quot;,
      &quot;localityName&quot; =&gt; &quot;Siena&quot;,
      &quot;organizationName&quot; =&gt; &quot;cacchi mia&quot;,
      &quot;organizationalUnitName&quot; =&gt; &quot;PHP Documentation Team&quot;,
      &quot;commonName&quot; =&gt; &quot;Pippo Baudo&quot;,
      &quot;emailAddress&quot; =&gt; &quot;wez@example.com&quot;
  );
  
  $todayCA = date(&quot;m.d.y&quot;) + rand(1,10000);
  
  $cerpathCA = &quot;certificato.crt&quot;;
  $keypathCA = &quot;server&quot;.$todayCA.&quot;.key&quot;;
  $requestpathCA = &quot;a&quot;.$todayCA.&quot;.csr&quot;;
  
  //openssl_pkey_export_to_file($privkey, $keypath);
  $csr1 = openssl_csr_new($dn1, $privkey);
  openssl_csr_export_to_file($csr1, $requestpathCA);
  $sscert1 = openssl_csr_sign($csr1, null, $privkey, 365);
  openssl_x509_export_to_file($sscert1, $cerpathCA);
  $src1 = getcwd();
  $dest1 = '/usr/local/lxlabs/kloxo/ext/lxhttpd/conf';
  
  //////////////////////////////////////////////////
  ///////////////////////////////////////////////////
  
  $cerpath2 = &quot;final&quot;.$today.&quot;.crt&quot;;
  
  $cacert=&quot;certificato.crt&quot;;
  
  $sscert2 = openssl_csr_sign($csr, &quot;certificato.crt&quot;, $privkey, 365, array('digest_alg'=&gt;'sha256'));
  
  echo &quot;&lt;br&gt; value sscert2 &lt;br&gt;&quot;;
  
  var_dump($sscert2);
  
  openssl_x509_export_to_file($sscert2, $cerpath2);
  
  $src1 = getcwd();
  $dest1 = '/usr/local/lxlabs/kloxo/ext/lxhttpd/conf';
  </code></pre>
  <p>i create the 2 csr client.crt and certificato.crt and after with the second certificato.crt i try to firm the in information of the first but  the function</p>
  <pre><code>$sscert2 = openssl_csr_sign($csr, &quot;certificato.crt&quot;, $privkey, 365, array('digest_alg'=&gt;'sha256'));
  echo &quot;&lt;br&gt; value sscert2 &lt;br&gt;&quot;;
  var_dump($sscert2);
  </code></pre>
  <p>give result</p>
  <pre><code>value sscert2
  bool(false)
  </code></pre>
  <p>and the CSR certificate.crt is not created.</p>
  <p>Where is my mistake?</p>