mirror of https://github.com/MISP/MISP
fix: [gpg key] handle the lack of an instance key more gracefully
parent
47a997363c
commit
26ea06f2d9
|
@ -50,7 +50,7 @@ class CryptographicKeysController extends AppController
|
|||
if ($this->restResponsePayload) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$instanceKey = FileAccessTool::readFromFile(APP . 'webroot/gpg.asc');
|
||||
$instanceKey = file_exists(APP . 'webroot/gpg.asc') ? FileAccessTool::readFromFile(APP . 'webroot/gpg.asc') : '';
|
||||
$this->set('instanceKey', $instanceKey);
|
||||
$this->set('menuData', array('menuList' => 'cryptographic_keys', 'menuItem' => 'add_cryptographic_key'));
|
||||
}
|
||||
|
|
|
@ -88,6 +88,9 @@ class CryptographicKey extends AppModel
|
|||
$redisKey = "misp:instance_fingerprint";
|
||||
$fingerprint = $redis->get($redisKey);
|
||||
}
|
||||
if (!file_exists(APP . '/webroot/gpg.asc')) {
|
||||
return false;
|
||||
}
|
||||
if (empty($fingerprint)) {
|
||||
$file = new File(APP . '/webroot/gpg.asc');
|
||||
$instanceKey = $file->read();
|
||||
|
@ -107,7 +110,9 @@ class CryptographicKey extends AppModel
|
|||
|
||||
public function signWithInstanceKey($data)
|
||||
{
|
||||
$this->ingestInstanceKey();
|
||||
if (!$this->ingestInstanceKey()) {
|
||||
return false;
|
||||
}
|
||||
$data = preg_replace("/\s+/", "", $data);
|
||||
$signature = $this->gpg->sign($data, Crypt_GPG::SIGN_MODE_DETACHED);
|
||||
return $signature;
|
||||
|
@ -115,7 +120,9 @@ class CryptographicKey extends AppModel
|
|||
|
||||
public function signFileWithInstanceKey($path)
|
||||
{
|
||||
$this->ingestInstanceKey();
|
||||
if (!$this->ingestInstanceKey()) {
|
||||
return false;
|
||||
}
|
||||
$signature = $this->gpg->signFile($path, Crypt_GPG::SIGN_MODE_DETACHED);
|
||||
return $signature;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue