Creates a certificate with the specified name and destination path.
21 {
23 $destPath = empty($destPath) ?
$bearsamppRoot->getSslPath() : $destPath;
24
25 $subject = '"/C=US/O=Bearsampp/CN=' . $name . '"';
26 $password = 'pass:bearsampp';
27 $ppkPath = '"' . $destPath . '/' . $name . '.ppk"';
28 $pubPath = '"' . $destPath . '/' . $name . '.pub"';
29 $crtPath = '"' . $destPath . '/' . $name . '.crt"';
30 $extension = 'SAN';
32
33
34 $extContent = PHP_EOL . '[' . $extension . ']' . PHP_EOL;
35 $extContent .= 'subjectAltName=DNS:*.' . $name . ',DNS:' . $name . PHP_EOL;
36
37
39 file_put_contents($conf, file_get_contents(
$bearsamppCore->getOpenSslConf()) . $extContent);
40
41
42 $confPath = '"' . $conf . '"';
43
44
45 $batch = $exe . ' genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -aes256 -pass ' . $password . ' -out ' . $ppkPath . ' -config ' . $confPath . PHP_EOL;
46 $batch .= 'IF %ERRORLEVEL% GEQ 1 GOTO EOF' . PHP_EOL . PHP_EOL;
47
48
49 $batch .= $exe . ' rsa -in ' . $ppkPath . ' -passin ' . $password . ' -out ' . $pubPath . PHP_EOL . PHP_EOL;
50 $batch .= 'IF %ERRORLEVEL% GEQ 1 GOTO EOF' . PHP_EOL . PHP_EOL;
51
52
53 $batch .= $exe . ' req -x509 -nodes -sha256 -new -key ' . $pubPath . ' -out ' . $crtPath . ' -passin ' . $password;
54 $batch .= ' -subj ' . $subject . ' -reqexts ' . $extension . ' -extensions ' . $extension . ' -config ' . $confPath . PHP_EOL;
55 $batch .= 'IF %ERRORLEVEL% GEQ 1 GOTO EOF' . PHP_EOL . PHP_EOL;
56
57 $batch .= ':EOF' . PHP_EOL;
58 $batch .= 'SET RESULT=KO' . PHP_EOL;
59 $batch .= 'IF EXIST ' . $pubPath . ' IF EXIST ' . $crtPath . ' SET RESULT=OK' . PHP_EOL;
60 $batch .= 'ECHO %RESULT%';
61
62 Log::trace(
'Creating SSL Certificate for "' . $name .
'"');
64
66 Log::trace(
'SSL Certificate generation for "' . $name .
'": ' . ($success ?
'SUCCESS' :
'FAILURE'));
67
68 return $success;
69 }
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)
static trace($data, $file=null)
static random($length=32, $withNumeric=true)