protected function insertKey(array $keyData, array $nodeData) : bool
{
$supplier = \preg_replace('/[^A-Za-z0-9_\\-]/', '', $keyData['supplier']);
if (empty($supplier)) {
throw new InvalidType(\__('Expected non-empty string for supplier name.'));
}
$filePath = ROOT . '/config/supplier_keys/' . $supplier . '.json';
if (\file_exists($filePath)) {
$supplierData = \Airship\loadJSON($filePath);
if (!$this->verifyMasterSignature($supplierData, $keyData, $nodeData)) {
return false;
}
// Create new entry
$supplierData['signing_keys'][] = ['type' => $keyData['type'] ?? 'signing', 'public_key' => $keyData['public_key']];
return \file_put_contents($filePath, \json_encode($supplierData, JSON_PRETTY_PRINT)) !== false;
} elseif ($keyData['type'] === 'master') {
// The supplier's first key.
$supplierData = ['channels' => [$this->channel], 'signing_keys' => [['type' => 'master', 'public_key' => $keyData['public_key']]]];
return \file_put_contents($filePath, \json_encode($supplierData, JSON_PRETTY_PRINT)) !== false;
}
// Fail closed:
return false;
}