cerebrate/tests/Fixture/EncryptionKeysFixture.php

134 lines
6.2 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace App\Test\Fixture;
use Cake\Http\Exception\NotImplementedException;
use Cake\TestSuite\Fixture\TestFixture;
class EncryptionKeysFixture extends TestFixture
{
public $connection = 'test';
public const ENCRYPTION_KEY_ORG_A_ID = 1;
public const ENCRYPTION_KEY_ORG_B_ID = 2;
public const TYPE_PGP = 'pgp';
public const TYPE_SMIME = 'smime';
public const KEY_TYPE_EDCH = 'EDCH';
public const KEY_TYPE_RSA = 'RSA';
public const KEY_TYPE_SMIME = 'S/MIME';
public function init(): void
{
$faker = \Faker\Factory::create();
$this->records = [
[
'id' => self::ENCRYPTION_KEY_ORG_A_ID,
'uuid' => $faker->uuid(),
'type' => self::TYPE_PGP,
'encryption_key' => $this->getPublicKey(self::KEY_TYPE_EDCH),
'revoked' => false,
'expires' => null,
'owner_id' => OrganisationsFixture::ORGANISATION_A_ID,
'owner_model' => 'Organisation',
'created' => $faker->dateTime()->getTimestamp(),
'modified' => $faker->dateTime()->getTimestamp()
],
[
'id' => self::ENCRYPTION_KEY_ORG_B_ID,
'uuid' => $faker->uuid(),
'type' => self::TYPE_PGP,
'encryption_key' => $this->getPublicKey(self::KEY_TYPE_EDCH),
'revoked' => false,
'expires' => null,
'owner_id' => OrganisationsFixture::ORGANISATION_B_ID,
'owner_model' => 'Organisation',
'created' => $faker->dateTime()->getTimestamp(),
'modified' => $faker->dateTime()->getTimestamp()
],
];
parent::init();
}
public static function getPublicKey(string $type): string
{
switch ($type) {
case self::KEY_TYPE_EDCH:
return <<<EOD
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: OpenPGP v1.0.0
xm8EYeaEmhMFK4EEACIDAwTS1DNpEsyLo6ynsxJhe1J1k75OYGjkiYgj+4157e06
m8uNX9TRI3XKAKUs2ecG6Iv6beXpvLHcBu/GqwYnpLigpABkhLbUob5spIg+OqNA
l0U75pLyshmQ8DOWupjq2ZT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WRg6VaVAFXX21dlQwIf
XUzE5dzw+nOspVE=
=WnCK
-----END PGP PUBLIC KEY BLOCK-----
EOD;
default:
throw new NotImplementedException('Unknown key type');
}
}
private static function getPrivateKey(string $type): string
{
switch ($type) {
case self::KEY_TYPE_EDCH:
return <<<EOD
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: OpenPGP v1.0.0
xcASBGHmhJoTBSuBBAAiAwME0tQzaRLMi6Osp7MSYXtSdZO+TmBo5ImII/uNee3t
OpvLjV/U0SN1ygClLNnnBuiL+m3l6byx3AbvxqsGJ6S4oKQAZIS21KG+bKSIPjqj
QJdFO+aS8rIZkPAzlrqY6tmU/gkDCCcuNcl1iEuoYIjwDlg5yqzxdXu9Q7V+WvBf
OflkWwIGYLjrqcDWNZqz9v4alO8/uKPZoRyYmQx3yBxjgrNs4bjibFxc43oTlHtD
JA7m+Ba4cWyMVFJ96TPXAvI5fAJszRtmb29iYXIgPGZvb2JhckBleGFtcGxlLmNv
bT7CjwQTEwoAFwUCYeaEmgIbLwMLCQcDFQoIAh4BAheAAAoJEH2CeDbFoGZamnYB
egKb9EtyayYJlHo0VWjAaAJRpTBOjom3wKP32mMjoTv7W9CsPDGH6xduw/jd/00f
AQF9HioSb4XKB2ZXG+hPsVLwE/c2MgqV+oNbNq1PaniyRG1nhIs+/3tXYmIENk7r
iU6/x6UEYeaEmhMIKoZIzj0DAQcCAwR0xpFCfTHAgBjAff44cySfWq2CyHTFMB28
X+vCt8kGokH9hdAVHIs9+yNqRTwVdewic7B3aCBuK4a1ODyPrK87/gkDCCiGr5A8
Yq+pYCpNvctmdVC3wwN+LNpiXHtkYWD37TdpwrdR0h8H/PSZFdHgkyK3tqmxPApC
S3+s+cBzza5mTPqaq/7Cc6ck40juXNBIC8rCwCcEGBMKAA8FAmHmhJoFCQ8JnAAC
Gy4AagkQfYJ4NsWgZlpfIAQZEwoABgUCYeaEmgAKCRC+TAWGbVzhxvHIAP9C6iog
C55FEE8XuQ2g6dPyIyou940sL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