1 |
d72b12cf
|
Jan Pašek
|
Vue.use(VueLoading);
|
2 |
|
|
Vue.component('loading', VueLoading)
|
3 |
5885e489
|
Jan Pašek
|
|
4 |
7a423499
|
Jan Pašek
|
|
5 |
d72b12cf
|
Jan Pašek
|
var certificateDetailsApp = new Vue({
|
6 |
|
|
el: "#certificate-detailed-view-content",
|
7 |
|
|
data: {
|
8 |
|
|
loading: true,
|
9 |
|
|
error: false,
|
10 |
|
|
id: null,
|
11 |
|
|
revocationReason: "unspecified",
|
12 |
|
|
issuedCertificates: [],
|
13 |
|
|
certificate: {
|
14 |
|
|
subject: {
|
15 |
|
|
C: "",
|
16 |
|
|
ST: "",
|
17 |
|
|
L: "",
|
18 |
|
|
CN: "",
|
19 |
|
|
O: "",
|
20 |
|
|
OU: "",
|
21 |
|
|
emailAddress: "",
|
22 |
7a423499
|
Jan Pašek
|
},
|
23 |
d72b12cf
|
Jan Pašek
|
notBefore: "",
|
24 |
|
|
notAfter: "",
|
25 |
|
|
usage: {
|
26 |
|
|
CA: false,
|
27 |
|
|
authentication: false,
|
28 |
|
|
digitalSignature: false,
|
29 |
|
|
SSL: false,
|
30 |
5f211e7b
|
Jan Pašek
|
},
|
31 |
d72b12cf
|
Jan Pašek
|
CA: null,
|
32 |
7a423499
|
Jan Pašek
|
},
|
33 |
d72b12cf
|
Jan Pašek
|
errorMessage: "",
|
34 |
|
|
successMessage: "",
|
35 |
|
|
},
|
36 |
|
|
computed: {
|
37 |
|
|
startDate: function () {
|
38 |
|
|
return this.certificate.notBefore.substr(0, 16);
|
39 |
7a423499
|
Jan Pašek
|
},
|
40 |
d72b12cf
|
Jan Pašek
|
endDate: function () {
|
41 |
|
|
return this.certificate.notAfter.substr(0, 16);
|
42 |
|
|
},
|
43 |
|
|
issuerURL: function () {
|
44 |
|
|
return "/static/certificate.html?id=" + this.certificate.CA;
|
45 |
|
|
},
|
46 |
|
|
crlEndpoint: function () {
|
47 |
|
|
return "/api/crl/" + this.certificate.CA;
|
48 |
|
|
},
|
49 |
|
|
ocspEndpoint: function () {
|
50 |
|
|
return "/api/ocsp/" + this.certificate.CA;
|
51 |
7a423499
|
Jan Pašek
|
}
|
52 |
d72b12cf
|
Jan Pašek
|
},
|
53 |
|
|
watch: {},
|
54 |
|
|
methods: {
|
55 |
4a772c43
|
Jan Pašek
|
onCertificateDownload: async function () {
|
56 |
|
|
await onCertificateDownload(this.id);
|
57 |
d72b12cf
|
Jan Pašek
|
},
|
58 |
4a772c43
|
Jan Pašek
|
onRootDownload: async function () {
|
59 |
|
|
await onCertificateRootDownload(this.id);
|
60 |
d72b12cf
|
Jan Pašek
|
},
|
61 |
4a772c43
|
Jan Pašek
|
onChainDownload: async function () {
|
62 |
|
|
await onCertificateChainDownload(this.id);
|
63 |
d72b12cf
|
Jan Pašek
|
},
|
64 |
4a772c43
|
Jan Pašek
|
onPublicKeyDownload: async function () {
|
65 |
|
|
await onPublicKeyDownload(this.id);
|
66 |
d72b12cf
|
Jan Pašek
|
},
|
67 |
4a772c43
|
Jan Pašek
|
onPrivateKeyDownload: async function () {
|
68 |
|
|
await onPrivateKeyDownload(this.id);
|
69 |
d72b12cf
|
Jan Pašek
|
},
|
70 |
4a772c43
|
Jan Pašek
|
onRevoke: async function () {
|
71 |
d72b12cf
|
Jan Pašek
|
document.body.scrollTop = 0;
|
72 |
|
|
document.documentElement.scrollTop = 0;
|
73 |
4a772c43
|
Jan Pašek
|
try {
|
74 |
|
|
const response = await axios.patch(API_URL + "certificates/" + this.id, {
|
75 |
|
|
status: "revoked",
|
76 |
|
|
reason: this.revocationReason
|
77 |
d72b12cf
|
Jan Pašek
|
});
|
78 |
4a772c43
|
Jan Pašek
|
if (response.data["success"]) {
|
79 |
|
|
certificateDetailsApp.successMessage = "Certificate revocation successful.";
|
80 |
|
|
} else {
|
81 |
|
|
certificateDetailsApp.errorMessage = "Certificate cannot be revoked - " + response.data["data"] + "!";
|
82 |
|
|
}
|
83 |
|
|
} catch (error) {
|
84 |
|
|
certificateDetailsApp.errorMessage = "An error occurred while revoking certificate";
|
85 |
|
|
}
|
86 |
d72b12cf
|
Jan Pašek
|
},
|
87 |
4a772c43
|
Jan Pašek
|
onDelete: async function () {
|
88 |
d72b12cf
|
Jan Pašek
|
document.body.scrollTop = 0;
|
89 |
|
|
document.documentElement.scrollTop = 0;
|
90 |
4a772c43
|
Jan Pašek
|
try {
|
91 |
|
|
const response = await axios.delete(API_URL + "certificates/" + this.id);
|
92 |
|
|
if (response.data["success"]) {
|
93 |
|
|
window.location.href = "/static/index.html?success=Certificate+successfully+deleted";
|
94 |
|
|
} else {
|
95 |
|
|
certificateDetailsApp.errorMessage = "Certificate cannot be deleted - " + response.data["data"] + "!";
|
96 |
|
|
}
|
97 |
|
|
} catch (error) {
|
98 |
|
|
certificateDetailsApp.errorMessage = "An error occurred while deleting certificate";
|
99 |
|
|
}
|
100 |
d72b12cf
|
Jan Pašek
|
}
|
101 |
|
|
},
|
102 |
4a772c43
|
Jan Pašek
|
mounted: async function () {
|
103 |
d72b12cf
|
Jan Pašek
|
// get details of the selected certificate
|
104 |
|
|
const params = window.location.search;
|
105 |
|
|
if (params !== "") {
|
106 |
|
|
// get requested ID
|
107 |
|
|
const urlParams = new URLSearchParams(params);
|
108 |
|
|
if (urlParams.get("id") != null) {
|
109 |
|
|
const id = urlParams.get("id");
|
110 |
|
|
this.id = id;
|
111 |
4a772c43
|
Jan Pašek
|
var loadedDetails = false;
|
112 |
d72b12cf
|
Jan Pašek
|
// query certificate details
|
113 |
4a772c43
|
Jan Pašek
|
try {
|
114 |
|
|
const response = await axios.get(API_URL + "certificates/" + id + "/details");
|
115 |
|
|
if (response.data["success"]) {
|
116 |
|
|
// display certificate
|
117 |
|
|
certificateDetailsApp.certificate = response.data["data"];
|
118 |
|
|
loadedDetails = true;
|
119 |
|
|
} else {
|
120 |
|
|
// certificate does not exists
|
121 |
|
|
console.error("Required certificate does not exists");
|
122 |
d72b12cf
|
Jan Pašek
|
certificateDetailsApp.loading = false;
|
123 |
|
|
certificateDetailsApp.error = true;
|
124 |
4a772c43
|
Jan Pašek
|
}
|
125 |
|
|
} catch (error) {
|
126 |
|
|
console.error(error);
|
127 |
|
|
certificateDetailsApp.loading = false;
|
128 |
|
|
certificateDetailsApp.error = true;
|
129 |
|
|
}
|
130 |
d72b12cf
|
Jan Pašek
|
} else {
|
131 |
|
|
// id was not provided as a URL parameter
|
132 |
|
|
console.error("URL does not contain 'id' parameter")
|
133 |
|
|
certificateDetailsApp.loading = false;
|
134 |
|
|
certificateDetailsApp.error = true;
|
135 |
|
|
}
|
136 |
7a423499
|
Jan Pašek
|
} else {
|
137 |
5885e489
|
Jan Pašek
|
console.error("URL does not contain 'id' parameter")
|
138 |
|
|
certificateDetailsApp.loading = false;
|
139 |
|
|
certificateDetailsApp.error = true;
|
140 |
7a423499
|
Jan Pašek
|
}
|
141 |
4a772c43
|
Jan Pašek
|
|
142 |
|
|
if (!loadedDetails) return;
|
143 |
|
|
try {
|
144 |
|
|
const response = await axios.get(API_URL + "certificates", {
|
145 |
|
|
params: {
|
146 |
|
|
filtering: {
|
147 |
|
|
issuedby: parseInt(certificateDetailsApp.id)
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
});
|
151 |
|
|
if (response.data["success"]) {
|
152 |
|
|
response.data["data"].forEach(item => {
|
153 |
|
|
if (item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item)
|
154 |
|
|
})
|
155 |
|
|
} else {
|
156 |
|
|
certificateDetailsApp.issuedCertificates = [];
|
157 |
|
|
}
|
158 |
|
|
} catch (error) {
|
159 |
|
|
console.log(error);
|
160 |
|
|
}
|
161 |
|
|
this.loading = false;
|
162 |
|
|
this.error = false;
|
163 |
5885e489
|
Jan Pašek
|
}
|
164 |
d72b12cf
|
Jan Pašek
|
});
|
165 |
|
|
|