commit d74b9c59ddb8d0154a4b0dacc441ec6364b4356e
Author: Jan Pašek <janpasek97@gmail.com>
Date:   Mon May 3 11:35:31 2021 +0200

    Re #8706 - Providing custom private key

diff --git a/static/create_certificate.html b/static/create_certificate.html
index cb04812..eb18526 100644
--- a/static/create_certificate.html
+++ b/static/create_certificate.html
@@ -185,6 +185,30 @@
                     <label class="form-check-label" for="isSSL_TLS">SSL/TLS</label><br>
                 </td>
             </tr>
+            <tr>
+                <div class="form-group form-check">
+                    <td><label class="form-check-label" for="specifyPasswordCheckbox" style="margin-top: 15px">Custom key:</label></td>
+                    <td class="pl-3">
+                        <input type="checkbox" v-model="customKey" id="specifyPasswordCheckbox" name="specifyPassword" class="mb-2 form-check-input form-check">
+                    </td>
+                </div>
+            </tr>
+            <tr v-if="customKey">
+                <div class="form-group">
+                    <td class="pl-5"><label for="key_password">Password:</label></td>
+                    <td class="pl-3">
+                        <input type="text" v-model:value="key.password" id="key_password" name="key_password" class="form-control">
+                    </td>
+                </div>
+            </tr>
+            <tr v-if="customKey">
+                <div class="form-group">
+                    <td class="pl-5"><label for="key_pem">Private key:</label></td>
+                    <td class="pl-3">
+                        <input type="file" v-on:change="onKeyFileChange" id="key_pem" name="key_pem" class="form-control-file">
+                    </td>
+                </div>
+            </tr>
             <tr>
                 <td align="center">
                     <button class="btn btn-success mt-3 w-auto" v-on:click="onCreateCertificate()">Create certificate</button>
diff --git a/static/js/create_certificate.js b/static/js/create_certificate.js
index 2b35e32..a930c62 100644
--- a/static/js/create_certificate.js
+++ b/static/js/create_certificate.js
@@ -6,6 +6,7 @@ var createCertificateApp = new Vue({
         notAfter: "",
         isSelfSigned: false,
         invalidCN: false,
+        customKey: false,
         // available certificate authorities
         authorities: [],
         // data of the selected certificate authorities to be displayed in the form
@@ -38,6 +39,10 @@ var createCertificateApp = new Vue({
             },
             CA: null
         },
+        key: {
+            password: null,
+            key_pem: null,
+        },
         errorMessage: ""
     },
     // actions to be performed when the page is loaded
@@ -66,6 +71,18 @@ var createCertificateApp = new Vue({
         }
     },
     methods: {
+        onKeyFileChange: function (event) {
+            var file = event.target.files[0];
+            var reader = new FileReader();
+            reader.readAsText(file, "UTF-8");
+            reader.onload = function (evt) {
+                createCertificateApp.key.key_pem = evt.target.result;
+            }
+            reader.onerror = function (evt) {
+                this.showError("Error occurred while reading custom private key file.");
+            }
+
+        },
         showError: function (message) {
             document.body.scrollTop = 0;
             document.documentElement.scrollTop = 0;
@@ -84,6 +101,15 @@ var createCertificateApp = new Vue({
                 this.invalidCN = true;
                 return;
             }
+
+            // populate optional key field in the request body
+            if (this.key.password != null && this.key.password !== "") {
+                this.certificateData.key.password = this.key.password;
+            }
+            if (this.key.key_pem != null) {
+                this.certificateData.key.key_pem = this.key.key_pem;
+            }
+
             this.certificateData.validityDays = parseInt(this.certificateData.validityDays);
             try {
                 const response = await axios.post(API_URL + "certificates", this.certificateData);
@@ -95,7 +121,7 @@ var createCertificateApp = new Vue({
                     createCertificateApp.showError(response.data["data"]);
                 }
             } catch (error) {
-                console.log(error);
+                createCertificateApp.showError(response.data["data"]);
             }
         }
     },
