Version 1.6

This commit is contained in:
sud0nick
2018-12-28 23:45:33 -05:00
parent a55c302c83
commit 4455ee1337
10 changed files with 456 additions and 16 deletions

View File

@@ -69,12 +69,21 @@ class Papers extends Module
case 'buildCert':
$this->buildCert($this->request->parameters);
break;
case 'encryptKey':
$this->respond($this->encryptKey($this->request->keyName, $this->request->keyType, $this->request->keyAlgo, $this->request->keyPass));
break;
case 'decryptKey':
$this->respond($this->decryptKey($this->request->keyName, $this->request->keyType, $this->request->keyPass));
break;
case 'genSSHKeys':
$this->genSSHKeys($this->request->parameters);
break;
case 'loadCertificates':
$this->loadCertificates();
break;
case 'loadCertProps':
$this->loadCertificateProperties($this->request->certName);
break;
case 'downloadKeys':
$this->downloadKeys($this->request->parameters->name, $this->request->parameters->type);
break;
@@ -288,6 +297,40 @@ class Papers extends Module
$this->respond(true, "Keys created successfully!");
}
private function encryptKey($keyName, $keyType, $algo, $pass) {
$retData = array();
$argString = "encryptKeys.sh --encrypt -k " . $keyName . " -a " . $algo . " -p " . $pass;
if ($keyType == "SSH") {
$argString .= " --ssh";
}
exec(__SCRIPTS__ . $argString, $retData);
$res = implode("\n", $retData);
if ($res != "Complete") {
$this->logError("Key Encryption Error", "The following error occurred:\n\n" . $res);
return false;
}
return true;
}
private function decryptKey($keyName, $keyType, $pass) {
$retData = array();
$argString = "decryptKeys.sh -k " . $keyName . " -p " . $pass;
if ($keyType == "SSH") {
$argString .= " --ssh";
}
exec(__SCRIPTS__ . $argString, $retData);
$res = implode("\n", $retData);
if ($res != "Complete") {
$this->logError("Key Decryption Error", "The following error occurred:\n\n" . $res);
return false;
}
return true;
}
/*
Generates an OpenSSL config file based on the passed in requirements ($req)
and returns the path to the file.
@@ -327,6 +370,29 @@ class Papers extends Module
$this->respond(true,null,$certs);
}
private function loadCertificateProperties($cert) {
$retData = array();
$res = [];
exec(__SCRIPTS__ . "getCertInfo.sh -k " . $cert, $retData);
if (count($retData) == 0) {
$this->respond(false);
return false;
}
// Create a mapping of the values that can be passed back to the front end
foreach ($retData as $line) {
$parts = explode("=", $line, 2);
$key = $parts[0];
$val = $parts[1];
$res[$key] = $val;
}
// Return success and the contents of the tmp file
$this->respond(true, null, $res);
return true;
}
private function getKeys($dir) {
$keyType = ($dir == __SSLSTORE__) ? "TLS/SSL" : "SSH";
$keys = scandir($dir);
@@ -603,7 +669,17 @@ class Papers extends Module
fclose($fh);
}
private function retrieveLog($logname, $type) {
$dir = ($type == "error") ? __LOGS__ : ($type == "help") ? __HELPFILES__ : __CHANGELOGS__;
switch($type) {
case "error":
$dir = __LOGS__;
break;
case "help":
$dir = __HELPFILES__;
break;
default:
$dir = __CHANGELOGS__;
break;
}
$data = file_get_contents($dir . $logname);
if (!$data) {
$this->respond(false);