Skip to content

Instantly share code, notes, and snippets.

Created July 1, 2010 01:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/459414 to your computer and use it in GitHub Desktop.
Save anonymous/459414 to your computer and use it in GitHub Desktop.
<?php
$key = $_SERVER['argv'][1];
$domain = $_SERVER['argv'][2];
$path = "/Users/adrian/test/" . $key;
if (!is_dir($path)) {
mkdir($path);
}
$pass = 'pass';
// generate a key
$cmd[] = sprintf('openssl genrsa -passout pass:%s -des3 -out %s/openssl.key.orig 1024', $pass, $path);
// unsign it
$cmd[] = sprintf('openssl rsa -passin pass:%s -in %s/openssl.key.orig -out %s/openssl.key', $pass, $path, $path);
$input = "/C=za/CN=$domain/OU=$domain/emailAddress=admin@$domain";
// Generate the CSR
$cmd[] = sprintf("openssl req -new -subj '%s' -key %s/openssl.key -out %s/openssl.csr -batch", $input, $path, $path);
$cmd[] = sprintf("openssl x509 -req -days 365 -in %s/openssl.csr -signkey %s/openssl.key -out %s/openssl.crt", $path, $path, $path);
foreach ($cmd as $command) {
echo $command . "\n";
system($command);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment