This repository has been archived by the owner on Jul 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.php
99 lines (68 loc) · 2.32 KB
/
make.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
include("connection.php");
$id = $_GET['id'];
// create CA and store to lib
ini_set('max_execution_time', 300);
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib0.3.10');
include('Net/SSH2.php');
include('phpseclib0.3.10/Crypt/RSA.php');
include('phpseclib0.3.10/File/X509.php');
$cert_file = fopen("ca_certificat.crt", "r");
$cert = fread ( $cert_file , 4096 );
$caprivKey_file = fopen("ca_private.key", "r");
$caprivatekey = fread ( $caprivKey_file , 4096 );
$caprivKey = new Crypt_RSA();
$caprivKey->loadKey($caprivatekey);
// echo $caprivatekey;
// issuer
$query = "SELECT public_key, nama FROM request WHERE status = 1 AND id = '$id' ;";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$publickey = $row[0];
$nama = $row[1];
// echo $nama." ".$publickey;
// $key = "-----BEGIN PUBLIC KEY-----";
// $key .= "\r\n";
// $str = chunk_split(base64_encode($publickey), 64);
// $key .= $str;
// $key .= "-----END PUBLIC KEY-----";
// $key .= "\r\n";
// echo $key;
$pubKey = new Crypt_RSA();
$pubKey->loadKey($publickey);
$pubKey->setPublicKey();
$subject = new File_X509();
$subject->setPublicKey($pubKey);
$subject->setDNProp($nama, $nama);
$subject->setDomain($nama);
$issuer = new File_X509();
$issuer->setPrivateKey($caprivKey);
// $issuer->setDNProp('KIJ Pro Thor CA', 'pro certificate authority, build using phpseclib');
// $issuer->setDomain('KIJ.Pro.Thor');
// $issuer->setDN($issuer->getDN());
if ($issuer->loadCA($cert)) {
$issuer->loadX509($cert);
}
// var_dump($issuer->getDN());
$x509 = new File_X509();
$x509->setStartDate('-1 month');
$x509->setEndDate('+1 year');
$x509->setSerialNumber(chr($id));
// var_dump($subject->getPublicKey());
$result = $x509->sign($issuer, $subject);
$content = $x509->saveX509($result, FILE_X509_FORMAT_DER);
// var_dump( $x509->saveX509($result) );
// var_dump($result);
$content = addslashes($content);
$tgl = date('Y-m-d');
$tgl1 = explode('-', $tgl);
$year = $tgl1[0] + 1;
// echo $year;
$tgl2 = str_replace($tgl1[0], $year, $tgl);
$query = "UPDATE request SET status = 2, tgl_create = '$tgl', sertifikat = '$content', tgl_expired = '$tgl2' WHERE id = '$id' ;";
$result = mysql_query($query);
// echo $result;
// echo mysql_error();
header("Location: create.php");
mysql_close($conn);
?>