Esempio n. 1
0
 /**
  * Return the appropriate supplier (or create it if it doesn't already exist)
  *
  * @param Channel $chan
  * @param array $updateData
  * @return Supplier
  * @throws CouldNotUpdate
  */
 protected function loadSupplier(Channel $chan, array $updateData) : Supplier
 {
     // No invalid names:
     $this->supplierName = \preg_replace('#[^A-Za-z0-9\\-_]#', '', $updateData['supplier']);
     try {
         if (!\file_exists(ROOT . '/config/supplier_keys/' . $this->supplierName . '.json')) {
             throw new NoSupplier($this->supplierName);
         }
         return $chan->getSupplier($this->supplierName);
     } catch (NoSupplier $ex) {
         if ($updateData['action'] !== self::ACTION_INSERT_KEY) {
             throw new CouldNotUpdate(\__('For new suppliers, we can only insert their first master key.'), 0, $ex);
         }
         if ($updateData['type'] !== self::KEY_TYPE_MASTER) {
             throw new CouldNotUpdate(\__('Non-master key provided. It is possible that the channel is borked.'), 0, $ex);
         }
         // If we reach here, it's a new supplier.
         $this->isNewSupplier = true;
         return $chan->createSupplier($updateData);
     }
 }
Esempio n. 2
0
 /**
  * We're storing a new public key for this supplier.
  *
  * @param Channel $chan
  * @param TreeUpdate $update
  * @return void
  */
 protected function revokeKey(Channel $chan, TreeUpdate $update)
 {
     $supplier = $update->getSupplier();
     $name = $supplier->getName();
     $file = ROOT . '/config/supplier_keys/' . $name . '.json';
     $supplierData = \Airship\loadJSON($file);
     foreach ($supplierData['signing_keys'] as $id => $skey) {
         if (\hash_equals($skey['public_key'], $update->getPublicKeyString())) {
             // Remove this key
             unset($supplierData['signing_keys'][$id]);
             break;
         }
     }
     \Airship\saveJSON($file, $supplierData);
     \clearstatcache();
     // Flush the channel's supplier cache
     $chan->getSupplier($name, true);
 }