blob: 6544c2c4b5c40bef34f3c67795507d284843c590 [file] [log] [blame]
Yoshie Muranaka532a4b02020-03-27 11:00:50 -07001<template>
2 <div>
3 <b-modal
4 id="generate-csr"
5 ref="modal"
6 size="lg"
7 no-stacking
8 :title="
9 $t('pageSslCertificates.modal.generateACertificateSigningRequest')
10 "
11 @ok="onOkGenerateCsrModal"
12 @cancel="resetForm"
13 @hidden="$v.$reset()"
14 >
Yoshie Muranakac77fdaf2020-05-04 09:33:51 -070015 <b-form id="generate-csr-form" novalidate @submit.prevent="handleSubmit">
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070016 <b-container fluid>
17 <b-row>
18 <b-col lg="9">
19 <b-row>
20 <b-col lg="6">
21 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -050022 :label="$t('pageSslCertificates.modal.certificateType')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070023 label-for="certificate-type"
24 >
25 <b-form-select
26 id="certificate-type"
27 v-model="form.certificateType"
SurenNewared0df7d22020-07-22 16:41:20 +053028 data-test-id="modalGenerateCsr-select-certificateType"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070029 :options="certificateOptions"
30 :state="getValidationState($v.form.certificateType)"
31 @input="$v.form.certificateType.$touch()"
32 >
Derick Montague602e98a2020-10-21 16:20:00 -050033 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070034 <b-form-select-option :value="null" disabled>
35 {{ $t('global.form.selectAnOption') }}
36 </b-form-select-option>
37 </template>
38 </b-form-select>
39 <b-form-invalid-feedback role="alert">
40 {{ $t('global.form.fieldRequired') }}
41 </b-form-invalid-feedback>
42 </b-form-group>
43 </b-col>
44 <b-col lg="6">
45 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -050046 :label="$t('pageSslCertificates.modal.country')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070047 label-for="country"
48 >
49 <b-form-select
50 id="country"
51 v-model="form.country"
SurenNewared0df7d22020-07-22 16:41:20 +053052 data-test-id="modalGenerateCsr-select-country"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070053 :options="countryOptions"
54 :state="getValidationState($v.form.country)"
55 @input="$v.form.country.$touch()"
56 >
Derick Montague602e98a2020-10-21 16:20:00 -050057 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070058 <b-form-select-option :value="null" disabled>
59 {{ $t('global.form.selectAnOption') }}
60 </b-form-select-option>
61 </template>
62 </b-form-select>
63 <b-form-invalid-feedback role="alert">
64 {{ $t('global.form.fieldRequired') }}
65 </b-form-invalid-feedback>
66 </b-form-group>
67 </b-col>
68 </b-row>
69 <b-row>
70 <b-col lg="6">
71 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -050072 :label="$t('pageSslCertificates.modal.state')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070073 label-for="state"
74 >
75 <b-form-input
76 id="state"
77 v-model="form.state"
78 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +053079 data-test-id="modalGenerateCsr-input-state"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070080 :state="getValidationState($v.form.state)"
81 />
82 <b-form-invalid-feedback role="alert">
83 {{ $t('global.form.fieldRequired') }}
84 </b-form-invalid-feedback>
85 </b-form-group>
86 </b-col>
87 <b-col lg="6">
88 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -050089 :label="$t('pageSslCertificates.modal.city')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070090 label-for="city"
91 >
92 <b-form-input
93 id="city"
94 v-model="form.city"
95 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +053096 data-test-id="modalGenerateCsr-input-city"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070097 :state="getValidationState($v.form.city)"
98 />
99 <b-form-invalid-feedback role="alert">
100 {{ $t('global.form.fieldRequired') }}
101 </b-form-invalid-feedback>
102 </b-form-group>
103 </b-col>
104 </b-row>
105 <b-row>
106 <b-col lg="6">
107 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500108 :label="$t('pageSslCertificates.modal.companyName')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700109 label-for="company-name"
110 >
111 <b-form-input
112 id="company-name"
113 v-model="form.companyName"
114 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530115 data-test-id="modalGenerateCsr-input-companyName"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700116 :state="getValidationState($v.form.companyName)"
117 />
118 <b-form-invalid-feedback role="alert">
119 {{ $t('global.form.fieldRequired') }}
120 </b-form-invalid-feedback>
121 </b-form-group>
122 </b-col>
123 <b-col lg="6">
124 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500125 :label="$t('pageSslCertificates.modal.companyUnit')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700126 label-for="company-unit"
127 >
128 <b-form-input
129 id="company-unit"
130 v-model="form.companyUnit"
131 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530132 data-test-id="modalGenerateCsr-input-companyUnit"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700133 :state="getValidationState($v.form.companyUnit)"
134 />
135 <b-form-invalid-feedback role="alert">
136 {{ $t('global.form.fieldRequired') }}
137 </b-form-invalid-feedback>
138 </b-form-group>
139 </b-col>
140 </b-row>
141 <b-row>
142 <b-col lg="6">
143 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500144 :label="$t('pageSslCertificates.modal.commonName')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700145 label-for="common-name"
146 >
147 <b-form-input
148 id="common-name"
149 v-model="form.commonName"
150 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530151 data-test-id="modalGenerateCsr-input-commonName"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700152 :state="getValidationState($v.form.commonName)"
153 />
154 <b-form-invalid-feedback role="alert">
155 {{ $t('global.form.fieldRequired') }}
156 </b-form-invalid-feedback>
157 </b-form-group>
158 </b-col>
159 <b-col lg="6">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500160 <b-form-group label-for="challenge-password">
Derick Montague602e98a2020-10-21 16:20:00 -0500161 <template #label>
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500162 {{ $t('pageSslCertificates.modal.challengePassword') }} -
163 <span class="form-text d-inline">
164 {{ $t('global.form.optional') }}
165 </span>
166 </template>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700167 <b-form-input
168 id="challenge-password"
169 v-model="form.challengePassword"
170 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530171 data-test-id="modalGenerateCsr-input-challengePassword"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700172 />
173 </b-form-group>
174 </b-col>
175 </b-row>
176 <b-row>
177 <b-col lg="6">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500178 <b-form-group label-for="contact-person">
Derick Montague602e98a2020-10-21 16:20:00 -0500179 <template #label>
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500180 {{ $t('pageSslCertificates.modal.contactPerson') }} -
181 <span class="form-text d-inline">
182 {{ $t('global.form.optional') }}
183 </span>
184 </template>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700185 <b-form-input
186 id="contact-person"
187 v-model="form.contactPerson"
188 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530189 data-test-id="modalGenerateCsr-input-contactPerson"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700190 />
191 </b-form-group>
192 </b-col>
193 <b-col lg="6">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500194 <b-form-group label-for="email-address">
Derick Montague602e98a2020-10-21 16:20:00 -0500195 <template #label>
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500196 {{ $t('pageSslCertificates.modal.emailAddress') }} -
197 <span class="form-text d-inline">
198 {{ $t('global.form.optional') }}
199 </span>
200 </template>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700201 <b-form-input
202 id="email-address"
203 v-model="form.emailAddress"
204 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530205 data-test-id="modalGenerateCsr-input-emailAddress"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700206 />
207 </b-form-group>
208 </b-col>
209 </b-row>
210 <b-row>
211 <b-col lg="12">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500212 <b-form-group label-for="alternate-name">
Derick Montague602e98a2020-10-21 16:20:00 -0500213 <template #label>
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500214 {{ $t('pageSslCertificates.modal.alternateName') }} -
215 <span class="form-text d-inline">
216 {{ $t('global.form.optional') }}
217 </span>
218 </template>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700219 <b-form-text id="alternate-name-help-block">
220 {{
221 $t('pageSslCertificates.modal.alternateNameHelperText')
222 }}
223 </b-form-text>
224 <b-form-tags
225 v-model="form.alternateName"
226 :remove-on-delete="true"
227 :tag-pills="true"
228 input-id="alternate-name"
229 size="lg"
230 separator=" "
231 :input-attrs="{
Derick Montague602e98a2020-10-21 16:20:00 -0500232 'aria-describedby': 'alternate-name-help-block',
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700233 }"
234 :duplicate-tag-text="
235 $t('pageSslCertificates.modal.duplicateAlternateName')
236 "
237 placeholder=""
Sandeepa Singh92f87552021-02-12 18:13:46 +0530238 data-test-id="modalGenerateCsr-input-alternateName"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700239 >
Derick Montague602e98a2020-10-21 16:20:00 -0500240 <template #add-button-text>
Dixsie Wolmers30f11f82020-11-10 16:07:56 -0600241 <icon-add /> {{ $t('global.action.add') }}
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700242 </template>
243 </b-form-tags>
244 </b-form-group>
245 </b-col>
246 </b-row>
247 </b-col>
248 <b-col lg="3">
249 <b-row>
250 <b-col lg="12">
251 <p class="col-form-label">
252 {{ $t('pageSslCertificates.modal.privateKey') }}
253 </p>
254 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500255 :label="$t('pageSslCertificates.modal.keyPairAlgorithm')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700256 label-for="key-pair-algorithm"
257 >
258 <b-form-select
259 id="key-pair-algorithm"
260 v-model="form.keyPairAlgorithm"
SurenNewared0df7d22020-07-22 16:41:20 +0530261 data-test-id="modalGenerateCsr-select-keyPairAlgorithm"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700262 :options="keyPairAlgorithmOptions"
263 :state="getValidationState($v.form.keyPairAlgorithm)"
264 @input="$v.form.keyPairAlgorithm.$touch()"
265 >
Derick Montague602e98a2020-10-21 16:20:00 -0500266 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700267 <b-form-select-option :value="null" disabled>
268 {{ $t('global.form.selectAnOption') }}
269 </b-form-select-option>
270 </template>
271 </b-form-select>
272 <b-form-invalid-feedback role="alert">
273 {{ $t('global.form.fieldRequired') }}
274 </b-form-invalid-feedback>
275 </b-form-group>
276 </b-col>
277 </b-row>
278 <b-row>
279 <b-col lg="12">
280 <template v-if="$v.form.keyPairAlgorithm.$model === 'EC'">
281 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500282 :label="$t('pageSslCertificates.modal.keyCurveId')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700283 label-for="key-curve-id"
284 >
285 <b-form-select
286 id="key-curve-id"
287 v-model="form.keyCurveId"
SurenNewared0df7d22020-07-22 16:41:20 +0530288 data-test-id="modalGenerateCsr-select-keyCurveId"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700289 :options="keyCurveIdOptions"
290 :state="getValidationState($v.form.keyCurveId)"
291 @input="$v.form.keyCurveId.$touch()"
292 >
Derick Montague602e98a2020-10-21 16:20:00 -0500293 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700294 <b-form-select-option :value="null" disabled>
295 {{ $t('global.form.selectAnOption') }}
296 </b-form-select-option>
297 </template>
298 </b-form-select>
299 <b-form-invalid-feedback role="alert">
300 {{ $t('global.form.fieldRequired') }}
301 </b-form-invalid-feedback>
302 </b-form-group>
303 </template>
304 <template v-if="$v.form.keyPairAlgorithm.$model === 'RSA'">
305 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500306 :label="$t('pageSslCertificates.modal.keyBitLength')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700307 label-for="key-bit-length"
308 >
309 <b-form-select
310 id="key-bit-length"
311 v-model="form.keyBitLength"
SurenNewared0df7d22020-07-22 16:41:20 +0530312 data-test-id="modalGenerateCsr-select-keyBitLength"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700313 :options="keyBitLengthOptions"
314 :state="getValidationState($v.form.keyBitLength)"
315 @input="$v.form.keyBitLength.$touch()"
316 >
Derick Montague602e98a2020-10-21 16:20:00 -0500317 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700318 <b-form-select-option :value="null" disabled>
319 {{ $t('global.form.selectAnOption') }}
320 </b-form-select-option>
321 </template>
322 </b-form-select>
323 <b-form-invalid-feedback role="alert">
324 {{ $t('global.form.fieldRequired') }}
325 </b-form-invalid-feedback>
326 </b-form-group>
327 </template>
328 </b-col>
329 </b-row>
330 </b-col>
331 </b-row>
332 </b-container>
333 </b-form>
Derick Montague602e98a2020-10-21 16:20:00 -0500334 <template #modal-footer="{ ok, cancel }">
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700335 <b-button variant="secondary" @click="cancel()">
336 {{ $t('global.action.cancel') }}
337 </b-button>
338 <b-button
339 form="generate-csr-form"
340 type="submit"
341 variant="primary"
SurenNewared0df7d22020-07-22 16:41:20 +0530342 data-test-id="modalGenerateCsr-button-ok"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700343 @click="ok()"
344 >
345 {{ $t('pageSslCertificates.generateCsr') }}
346 </b-button>
347 </template>
348 </b-modal>
349 <b-modal
350 id="csr-string"
351 no-stacking
352 size="lg"
353 :title="$t('pageSslCertificates.modal.certificateSigningRequest')"
354 @hidden="onHiddenCsrStringModal"
355 >
356 {{ csrString }}
Derick Montague602e98a2020-10-21 16:20:00 -0500357 <template #modal-footer>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700358 <b-btn variant="secondary" @click="copyCsrString">
359 <template v-if="csrStringCopied">
360 <icon-checkmark />
361 {{ $t('global.status.copied') }}
362 </template>
363 <template v-else>
364 {{ $t('global.action.copy') }}
365 </template>
366 </b-btn>
367 <a
368 :href="`data:text/json;charset=utf-8,${csrString}`"
369 download="certificate.txt"
370 class="btn btn-primary"
371 >
372 {{ $t('global.action.download') }}
373 </a>
374 </template>
375 </b-modal>
376 </div>
377</template>
378
379<script>
380import IconAdd from '@carbon/icons-vue/es/add--alt/20';
381import IconCheckmark from '@carbon/icons-vue/es/checkmark/20';
382
383import { required, requiredIf } from 'vuelidate/lib/validators';
384
385import { COUNTRY_LIST } from './CsrCountryCodes';
SurenNeware61859092020-10-01 09:37:32 +0530386import { CERTIFICATE_TYPES } from '@/store/modules/AccessControl/SslCertificatesStore';
387import BVToastMixin from '@/components/Mixins/BVToastMixin';
388import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700389
390export default {
391 name: 'ModalGenerateCsr',
392 components: { IconAdd, IconCheckmark },
393 mixins: [BVToastMixin, VuelidateMixin],
394 data() {
395 return {
396 form: {
397 certificateType: null,
398 country: null,
399 state: null,
400 city: null,
401 companyName: null,
402 companyUnit: null,
403 commonName: null,
404 challengePassword: null,
405 contactPerson: null,
406 emailAddress: null,
407 alternateName: [],
408 keyPairAlgorithm: null,
409 keyCurveId: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500410 keyBitLength: null,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700411 },
412 certificateOptions: CERTIFICATE_TYPES.reduce((arr, cert) => {
413 if (cert.type === 'TrustStore Certificate') return arr;
414 arr.push({
415 text: cert.label,
Derick Montague602e98a2020-10-21 16:20:00 -0500416 value: cert.type,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700417 });
418 return arr;
419 }, []),
Derick Montague602e98a2020-10-21 16:20:00 -0500420 countryOptions: COUNTRY_LIST.map((country) => ({
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700421 text: country.label,
Derick Montague602e98a2020-10-21 16:20:00 -0500422 value: country.code,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700423 })),
424 keyPairAlgorithmOptions: ['EC', 'RSA'],
425 keyCurveIdOptions: ['prime256v1', 'secp521r1', 'secp384r1'],
426 keyBitLengthOptions: [2048],
427 csrString: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500428 csrStringCopied: false,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700429 };
430 },
431 validations: {
432 form: {
433 certificateType: { required },
434 country: { required },
435 state: { required },
436 city: { required },
437 companyName: { required },
438 companyUnit: { required },
439 commonName: { required },
440 challengePassword: {},
441 contactPerson: {},
442 emailAddress: {},
443 alternateName: {},
444 keyPairAlgorithm: { required },
445 keyCurveId: {
Derick Montague602e98a2020-10-21 16:20:00 -0500446 reuired: requiredIf(function (form) {
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700447 return form.keyPairAlgorithm === 'EC';
Derick Montague602e98a2020-10-21 16:20:00 -0500448 }),
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700449 },
450 keyBitLength: {
Derick Montague602e98a2020-10-21 16:20:00 -0500451 reuired: requiredIf(function (form) {
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700452 return form.keyPairAlgorithm === 'RSA';
Derick Montague602e98a2020-10-21 16:20:00 -0500453 }),
454 },
455 },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700456 },
457 methods: {
458 handleSubmit() {
459 this.$v.$touch();
460 if (this.$v.$invalid) return;
461 this.$store
462 .dispatch('sslCertificates/generateCsr', this.form)
463 .then(({ data: { CSRString } }) => {
464 this.csrString = CSRString;
465 this.$bvModal.show('csr-string');
466 this.$v.$reset();
467 });
468 },
469 resetForm() {
470 for (let key of Object.keys(this.form)) {
471 if (key === 'alternateName') {
472 this.form[key] = [];
473 } else {
474 this.form[key] = null;
475 }
476 }
477 },
478 onOkGenerateCsrModal(bvModalEvt) {
479 // prevent modal close
480 bvModalEvt.preventDefault();
481 this.handleSubmit();
482 },
483 onHiddenCsrStringModal() {
484 this.csrString = '';
485 this.resetForm();
486 },
487 copyCsrString(bvModalEvt) {
488 // prevent modal close
489 bvModalEvt.preventDefault();
490 navigator.clipboard.writeText(this.csrString).then(() => {
491 // Show copied text for 5 seconds
492 this.csrStringCopied = true;
493 setTimeout(() => {
494 this.csrStringCopied = false;
495 }, 5000 /*5 seconds*/);
496 });
Derick Montague602e98a2020-10-21 16:20:00 -0500497 },
498 },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700499};
500</script>