Start.html

<html>
<head>
<title>Disa Certification Authority</title>
</head>

<script>
function validateForm()
{
var x=document.forms["derp"]["pass"].value;
var y=document.forms["derp"]["pass2"].value;
if (x==null || x=="")
  {
  document.getElementById('error').innerHTML = "Fill all fields";
  //alert("1");
  return false;
  }
  else
  {
  
  if (x.length < 4) 
  {
  document.getElementById('error').innerHTML = "At least 4 chars for Passphase";
  return false;
  }
  
  }
if (y==null || y=="")
  {
  document.getElementById('error').innerHTML = "Fill all fields";
  //alert("2");
  return false;
  }
    else
  {
  
  if (x.length < 4) 
  {
  document.getElementById('error').innerHTML = "At least 4 chars for Passphase";
  return false;
  }
  
  }
if (x!==y)
  {
  document.getElementById('error').innerHTML = "Passwords must be same!";
  //alert("3");
  return false;
  }
document.getElementById('error').innerHTML = "<input type=\"submit\">"; 
}

</script>

<body>
Enter passphase for your private key.
<form name="derp" method="post" action="genrsa.php" onsubmit="return validateForm()" >
Passphase: <input onchange="validateForm()" type="password" name="pass"><br>
Once again: <input onchange="validateForm()" type="password" name="pass2"><br>

Chose key length: <select onchange="validateForm()" name="key">
  <option value="512" name="key">512(Not recommended)</option>
  <option value="1024" name="key">1024(Not recommended)</option>
  <option value="2048" name="key">2048(Fast)</option>
  <option value="4096" name="key">4096(Secure)</option>
  <option value="8192" name="key">8192(Slow, Very secure)</option>
</select><br>
<a id="error"></a>
</form><br>

</body>
</html>`

genrsa.php 

`<?php
$p = $_POST['pass'];
$p2 = $_POST['pass2'];
$k = intval($_POST['key']);
if ($p === '') {
?>
<a rel="nofollow" href="start.html">Enter password(at least 4 chars)</a>
<?php
exit;
}


if (!(strlen($p) > 3)) {
?>
<a rel="nofollow" href="start.html">Enter password(at least 4 chars)</a>
<?php
exit;
}

if (!($p === $p2)) {
?> <a rel="nofollow" href="start.html">Wrong password</a>
<?php
exit;
}
echo "Passwords are same. Excellent!";
$config = array('private_key_bits' => $k, 'passphrase' => "$p");

$privKey = openssl_pkey_new($config);

//openssl_pkey_export_to_file($privKey, 'D:\wamp\www\keys\key5.key', 'lol1');
openssl_pkey_export($privKey, $klucz, "$p");
//echo $key;


?>
<textarea cols="70" rows="15"><?php echo $klucz; ?></textarea>

Copy this key into key.key file.
<input type="button" onclick="location.href='csr.html';" name="Click to process to next step" value="Click to process to next step">
`


csr.html
`<html>
<head>
<title>Disa Certification Authority</title>
</head>

<script>
function validateForm()
{
var x=document.forms["derp"]["c"].value;
var y=document.forms["derp"]["city"].value;
var z=document.forms["derp"]["cn"].value;
var w=document.forms["derp"]["email"].value;
var a=document.forms["derp"]["key"].value;
if (x==null || x=="")
  {
  document.getElementById('error').innerHTML = "Fill all fields";
  //alert("1");
  return false;
  }
  else
  {
  if (x.length!==2)
  {
  document.getElementById('error').innerHTML = "Country name should have 2 chars";
  return false;
  }
  }
if (y==null || y=="")
  {
  document.getElementById('error').innerHTML = "Fill all fields";
  //alert("2");
  return false;
  }
if (z==null || z=="")
  {
  document.getElementById('error').innerHTML = "Fill all fields";
  //alert("2");
  return false;
  }
if (w==null || w=="")
  {
  document.getElementById('error').innerHTML = "Fill all fields";
  //alert("2");
  return false;
  }
  if (a==null || a=="")
  {
  document.getElementById('error').innerHTML = "Enter key from prev step";
  //alert("2");
  return false;
  }
document.getElementById('error').innerHTML = "<input type=\"submit\">"; 
}

</script>

<body>
Enter passphase for your private key.
<form name="derp" method="post" action="csr.php" onsubmit="return validateForm()" >
Country Code: <input onchange="validateForm()" maxlength="2" type="text" name="c"><br>
City: <input onchange="validateForm()" type="text" name="city"><br>
Common name(domain name): <input onchange="validateForm()" type="text" name="cn"><br>
E-mail: <input onchange="validateForm()" type="text" name="email"><br>
Private key pass: <input onchange="validateForm()" type="password" name="pass"><br>
Private key: <textarea onchange="validateForm()" cols="75" rows="15" name="key"></textarea><br>
<br>
<a id="error"></a>
</form><br>

</body>
</html>`

csr.php
`<?php 
$c = $_POST['c'];
$city = $_POST['city'];
$cn = $_POST['cn'];
$mail = $_POST['email'];
$p = $_POST['pass'];

$key = $_POST['key'];
//$key = openssl_pkey_new();
$dn = array(
    "countryName" => "$c",
    //"stateOrProvinceName" => "",
    "localityName" => "$city",
    //"organizationName" => "",
    //"organizationalUnitName" => "",
    "commonName" => "$cn",
    "emailAddress" => "$key",
	"passphase" => "$p"
);
// Generate a certificate signing request
$csr = openssl_csr_new($dn, $key);
var_dump($csr);
while ($msg = openssl_error_string())
    echo $msg . "<br />\n";
?>

Kiedy próbuje utworzyć CSR, wyrzuca mi błąd:
error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0906406D:PEM routines:PEM_def_callback:problems getting password error:0906A068:PEM routines:PEM_do_header:bad password read error:0D07A086:asn1 encoding routines:ASN1_mbstring_ncopy:invalid utf8string

var_dump zmiennej $csr pokazuje: false