fix: [gpg key] handle the lack of an instance key more gracefully

pull/8213/head
iglocska 2022-03-17 02:31:45 +01:00
parent 47a997363c
commit 26ea06f2d9
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
2 changed files with 10 additions and 3 deletions

View File

@ -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'));
}

View File

@ -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;
}