embedded config support is now present for a locally saved private key or a remote private key, but decryption is currently a stub

master
Tim Bazuin 5 years ago
parent a9c368e980
commit aa8812b837

@ -39,7 +39,51 @@ $(function () {
}
function handleEmbeddedResult(data) {
console.log("I haven't implemented this yet")
var fileReader = new FileReader();
fileReader.onload = function() {
var text = this.result;
if (keyFileContent === null) {
saveText(text, 'server-embedded.conf');
}
var match = /<key>/.exec(text);
matchOffset = match.index + 6;
text = text.substring(0, matchOffset) + keyFileContent + text.substring(matchOffset);
if (decryptKeyCheckbox.prop('checked') === true) {
var keyPassword = password.val();
text = decryptKey(text, keyPassword);
}
saveText(text, 'server-embedded.conf');
};
fileReader.readAsText(data);
}
function decryptKey(text, keyPassword) {
var match = /<key>/.exec(text);
var keyStartOffset = match.index + 6;
match = /<\/key>/.exec(text);
var keyEndOffset = match.index;
var keyContent = text.substring(keyStartOffset, keyEndOffset);
var decryptedKey = 'DECRYPTED_KEY';
// actual decryption happens here
return text.substring(0, keyStartOffset) + decryptedKey + text.substring(keyEndOffset);
}
function saveText(text, fileName) {
var blob = new Blob([text], {type: 'text/plain'});
var blobUrl = URL.createObjectURL(blob);
saveBlobUrl(blobUrl, fileName);
}
var downloadElement = document.createElement("a");
@ -54,15 +98,12 @@ $(function () {
}
function submitCertificateForm(event) {
console.log('submitCert');
var url = getCertificateForm.attr('action'),
method = getCertificateForm.attr('method'),
data = getCertificateForm.serialize(),
dataType = 'application/zip',
handler = handleZipResult;
if (embedConfiguration.checked) {
dataType = 'text/plain';
if (embedConfiguration.prop('checked') === true) {
handler = handleEmbeddedResult;
}

@ -17,14 +17,21 @@ class Action extends Session
$zip = new \ZipArchive();
$zip->open($zipFile, \ZipArchive::CREATE);
$cert = $this->post('cert');
if ($cert === null) {
$this->getResponse()
->withStatus(500)
->write('Stop messing with the form');
}
$wantEmbedded = $this->post('want-embedded');
$server = ServerQuery::create()->findOneByFingerprint($this->post('fingerprint'));
$name = $server->getFqdn();
if ($cert !== null && $wantEmbedded !== null) {
if ($wantEmbedded !== null) {
$certModel = CertificateQuery::create()->findOneByUserAndName($this->getUser(), $cert);
$config = $this->getEmbeddedConfig($zip, $server, $certModel);
$config = $this->getEmbeddedConfig($server, $certModel);
$name .= '-' . $certModel->getName() . '.' . $certModel->getSerial();
return $this->getResponse()
@ -33,16 +40,13 @@ class Action extends Session
->write($config);
}
if ($cert !== null && $wantEmbedded === null) {
$certModel = CertificateQuery::create()->findOneByUserAndName($this->getUser(), $cert);
$this->addClientCertificateData($zip, $certModel);
$name .= '-' . $certModel->getName() . '.' . $certModel->getSerial();
}
$certModel = CertificateQuery::create()->findOneByUserAndName($this->getUser(), $cert);
$this->addClientCertificateData($zip, $certModel);
if ($wantEmbedded === null) {
$this->fillZipWithCaAndConfig($zip, $server);
}
$name .= '-' . $certModel->getName() . '.' . $certModel->getSerial();
$this->fillZipWithCaAndConfig($zip, $server);
$zip->close();

Loading…
Cancel
Save