Created
January 23, 2018 20:03
-
-
Save melvincarvalho/d9acb32ea07dbd4b3ca11f0e2d2756fe to your computer and use it in GitHub Desktop.
keygen.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function write_cert($cert) { | |
echo "$cert"; | |
$myFile = "/tmp/tmp1234.spkac"; | |
$fh = fopen($myFile, 'w') or die("can't open file"); | |
fwrite($fh, $cert); | |
fclose($fh); | |
$opensslconf = "/etc/ssl/openssl.cnf"; | |
$days = 36500; | |
$certfolder = "/tmp"; | |
$uniq = "1234"; | |
$capw = ""; | |
$command = "/usr/bin/openssl ca -config ".$opensslconf." -days ".$days." -notext \ | |
-batch -spkac ".$certfolder.$uniq.".spkac -out ".$certfolder.$uniq." -passin pass:'".$capw."' 2>&1"; | |
$output = shell_exec($command); | |
echo $command; | |
echo "\n" ; | |
} | |
echo "<pre>"; | |
$key = $_REQUEST['pubkey']; | |
$username = "Joe"; | |
$CAmail = "joe@example.org"; | |
$CAorg = "AA Ltd"; | |
$CAcity = "AA"; | |
$CAcountry = "AA"; | |
$localityName = "Prage"; | |
$keyreq = "SPKAC=".str_replace(str_split(" \t\n\r\0\x0B"), '', $key); | |
$keyreq .= "\nCN=".$username; | |
$keyreq .= "\nemailAddress=".$CAmail; | |
$keyreq .= "\n0.OU=".$CAorg." client certificate"; | |
$keyreq .= "\norganizationName=".$CAorg; | |
$keyreq .= "\ncountryName=".$CAcountry; | |
$keyreq .= "\nstateOrProvinceName=".$CAcity; | |
$keyreq .= "\nlocalityName=".$CAcity; | |
write_cert($keyreq); | |
echo "</pre>"; | |
?> | |
<form> | |
<keygen name="pubkey" challenge="randomchars"> | |
<input type="submit" name="createcert" value="Generate"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment