-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathConfig.php
More file actions
69 lines (56 loc) · 1.18 KB
/
Config.php
File metadata and controls
69 lines (56 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Madeny\lhttps;
use Symfony\Component\Dotenv\Dotenv;
class Config
{
public function __construct($domain)
{
$path = $this->path();
$this->v3($path, $domain);
$this->openssl($path);
}
private function v3($path, $domain)
{
$v3 = [
'authorityKeyIdentifier=keyid,issuer',
'basicConstraints=CA:FALSE',
'keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment',
'subjectAltName = @alt_names',
"[alt_names]",
"DNS.1 = {$domain}"
];
$str = implode("\n", $v3);
file_put_contents($path.'/cnf/v3.ext', $str);
return $str;
}
private function openssl($path)
{
$dotenv = new Dotenv();
$dotenv->load(realpath(__DIR__.'/../.env'));
$arr = [
$_ENV['R'],
$_ENV['D'],
$_ENV['P'],
$_ENV['DM'],
$_ENV['DN'],
$_ENV['D2'],
$_ENV['COUNTRY'],
$_ENV['STATE'],
$_ENV['LOCALITY'],
$_ENV['ORGANIZATION'],
$_ENV['ORGANIZATION_UNIT'],
$_ENV['EMAILADDRESS'],
$_ENV['COMMONNAME']];
$str = implode("\n", $arr);
file_put_contents($path.'/cnf/openssl.cnf', $str);
return $str;
}
public static function path()
{
$dir = __DIR__.'/../cert';
if (!file_exists($dir)) {
mkdir($dir);
}
return $dir;
}
}