Skip to content

Commit 0d6e058

Browse files
authored
Merge pull request #774 from chaptergy/better-custom-certificate-handling
Better custom certificate handling
2 parents bc1c50a + 6af13d4 commit 0d6e058

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

backend/internal/certificate.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -615,18 +615,26 @@ const internalCertificate = {
615615
checkPrivateKey: (private_key) => {
616616
return tempWrite(private_key, '/tmp')
617617
.then((filepath) => {
618-
let key_type = private_key.includes('-----BEGIN RSA') ? 'rsa' : 'ec';
619-
return utils.exec('openssl ' + key_type + ' -in ' + filepath + ' -check -noout 2>&1 ')
620-
.then((result) => {
621-
if (!result.toLowerCase().includes('key ok') && !result.toLowerCase().includes('key valid') ) {
622-
throw new error.ValidationError('Result Validation Error: ' + result);
623-
}
624-
fs.unlinkSync(filepath);
625-
return true;
626-
}).catch((err) => {
627-
fs.unlinkSync(filepath);
628-
throw new error.ValidationError('Certificate Key is not valid (' + err.message + ')', err);
629-
});
618+
return new Promise((resolve, reject) => {
619+
const failTimeout = setTimeout(() => {
620+
reject(new error.ValidationError('Result Validation Error: Validation timed out. This could be due to the key being passphrase-protected.'));
621+
}, 10000);
622+
utils
623+
.exec('openssl pkey -in ' + filepath + ' -check -noout 2>&1 ')
624+
.then((result) => {
625+
clearTimeout(failTimeout);
626+
if (!result.toLowerCase().includes('key is valid')) {
627+
reject(new error.ValidationError('Result Validation Error: ' + result));
628+
}
629+
fs.unlinkSync(filepath);
630+
resolve(true);
631+
})
632+
.catch((err) => {
633+
clearTimeout(failTimeout);
634+
fs.unlinkSync(filepath);
635+
reject(new error.ValidationError('Certificate Key is not valid (' + err.message + ')', err));
636+
});
637+
});
630638
});
631639
},
632640

frontend/js/app/nginx/certificates/form.ejs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
</div>
130130
<% } else if (provider === 'other') { %>
131131
<!-- Other -->
132+
<div class="col-sm-12 col-md-12">
133+
<div class="text-blue mb-4"><i class="fe fe-alert-triangle"></i> <%= i18n('ssl', 'passphrase-protection-support-info') %></div>
134+
</div>
132135
<div class="col-sm-12 col-md-12">
133136
<div class="form-group">
134137
<label class="form-label"><%- i18n('str', 'name') %> <span class="form-required">*</span></label>

frontend/js/i18n/messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@
112112
"stored-as-plaintext-info": "This data will be stored as plaintext in the database and in a file!",
113113
"propagation-seconds": "Propagation Seconds",
114114
"propagation-seconds-info": "Leave empty to use the plugins default value. Number of seconds to wait for DNS propagation.",
115-
"processing-info": "Processing... This might take a few minutes."
115+
"processing-info": "Processing... This might take a few minutes.",
116+
"passphrase-protection-support-info": "Key files protected with a passphrase are not supported."
116117
},
117118
"proxy-hosts": {
118119
"title": "Proxy Hosts",

0 commit comments

Comments
 (0)