-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.php
More file actions
130 lines (121 loc) · 4.23 KB
/
Copy pathlist.php
File metadata and controls
130 lines (121 loc) · 4.23 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
require_once 'config.php';
require_once 'helper_functions.php';
require_once 'sql.php';
$clientCertVerify = $_SERVER['CLIENT_CERT_VERIFY'];
switch ($clientCertVerify) {
case 'SUCCESS':
break;
case 'NONE':
response(401, 'Unauthorized: please use your client SSL certificate for authentication');
break;
default: //FAILED:reason
response(401, 'Unauthorized: SSL authentication with your client certificate failed. Reason: ' . explode(':', $clientCertVerify)[1]);
}
$dn = $_SERVER['SUBJECT_DN'];
$attrs = explode(',', $dn);
foreach ($attrs as $attr) {
list($type, $value) = explode('=', $attr);
switch(strtolower($type)) {
case 'role':
$role = $value;
break;
case 'cn':
$username = $value;
break;
}
}
if (!empty($_REQUEST["expire"])) {
$expire = sanitize($_REQUEST["expire"]);
if (is_numeric($expire)) {
$expire = date_interval_create_from_date_string($expire . ' days');
$expire = date_add($now, $expire)->getTimestamp();
}
else response(400, 'Usage: ' . $base_url . '/list.php?type=<issued|revoked|expired|all>&expire=<DAYS>');
}
if (!empty($_REQUEST["type"])) {
$type = sanitize($_REQUEST["type"]);
switch(strtolower($type)) {
case 'issued':
$status = 0;
$type = 'issued';
break;
case 'revoked':
$status = -1;
$type = 'revoked';
break;
case 'expired':
$status = 1;
$type = 'expired';
break;
case 'all':
$status = null;
$type = 'all';
break;
default:
response(400, 'Usage: ' . $base_url . '/list.php?type=<issued|revoked|expired|all>&expire=<DAYS>');
}
}
sqlUpdateAllCerts();
$certs = sqlGetOwnCerts($username, $status);
if (! $certs)
response(404, 'No certificates have been found');
$certificates = array();
foreach ($certs as $cert) {
$attrs = explode('/', $cert['subject']);
foreach ($attrs as $attr) {
if (empty($attr)) continue;
list($attrib, $value) = explode('=', $attr);
switch(strtolower($attrib)) {
case 'owner':
$owner = $value;
break;
case 'cn':
$cn = $value;
break;
}
}
$notBefore = new DateTime('@' . $cert['notBefore']);
$notBefore = $notBefore->format("YmdHis") . 'Z';
$notAfter = new DateTime('@' . $cert['notAfter']);
$notAfter = $notAfter->format("YmdHis") . 'Z';
switch ($cert['status']) {
case 0:
$status = 'valid';
if (! isset($expire))
$certificates[] = array('Common Name' => $cn, 'Status' => $status, 'notBefore' => $notBefore, 'notAfter' => $notAfter, 'Serial Number' => $cert['serial']);
else {
if ($cert['notAfter'] <= $expire)
$certificates[] = array('Common Name' => $cn, 'Status' => $status, 'notBefore' => $notBefore, 'notAfter' => $notAfter, 'Serial Number' => $cert['serial']);
}
break;
case 1:
$status = 'expired';
$certificates[] = array('Common Name' => $cn, 'Status' => $status, 'notBefore' => $notBefore, 'notAfter' => $notAfter, 'Serial Number' => $cert['serial']);
break;
case 2:
$status = 'on-hold';
break;
case -1:
$status = 'revoked';
switch ($cert['revocationReason']) {
case 0: $revReason = 'unspecified'; break;
case 1: $revReason = 'keyCompromise'; break;
case 2: $revReason = 'cACompromise'; break;
case 3: $revReason = 'affiliationChanged'; break;
case 4: $revReason = 'superseded'; break;
case 5: $revReason = 'cessationOfOperation'; break;
case 6: $revReason = 'certificateHold'; break;
case 8: $revReason = 'removeFromCRL'; break;
case 9: $revReason = 'privilegeWithdrawn'; break;
case 10: $revReason = 'aACompromise'; break;
}
$revDate = new DateTime('@' . $cert['revocationDate']);
$revDate = $revDate->format("YmdHis") . 'Z';
$certificates[] = array('Common Name' => $cn, 'Status' => $status, 'notBefore' => $notBefore, 'notAfter' => $notAfter, 'Serial Number' => $cert['serial'], 'RevocationDate' => $revDate, 'RevocationReason' => $revReason);
break;
}
}
$result = array('status' => 200, 'detail' => 'Listing ' . $type . ' certificates');
header('Content-type: application/json', true, 200);
echo json_encode(array($result, $certificates), JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);