1 |
6c9cb54a
|
Jan Pašek
|
|
2 |
|
|
// VUE instance of certificate creation page
|
3 |
a3b708c2
|
Jan Pašek
|
var createCertificateApp = new Vue({
|
4 |
|
|
el: "#create-certificate-content",
|
5 |
|
|
data: {
|
6 |
1b9fc014
|
Jan Pašek
|
notBefore: "",
|
7 |
|
|
notAfter: "",
|
8 |
6c9cb54a
|
Jan Pašek
|
// available certificate authorities
|
9 |
|
|
authorities: [],
|
10 |
|
|
// data of the selected certificate authorities to be displayed in the form
|
11 |
b556270c
|
Jan Pašek
|
selectedCAData: {
|
12 |
a3b708c2
|
Jan Pašek
|
CN: "",
|
13 |
|
|
C: "",
|
14 |
|
|
L: "",
|
15 |
|
|
ST: "",
|
16 |
|
|
O: "",
|
17 |
|
|
OU: "",
|
18 |
|
|
emailAddress: ""
|
19 |
9cac7fd4
|
Jan Pašek
|
},
|
20 |
6c9cb54a
|
Jan Pašek
|
// Data of the new certificate to be created received from the input fields
|
21 |
9cac7fd4
|
Jan Pašek
|
certificateData: {
|
22 |
|
|
subject: {
|
23 |
|
|
CN: "",
|
24 |
|
|
C: "",
|
25 |
|
|
L: "",
|
26 |
|
|
ST: "",
|
27 |
|
|
O: "",
|
28 |
|
|
OU: "",
|
29 |
|
|
emailAddress: ""
|
30 |
|
|
},
|
31 |
1b9fc014
|
Jan Pašek
|
validityDays: 30,
|
32 |
9cac7fd4
|
Jan Pašek
|
usage: {
|
33 |
|
|
CA: false,
|
34 |
|
|
authentication: false,
|
35 |
|
|
digitalSignature: false,
|
36 |
|
|
SSL: false
|
37 |
|
|
},
|
38 |
|
|
CA: null
|
39 |
a3b708c2
|
Jan Pašek
|
}
|
40 |
b556270c
|
Jan Pašek
|
},
|
41 |
6c9cb54a
|
Jan Pašek
|
// actions to be performed when the page is loaded
|
42 |
|
|
// - initialize notBefore and notAfter with current date and current date + 1 month respectively
|
43 |
9cac7fd4
|
Jan Pašek
|
mounted () {
|
44 |
1b9fc014
|
Jan Pašek
|
this.notBefore = new Date().toDateInputValue(); // init notBefore to current date
|
45 |
9cac7fd4
|
Jan Pašek
|
var endDate = new Date(new Date().getTime()+(30*24*60*60*1000));
|
46 |
1b9fc014
|
Jan Pašek
|
this.notAfter = endDate.toDateInputValue(); // init notAfter to notBefore + 30 days
|
47 |
9cac7fd4
|
Jan Pašek
|
},
|
48 |
71d8054e
|
Jan Pašek
|
methods: {
|
49 |
6c9cb54a
|
Jan Pašek
|
// handle certificate creation request
|
50 |
71d8054e
|
Jan Pašek
|
onCreateCertificate: function () {
|
51 |
6c9cb54a
|
Jan Pašek
|
// validate input data
|
52 |
|
|
// - validate if subject CN is filled in
|
53 |
|
|
if(this.certificateData.subject.CN === "") {
|
54 |
|
|
alert("CN field must be filled in!"); // TODO highlight the field
|
55 |
|
|
return;
|
56 |
|
|
}
|
57 |
493022a0
|
Jan Pašek
|
this.certificateData.validityDays = parseInt(this.certificateData.validityDays);
|
58 |
71d8054e
|
Jan Pašek
|
axios.post(API_URL + "certificates", this.certificateData)
|
59 |
|
|
.then(function (response) {
|
60 |
6c9cb54a
|
Jan Pašek
|
// on success return to index page
|
61 |
71d8054e
|
Jan Pašek
|
if(response.data["success"]) {
|
62 |
|
|
alert("Certificate was successfully created.");
|
63 |
|
|
window.location.href = "/static/index.html";
|
64 |
|
|
}
|
65 |
6c9cb54a
|
Jan Pašek
|
// on error display server response message
|
66 |
71d8054e
|
Jan Pašek
|
else {
|
67 |
|
|
alert(response.data["data"]);
|
68 |
|
|
}
|
69 |
|
|
})
|
70 |
|
|
.catch(function (error) {
|
71 |
|
|
console.log(error);
|
72 |
|
|
});
|
73 |
|
|
}
|
74 |
|
|
},
|
75 |
6c9cb54a
|
Jan Pašek
|
// data watches
|
76 |
b556270c
|
Jan Pašek
|
watch: {
|
77 |
6c9cb54a
|
Jan Pašek
|
// if the selected CA is changed, the Issuer input fileds must be filled in
|
78 |
1b9fc014
|
Jan Pašek
|
'certificateData.validityDays': function (val, oldVal) {
|
79 |
|
|
var endDate = new Date(new Date().getTime()+(val*24*60*60*1000));
|
80 |
|
|
this.notAfter = endDate.toDateInputValue(); // init notAfter to today + validityDays
|
81 |
|
|
},
|
82 |
9cac7fd4
|
Jan Pašek
|
'certificateData.CA': function (val, oldVal) {
|
83 |
6c9cb54a
|
Jan Pašek
|
// self-signed certificate - all fields are empty
|
84 |
b556270c
|
Jan Pašek
|
if (val === "null" || val == null) {
|
85 |
|
|
createCertificateApp.selectedCAData = {
|
86 |
|
|
CN: "",
|
87 |
|
|
C: "",
|
88 |
|
|
L: "",
|
89 |
|
|
ST: "",
|
90 |
|
|
O: "",
|
91 |
|
|
OU: "",
|
92 |
|
|
emailAddress: ""
|
93 |
|
|
};
|
94 |
|
|
}
|
95 |
6c9cb54a
|
Jan Pašek
|
// a CA is selected - get CA's details and display them
|
96 |
b556270c
|
Jan Pašek
|
else {
|
97 |
|
|
axios.get(API_URL + "certificates/" + val + "/details")
|
98 |
|
|
.then(function (response) {
|
99 |
|
|
if (response.data["success"]) {
|
100 |
|
|
createCertificateApp.selectedCAData = response.data["data"]["subject"];
|
101 |
|
|
}
|
102 |
|
|
else
|
103 |
|
|
console.log("Error occurred while fetching CA details");
|
104 |
|
|
})
|
105 |
|
|
.catch(function (error) {
|
106 |
|
|
console.log(error);
|
107 |
|
|
});
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
});
|
112 |
|
|
|
113 |
6c9cb54a
|
Jan Pašek
|
// Initialize available CA select values
|
114 |
b556270c
|
Jan Pašek
|
axios.get(API_URL+"certificates", {
|
115 |
|
|
params: {
|
116 |
|
|
filtering: {
|
117 |
|
|
CA: true
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
})
|
121 |
|
|
.then(function (response) {
|
122 |
|
|
if (response.data["success"]) {
|
123 |
|
|
createCertificateApp.authorities = response.data["data"];
|
124 |
a3b708c2
|
Jan Pašek
|
}
|
125 |
b556270c
|
Jan Pašek
|
else
|
126 |
|
|
console.log("Error occurred while fetching list of available certificate authorities");
|
127 |
|
|
})
|
128 |
|
|
.catch(function (error) {
|
129 |
|
|
console.log(error);
|
130 |
a3b708c2
|
Jan Pašek
|
});
|