Revize 4a772c43
Přidáno uživatelem Jan Pašek před asi 4 roky(ů)
static/js/certificate.js | ||
---|---|---|
52 | 52 |
}, |
53 | 53 |
watch: {}, |
54 | 54 |
methods: { |
55 |
onCertificateDownload: function () { |
|
56 |
onCertificateDownload(this.id); |
|
55 |
onCertificateDownload: async function () {
|
|
56 |
await onCertificateDownload(this.id);
|
|
57 | 57 |
}, |
58 |
onRootDownload: function () { |
|
59 |
onCertificateRootDownload(this.id); |
|
58 |
onRootDownload: async function () {
|
|
59 |
await onCertificateRootDownload(this.id);
|
|
60 | 60 |
}, |
61 |
onChainDownload: function () { |
|
62 |
onCertificateChainDownload(this.id); |
|
61 |
onChainDownload: async function () {
|
|
62 |
await onCertificateChainDownload(this.id);
|
|
63 | 63 |
}, |
64 |
onPublicKeyDownload: function () { |
|
65 |
onPublicKeyDownload(this.id); |
|
64 |
onPublicKeyDownload: async function () {
|
|
65 |
await onPublicKeyDownload(this.id);
|
|
66 | 66 |
}, |
67 |
onPrivateKeyDownload: function () { |
|
68 |
onPrivateKeyDownload(this.id); |
|
67 |
onPrivateKeyDownload: async function () {
|
|
68 |
await onPrivateKeyDownload(this.id);
|
|
69 | 69 |
}, |
70 |
onRevoke: function () { |
|
70 |
onRevoke: async function () {
|
|
71 | 71 |
document.body.scrollTop = 0; |
72 | 72 |
document.documentElement.scrollTop = 0; |
73 |
axios.patch(API_URL + "certificates/" + this.id, { |
|
74 |
status: "revoked", |
|
75 |
reason: this.revocationReason |
|
76 |
}) |
|
77 |
.then(function (response) { |
|
78 |
if (response.data["success"]) { |
|
79 |
certificateDetailsApp.successMessage = "Certificate revocation successful."; |
|
80 |
} else { |
|
81 |
certificateDetailsApp.errorMessage = "Certificate cannot be revoked - " + response.data["data"] + "!"; |
|
82 |
} |
|
83 |
}) |
|
84 |
.catch(function (error) { |
|
85 |
certificateDetailsApp.errorMessage = "An error occurred while revoking certificate"; |
|
73 |
try { |
|
74 |
const response = await axios.patch(API_URL + "certificates/" + this.id, { |
|
75 |
status: "revoked", |
|
76 |
reason: this.revocationReason |
|
86 | 77 |
}); |
78 |
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 |
} |
|
87 | 86 |
}, |
88 |
onDelete: function () { |
|
87 |
onDelete: async function () {
|
|
89 | 88 |
document.body.scrollTop = 0; |
90 | 89 |
document.documentElement.scrollTop = 0; |
91 |
axios.delete(API_URL + "certificates/" + this.id) |
|
92 |
.then(function (response) { |
|
93 |
if (response.data["success"]) { |
|
94 |
window.location.href = "/static/index.html?success=Certificate+successfully+deleted"; |
|
95 |
} else { |
|
96 |
certificateDetailsApp.errorMessage = "Certificate cannot be deleted - " + response.data["data"] + "!"; |
|
97 |
} |
|
98 |
}) |
|
99 |
.catch(function (error) { |
|
100 |
certificateDetailsApp.errorMessage = "An error occurred while deleting certificate"; |
|
101 |
}); |
|
102 |
}, |
|
103 |
loadIssuedCertificates: function () { |
|
104 |
|
|
90 |
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 |
} |
|
105 | 100 |
} |
106 | 101 |
}, |
107 |
mounted: function () { |
|
102 |
mounted: async function () {
|
|
108 | 103 |
// get details of the selected certificate |
109 | 104 |
const params = window.location.search; |
110 | 105 |
if (params !== "") { |
... | ... | |
113 | 108 |
if (urlParams.get("id") != null) { |
114 | 109 |
const id = urlParams.get("id"); |
115 | 110 |
this.id = id; |
111 |
var loadedDetails = false; |
|
116 | 112 |
// query certificate details |
117 |
axios.get(API_URL + "certificates/" + id + "/details") |
|
118 |
.then(function (response) { |
|
119 |
if (response.data["success"]) { |
|
120 |
// display certificate |
|
121 |
certificateDetailsApp.certificate = response.data["data"]; |
|
122 |
axios.get(API_URL + "certificates", { |
|
123 |
params: { |
|
124 |
filtering: { |
|
125 |
issuedby: parseInt(certificateDetailsApp.id) |
|
126 |
} |
|
127 |
} |
|
128 |
}) |
|
129 |
.then(function (response) { |
|
130 |
if (response.data["success"]) { |
|
131 |
response.data["data"].forEach(item => { |
|
132 |
if (item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item) |
|
133 |
}) |
|
134 |
} else { |
|
135 |
certificateDetailsApp.issuedCertificates = []; |
|
136 |
} |
|
137 |
}) |
|
138 |
.catch(function (error) { |
|
139 |
console.log(error); |
|
140 |
}); |
|
141 |
certificateDetailsApp.loading = false; |
|
142 |
certificateDetailsApp.error = false; |
|
143 |
} else { |
|
144 |
// certificate does not exists |
|
145 |
console.error("Required certificate does not exists"); |
|
146 |
certificateDetailsApp.loading = false; |
|
147 |
certificateDetailsApp.error = true; |
|
148 |
} |
|
149 |
}) |
|
150 |
.catch(function (error) { |
|
151 |
// server error |
|
152 |
console.error(error); |
|
113 |
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"); |
|
153 | 122 |
certificateDetailsApp.loading = false; |
154 | 123 |
certificateDetailsApp.error = true; |
155 |
}); |
|
124 |
} |
|
125 |
} catch (error) { |
|
126 |
console.error(error); |
|
127 |
certificateDetailsApp.loading = false; |
|
128 |
certificateDetailsApp.error = true; |
|
129 |
} |
|
156 | 130 |
} else { |
157 | 131 |
// id was not provided as a URL parameter |
158 | 132 |
console.error("URL does not contain 'id' parameter") |
... | ... | |
164 | 138 |
certificateDetailsApp.loading = false; |
165 | 139 |
certificateDetailsApp.error = true; |
166 | 140 |
} |
141 |
|
|
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; |
|
167 | 163 |
} |
168 | 164 |
}); |
169 | 165 |
|
static/js/utilities.js | ||
---|---|---|
21 | 21 |
|
22 | 22 |
// Adds toDateInputValue() method to Date object |
23 | 23 |
// toDateInputValue() produces date in YYYY-MM-DD format |
24 |
Date.prototype.toDateInputValue = (function() { |
|
24 |
Date.prototype.toDateInputValue = (function () {
|
|
25 | 25 |
var local = new Date(this); |
26 | 26 |
local.setMinutes(this.getMinutes() - this.getTimezoneOffset()); |
27 |
return local.toJSON().slice(0,10); |
|
27 |
return local.toJSON().slice(0, 10);
|
|
28 | 28 |
}); |
29 | 29 |
|
30 | 30 |
/** |
31 | 31 |
* Download certificate given by id |
32 | 32 |
* @param id identifier of certificate to be downloaded |
33 | 33 |
*/ |
34 |
function onCertificateDownload(id) { |
|
35 |
axios.get(API_URL + "certificates/" + id) |
|
36 |
.then(function (response) { |
|
37 |
if (response.data["success"]) { |
|
38 |
download(id + ".pem", response.data["data"]) |
|
39 |
} else |
|
40 |
console.log("Error occurred while downloading the certificate") // TODO more action may be required |
|
41 |
}) |
|
42 |
.catch(function (error) { |
|
43 |
console.log(error); |
|
44 |
}); |
|
34 |
async function onCertificateDownload(id) { |
|
35 |
try { |
|
36 |
const response = await axios.get(API_URL + "certificates/" + id); |
|
37 |
if (response.data["success"]) { |
|
38 |
download(id + ".pem", response.data["data"]) |
|
39 |
} else |
|
40 |
console.log("Error occurred while downloading the certificate") // TODO more action may be required |
|
41 |
} catch (error) { |
|
42 |
console.log(error); |
|
43 |
} |
|
45 | 44 |
} |
46 | 45 |
|
47 | 46 |
/** |
48 | 47 |
* Download root of chain of trust excluding root of given certificate |
49 | 48 |
* @param id identifier of certificate whose chain shall be downloaded |
50 | 49 |
*/ |
51 |
function onCertificateChainDownload(id) { |
|
52 |
axios.get(API_URL + "certificates/" + id + "/chain") |
|
53 |
.then(function (response) { |
|
54 |
if(response.data["success"]) { |
|
55 |
download(id + "_chain.pem", response.data["data"]) |
|
56 |
} |
|
57 |
else |
|
58 |
console.log("Error occurred while downloading the certificate's chain of trust") // TODO more action may be required |
|
59 |
}) |
|
60 |
.catch(function (error) { |
|
61 |
console.log(error); |
|
62 |
}); |
|
50 |
async function onCertificateChainDownload(id) { |
|
51 |
try { |
|
52 |
const response = await axios.get(API_URL + "certificates/" + id + "/chain"); |
|
53 |
if (response.data["success"]) { |
|
54 |
download(id + "_chain.pem", response.data["data"]) |
|
55 |
} else |
|
56 |
console.log("Error occurred while downloading the certificate's chain of trust") // TODO more action may be required |
|
57 |
} catch (error) { |
|
58 |
console.log(error); |
|
59 |
} |
|
63 | 60 |
} |
64 | 61 |
|
65 | 62 |
/** |
66 | 63 |
* Download root of chain of trust corresponding to the given certificate |
67 | 64 |
* @param id identifier of certificate whose root shall be downloaded |
68 | 65 |
*/ |
69 |
function onCertificateRootDownload(id) { |
|
70 |
axios.get(API_URL + "certificates/" + id + "/root") |
|
71 |
.then(function (response) { |
|
72 |
if(response.data["success"]) { |
|
73 |
download(id + "_root.pem", response.data["data"]) |
|
74 |
} |
|
75 |
else |
|
76 |
console.log("Error occurred while downloading the certificate's root CA") // TODO more action may be required |
|
77 |
}) |
|
78 |
.catch(function (error) { |
|
79 |
console.log(error); |
|
80 |
}); |
|
66 |
async function onCertificateRootDownload(id) { |
|
67 |
try { |
|
68 |
const response = await axios.get(API_URL + "certificates/" + id + "/root"); |
|
69 |
if (response.data["success"]) { |
|
70 |
download(id + "_root.pem", response.data["data"]) |
|
71 |
} else |
|
72 |
console.log("Error occurred while downloading the certificate's root CA") // TODO more action may be required |
|
73 |
} catch (error) { |
|
74 |
console.log(error); |
|
75 |
} |
|
81 | 76 |
} |
82 | 77 |
|
83 | 78 |
/** |
84 | 79 |
* Download public key associated with the selected certificate |
85 | 80 |
* @param id identifier of certificate whose pub. key shall be downloaded |
86 | 81 |
*/ |
87 |
function onPublicKeyDownload(id) { |
|
88 |
axios.get(API_URL + "certificates/" + id + "/publickey") |
|
89 |
.then(function (response) { |
|
90 |
if (response.data["success"]) { |
|
91 |
download(id + "_public_key.pem", response.data["data"]) |
|
92 |
} else |
|
93 |
console.log("Error occurred while downloading the certificate's public key") // TODO more action may be required |
|
94 |
}) |
|
95 |
.catch(function (error) { |
|
96 |
console.log(error); |
|
97 |
}); |
|
82 |
async function onPublicKeyDownload(id) { |
|
83 |
try { |
|
84 |
const response = await axios.get(API_URL + "certificates/" + id + "/publickey"); |
|
85 |
if (response.data["success"]) { |
|
86 |
download(id + "_public_key.pem", response.data["data"]) |
|
87 |
} else |
|
88 |
console.log("Error occurred while downloading the certificate's public key") // TODO more action may be required |
|
89 |
} catch (error) { |
|
90 |
console.log(error); |
|
91 |
} |
|
98 | 92 |
} |
99 | 93 |
|
100 | 94 |
/** |
101 | 95 |
* Download public key associated with the selected certificate |
102 | 96 |
* @param id identifier of certificate whose pub. key shall be downloaded |
103 | 97 |
*/ |
104 |
function onPrivateKeyDownload(id) { |
|
105 |
axios.get(API_URL + "certificates/" + id + "/privatekey") |
|
106 |
.then(function (response) { |
|
107 |
if (response.data["success"]) { |
|
108 |
download(id + "_private_key.pem", response.data["data"]) |
|
109 |
} else |
|
110 |
console.log("Error occurred while downloading the certificate's private key") // TODO more action may be required |
|
111 |
}) |
|
112 |
.catch(function (error) { |
|
113 |
console.log(error); |
|
114 |
}); |
|
98 |
async function onPrivateKeyDownload(id) { |
|
99 |
try { |
|
100 |
const response = await axios.get(API_URL + "certificates/" + id + "/privatekey"); |
|
101 |
if (response.data["success"]) { |
|
102 |
download(id + "_private_key.pem", response.data["data"]) |
|
103 |
} else |
|
104 |
console.log("Error occurred while downloading the certificate's private key") // TODO more action may be required |
|
105 |
} catch (error) { |
|
106 |
console.log(error); |
|
107 |
} |
|
115 | 108 |
} |
Také k dispozici: Unified diff
Re #8583 - certificate.js and utilities.js using await