blob: da6b457c610366eabbf29901c011055321ecc3d9 [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=""
238 >
Derick Montague602e98a2020-10-21 16:20:00 -0500239 <template #add-button-text>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700240 {{ $t('global.action.add') }} <icon-add />
241 </template>
242 </b-form-tags>
243 </b-form-group>
244 </b-col>
245 </b-row>
246 </b-col>
247 <b-col lg="3">
248 <b-row>
249 <b-col lg="12">
250 <p class="col-form-label">
251 {{ $t('pageSslCertificates.modal.privateKey') }}
252 </p>
253 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500254 :label="$t('pageSslCertificates.modal.keyPairAlgorithm')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700255 label-for="key-pair-algorithm"
256 >
257 <b-form-select
258 id="key-pair-algorithm"
259 v-model="form.keyPairAlgorithm"
SurenNewared0df7d22020-07-22 16:41:20 +0530260 data-test-id="modalGenerateCsr-select-keyPairAlgorithm"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700261 :options="keyPairAlgorithmOptions"
262 :state="getValidationState($v.form.keyPairAlgorithm)"
263 @input="$v.form.keyPairAlgorithm.$touch()"
264 >
Derick Montague602e98a2020-10-21 16:20:00 -0500265 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700266 <b-form-select-option :value="null" disabled>
267 {{ $t('global.form.selectAnOption') }}
268 </b-form-select-option>
269 </template>
270 </b-form-select>
271 <b-form-invalid-feedback role="alert">
272 {{ $t('global.form.fieldRequired') }}
273 </b-form-invalid-feedback>
274 </b-form-group>
275 </b-col>
276 </b-row>
277 <b-row>
278 <b-col lg="12">
279 <template v-if="$v.form.keyPairAlgorithm.$model === 'EC'">
280 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500281 :label="$t('pageSslCertificates.modal.keyCurveId')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700282 label-for="key-curve-id"
283 >
284 <b-form-select
285 id="key-curve-id"
286 v-model="form.keyCurveId"
SurenNewared0df7d22020-07-22 16:41:20 +0530287 data-test-id="modalGenerateCsr-select-keyCurveId"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700288 :options="keyCurveIdOptions"
289 :state="getValidationState($v.form.keyCurveId)"
290 @input="$v.form.keyCurveId.$touch()"
291 >
Derick Montague602e98a2020-10-21 16:20:00 -0500292 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700293 <b-form-select-option :value="null" disabled>
294 {{ $t('global.form.selectAnOption') }}
295 </b-form-select-option>
296 </template>
297 </b-form-select>
298 <b-form-invalid-feedback role="alert">
299 {{ $t('global.form.fieldRequired') }}
300 </b-form-invalid-feedback>
301 </b-form-group>
302 </template>
303 <template v-if="$v.form.keyPairAlgorithm.$model === 'RSA'">
304 <b-form-group
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500305 :label="$t('pageSslCertificates.modal.keyBitLength')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700306 label-for="key-bit-length"
307 >
308 <b-form-select
309 id="key-bit-length"
310 v-model="form.keyBitLength"
SurenNewared0df7d22020-07-22 16:41:20 +0530311 data-test-id="modalGenerateCsr-select-keyBitLength"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700312 :options="keyBitLengthOptions"
313 :state="getValidationState($v.form.keyBitLength)"
314 @input="$v.form.keyBitLength.$touch()"
315 >
Derick Montague602e98a2020-10-21 16:20:00 -0500316 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700317 <b-form-select-option :value="null" disabled>
318 {{ $t('global.form.selectAnOption') }}
319 </b-form-select-option>
320 </template>
321 </b-form-select>
322 <b-form-invalid-feedback role="alert">
323 {{ $t('global.form.fieldRequired') }}
324 </b-form-invalid-feedback>
325 </b-form-group>
326 </template>
327 </b-col>
328 </b-row>
329 </b-col>
330 </b-row>
331 </b-container>
332 </b-form>
Derick Montague602e98a2020-10-21 16:20:00 -0500333 <template #modal-footer="{ ok, cancel }">
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700334 <b-button variant="secondary" @click="cancel()">
335 {{ $t('global.action.cancel') }}
336 </b-button>
337 <b-button
338 form="generate-csr-form"
339 type="submit"
340 variant="primary"
SurenNewared0df7d22020-07-22 16:41:20 +0530341 data-test-id="modalGenerateCsr-button-ok"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700342 @click="ok()"
343 >
344 {{ $t('pageSslCertificates.generateCsr') }}
345 </b-button>
346 </template>
347 </b-modal>
348 <b-modal
349 id="csr-string"
350 no-stacking
351 size="lg"
352 :title="$t('pageSslCertificates.modal.certificateSigningRequest')"
353 @hidden="onHiddenCsrStringModal"
354 >
355 {{ csrString }}
Derick Montague602e98a2020-10-21 16:20:00 -0500356 <template #modal-footer>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700357 <b-btn variant="secondary" @click="copyCsrString">
358 <template v-if="csrStringCopied">
359 <icon-checkmark />
360 {{ $t('global.status.copied') }}
361 </template>
362 <template v-else>
363 {{ $t('global.action.copy') }}
364 </template>
365 </b-btn>
366 <a
367 :href="`data:text/json;charset=utf-8,${csrString}`"
368 download="certificate.txt"
369 class="btn btn-primary"
370 >
371 {{ $t('global.action.download') }}
372 </a>
373 </template>
374 </b-modal>
375 </div>
376</template>
377
378<script>
379import IconAdd from '@carbon/icons-vue/es/add--alt/20';
380import IconCheckmark from '@carbon/icons-vue/es/checkmark/20';
381
382import { required, requiredIf } from 'vuelidate/lib/validators';
383
384import { COUNTRY_LIST } from './CsrCountryCodes';
SurenNeware61859092020-10-01 09:37:32 +0530385import { CERTIFICATE_TYPES } from '@/store/modules/AccessControl/SslCertificatesStore';
386import BVToastMixin from '@/components/Mixins/BVToastMixin';
387import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700388
389export default {
390 name: 'ModalGenerateCsr',
391 components: { IconAdd, IconCheckmark },
392 mixins: [BVToastMixin, VuelidateMixin],
393 data() {
394 return {
395 form: {
396 certificateType: null,
397 country: null,
398 state: null,
399 city: null,
400 companyName: null,
401 companyUnit: null,
402 commonName: null,
403 challengePassword: null,
404 contactPerson: null,
405 emailAddress: null,
406 alternateName: [],
407 keyPairAlgorithm: null,
408 keyCurveId: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500409 keyBitLength: null,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700410 },
411 certificateOptions: CERTIFICATE_TYPES.reduce((arr, cert) => {
412 if (cert.type === 'TrustStore Certificate') return arr;
413 arr.push({
414 text: cert.label,
Derick Montague602e98a2020-10-21 16:20:00 -0500415 value: cert.type,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700416 });
417 return arr;
418 }, []),
Derick Montague602e98a2020-10-21 16:20:00 -0500419 countryOptions: COUNTRY_LIST.map((country) => ({
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700420 text: country.label,
Derick Montague602e98a2020-10-21 16:20:00 -0500421 value: country.code,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700422 })),
423 keyPairAlgorithmOptions: ['EC', 'RSA'],
424 keyCurveIdOptions: ['prime256v1', 'secp521r1', 'secp384r1'],
425 keyBitLengthOptions: [2048],
426 csrString: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500427 csrStringCopied: false,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700428 };
429 },
430 validations: {
431 form: {
432 certificateType: { required },
433 country: { required },
434 state: { required },
435 city: { required },
436 companyName: { required },
437 companyUnit: { required },
438 commonName: { required },
439 challengePassword: {},
440 contactPerson: {},
441 emailAddress: {},
442 alternateName: {},
443 keyPairAlgorithm: { required },
444 keyCurveId: {
Derick Montague602e98a2020-10-21 16:20:00 -0500445 reuired: requiredIf(function (form) {
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700446 return form.keyPairAlgorithm === 'EC';
Derick Montague602e98a2020-10-21 16:20:00 -0500447 }),
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700448 },
449 keyBitLength: {
Derick Montague602e98a2020-10-21 16:20:00 -0500450 reuired: requiredIf(function (form) {
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700451 return form.keyPairAlgorithm === 'RSA';
Derick Montague602e98a2020-10-21 16:20:00 -0500452 }),
453 },
454 },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700455 },
456 methods: {
457 handleSubmit() {
458 this.$v.$touch();
459 if (this.$v.$invalid) return;
460 this.$store
461 .dispatch('sslCertificates/generateCsr', this.form)
462 .then(({ data: { CSRString } }) => {
463 this.csrString = CSRString;
464 this.$bvModal.show('csr-string');
465 this.$v.$reset();
466 });
467 },
468 resetForm() {
469 for (let key of Object.keys(this.form)) {
470 if (key === 'alternateName') {
471 this.form[key] = [];
472 } else {
473 this.form[key] = null;
474 }
475 }
476 },
477 onOkGenerateCsrModal(bvModalEvt) {
478 // prevent modal close
479 bvModalEvt.preventDefault();
480 this.handleSubmit();
481 },
482 onHiddenCsrStringModal() {
483 this.csrString = '';
484 this.resetForm();
485 },
486 copyCsrString(bvModalEvt) {
487 // prevent modal close
488 bvModalEvt.preventDefault();
489 navigator.clipboard.writeText(this.csrString).then(() => {
490 // Show copied text for 5 seconds
491 this.csrStringCopied = true;
492 setTimeout(() => {
493 this.csrStringCopied = false;
494 }, 5000 /*5 seconds*/);
495 });
Derick Montague602e98a2020-10-21 16:20:00 -0500496 },
497 },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700498};
499</script>