-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
72 lines (60 loc) · 1.63 KB
/
Copy pathexample.php
File metadata and controls
72 lines (60 loc) · 1.63 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
68
69
70
71
72
<?php
declare(strict_types=1);
include "vendor/autoload.php";
use OpenSSL\CertificateAuthority;
use OpenSSL\Config\Args;
use OpenSSL\Config\Extra;
use OpenSSL\Csr;
use OpenSSL\DistinguishedName;
use OpenSSL\DN\Location;
use OpenSSL\DN\Organization;
use OpenSSL\DN\Person;
use OpenSSL\PrivateKey;
use OpenSSL\SlaveCertificate;
$privateKey = PrivateKey::generate();
echo $privateKey->export() . PHP_EOL;
$args = new Args();
$args->set("digest_alg", "sha256WithRSAEncryption");
$args->set("x509_extensions", "v3_ca");
$csr = new Csr(
new DistinguishedName(
new Location(
"RU", "Saint-Petersburg", "SPb"
),
new Organization(
"HROM", "HROM Team"
),
new Person(
"Taras D",
"td@hrom.fund"
)
),
$privateKey,
$args
);
$slaveArgs = new Args();
$slaveArgs->set("digest_alg", "sha256WithRSAEncryption");
$slaveArgs->set("x509_extensions", "v3_req");
$slaveExtra = new Extra();
$slaveCsr = new Csr(
new DistinguishedName(
new Location(
"RU", "Saint-Petersburg", "SPb"
),
new Organization(
"HROM", "HROM Team"
),
new Person(
"Taras D",
"td@hrom.fund"
)
),
$privateKey,
$slaveArgs
);
$ca = CertificateAuthority::generate( $csr, $privateKey, 365, $args );
$saved = $ca->export();
$exportedCA = CertificateAuthority::restore($saved);
echo $exportedCA->export();
$slave = SlaveCertificate::generate( $slaveCsr, $ca, $privateKey,365, $slaveArgs, 30 );
$slave2 = SlaveCertificate::generate( $slaveCsr, $exportedCA, $privateKey,365, $slaveArgs, 30 );