1
|
Vue.use(VueLoading);
|
2
|
Vue.component('loading', VueLoading)
|
3
|
|
4
|
|
5
|
var certificateDetailsApp = new Vue({
|
6
|
el: "#certificate-detailed-view-content",
|
7
|
data: {
|
8
|
loading: true,
|
9
|
error: false,
|
10
|
id: null,
|
11
|
displayIssuer: false,
|
12
|
issuerLoaded: false,
|
13
|
revocationReason: "unspecified",
|
14
|
issuedCertificates: [],
|
15
|
identityName: "",
|
16
|
identityPass: "",
|
17
|
certificate: {
|
18
|
subject: {
|
19
|
C: "",
|
20
|
ST: "",
|
21
|
L: "",
|
22
|
CN: "",
|
23
|
O: "",
|
24
|
OU: "",
|
25
|
emailAddress: "",
|
26
|
},
|
27
|
notBefore: "",
|
28
|
notAfter: "",
|
29
|
usage: {
|
30
|
CA: false,
|
31
|
authentication: false,
|
32
|
digitalSignature: false,
|
33
|
SSL: false,
|
34
|
},
|
35
|
CA: null,
|
36
|
status: "",
|
37
|
},
|
38
|
issuer: {
|
39
|
subject: {
|
40
|
C: "",
|
41
|
ST: "",
|
42
|
L: "",
|
43
|
CN: "",
|
44
|
O: "",
|
45
|
OU: "",
|
46
|
emailAddress: "",
|
47
|
},
|
48
|
notBefore: "",
|
49
|
notAfter: "",
|
50
|
usage: {
|
51
|
CA: false,
|
52
|
authentication: false,
|
53
|
digitalSignature: false,
|
54
|
SSL: false,
|
55
|
},
|
56
|
CA: null,
|
57
|
status: "",
|
58
|
},
|
59
|
errorMessage: "",
|
60
|
successMessage: "",
|
61
|
},
|
62
|
computed: {
|
63
|
startDate: function () {
|
64
|
return this.certificate.notBefore.substr(0, 16);
|
65
|
},
|
66
|
endDate: function () {
|
67
|
return this.certificate.notAfter.substr(0, 16);
|
68
|
},
|
69
|
issuerURL: function () {
|
70
|
return "/static/certificate.html?id=" + this.certificate.CA;
|
71
|
},
|
72
|
crlEndpoint: function () {
|
73
|
return "/api/crl/" + this.certificate.CA;
|
74
|
},
|
75
|
ocspEndpoint: function () {
|
76
|
return "/api/ocsp/" + this.certificate.CA;
|
77
|
}
|
78
|
},
|
79
|
watch: {},
|
80
|
methods: {
|
81
|
onShowIssuer: async function() {
|
82
|
if (!this.issuerLoaded) {
|
83
|
// query certificate details
|
84
|
try {
|
85
|
const response = await axios.get(API_URL + "certificates/" + this.certificate.CA + "/details");
|
86
|
if (response.data["success"]) {
|
87
|
// display certificate
|
88
|
certificateDetailsApp.issuer = response.data["data"];
|
89
|
this.issuerLoaded = true;
|
90
|
} else {
|
91
|
// certificate does not exists
|
92
|
console.error("Required certificate does not exists");
|
93
|
this.showError("Error occurred while loading issuer's details.");
|
94
|
}
|
95
|
} catch (error) {
|
96
|
console.error(error);
|
97
|
this.showError("Error occurred while loading issuer's details.");
|
98
|
}
|
99
|
}
|
100
|
this.displayIssuer = ~this.displayIssuer;
|
101
|
},
|
102
|
onCertificateDownload: async function () {
|
103
|
await onCertificateDownload(this.id);
|
104
|
},
|
105
|
onRootDownload: async function () {
|
106
|
await onCertificateRootDownload(this.id);
|
107
|
},
|
108
|
onChainDownload: async function () {
|
109
|
await onCertificateChainDownload(this.id);
|
110
|
},
|
111
|
onPublicKeyDownload: async function () {
|
112
|
await onPublicKeyDownload(this.id);
|
113
|
},
|
114
|
onPrivateKeyDownload: async function () {
|
115
|
await onPrivateKeyDownload(this.id);
|
116
|
},
|
117
|
onIdentityDownload: async function() {
|
118
|
this.errorMessage = "";
|
119
|
if (this.identityName === "") {
|
120
|
this.errorMessage = "Identity name must not be empty! Please try again.";
|
121
|
document.body.scrollTop = 0;
|
122
|
document.documentElement.scrollTop = 0;
|
123
|
return;
|
124
|
}
|
125
|
await onIdentityDownload(this.id, this.identityName, this.identityPass);
|
126
|
},
|
127
|
onRevoke: async function () {
|
128
|
document.body.scrollTop = 0;
|
129
|
document.documentElement.scrollTop = 0;
|
130
|
try {
|
131
|
const response = await axios.patch(API_URL + "certificates/" + this.id, {
|
132
|
status: "revoked",
|
133
|
reason: this.revocationReason
|
134
|
});
|
135
|
if (response.data["success"]) {
|
136
|
this.certificate.status="revoked";
|
137
|
certificateDetailsApp.successMessage = "Certificate revocation successful.";
|
138
|
} else {
|
139
|
certificateDetailsApp.errorMessage = "Certificate cannot be revoked - " + response.data["data"] + "!";
|
140
|
}
|
141
|
} catch (error) {
|
142
|
certificateDetailsApp.errorMessage = "An error occurred while revoking certificate";
|
143
|
}
|
144
|
},
|
145
|
onDelete: async function () {
|
146
|
document.body.scrollTop = 0;
|
147
|
document.documentElement.scrollTop = 0;
|
148
|
try {
|
149
|
const response = await axios.delete(API_URL + "certificates/" + this.id);
|
150
|
if (response.data["success"]) {
|
151
|
window.location.href = "/static/index.html?success=Certificate+successfully+deleted";
|
152
|
} else {
|
153
|
certificateDetailsApp.errorMessage = "Certificate cannot be deleted - " + response.data["data"] + "!";
|
154
|
}
|
155
|
} catch (error) {
|
156
|
certificateDetailsApp.errorMessage = "An error occurred while deleting certificate";
|
157
|
}
|
158
|
}
|
159
|
},
|
160
|
mounted: async function () {
|
161
|
// get details of the selected certificate
|
162
|
const params = window.location.search;
|
163
|
if (params !== "") {
|
164
|
// get requested ID
|
165
|
const urlParams = new URLSearchParams(params);
|
166
|
if (urlParams.get("id") != null) {
|
167
|
const id = urlParams.get("id");
|
168
|
this.id = id;
|
169
|
var loadedDetails = false;
|
170
|
// query certificate details
|
171
|
try {
|
172
|
const response = await axios.get(API_URL + "certificates/" + id + "/details");
|
173
|
if (response.data["success"]) {
|
174
|
// display certificate
|
175
|
certificateDetailsApp.certificate = response.data["data"];
|
176
|
loadedDetails = true;
|
177
|
} else {
|
178
|
// certificate does not exists
|
179
|
console.error("Required certificate does not exists");
|
180
|
certificateDetailsApp.loading = false;
|
181
|
certificateDetailsApp.error = true;
|
182
|
}
|
183
|
} catch (error) {
|
184
|
console.error(error);
|
185
|
certificateDetailsApp.loading = false;
|
186
|
certificateDetailsApp.error = true;
|
187
|
}
|
188
|
} else {
|
189
|
// id was not provided as a URL parameter
|
190
|
console.error("URL does not contain 'id' parameter")
|
191
|
certificateDetailsApp.loading = false;
|
192
|
certificateDetailsApp.error = true;
|
193
|
}
|
194
|
} else {
|
195
|
console.error("URL does not contain 'id' parameter")
|
196
|
certificateDetailsApp.loading = false;
|
197
|
certificateDetailsApp.error = true;
|
198
|
}
|
199
|
|
200
|
if (!loadedDetails) return;
|
201
|
try {
|
202
|
const response = await axios.get(API_URL + "certificates", {
|
203
|
params: {
|
204
|
filtering: {
|
205
|
issuedby: parseInt(certificateDetailsApp.id)
|
206
|
}
|
207
|
}
|
208
|
});
|
209
|
if (response.data["success"]) {
|
210
|
response.data["data"].forEach(item => {
|
211
|
if (item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item)
|
212
|
})
|
213
|
} else {
|
214
|
certificateDetailsApp.issuedCertificates = [];
|
215
|
}
|
216
|
} catch (error) {
|
217
|
console.log(error);
|
218
|
}
|
219
|
this.loading = false;
|
220
|
this.error = false;
|
221
|
}
|
222
|
});
|
223
|
|
224
|
|