Skip to content

Commit

Permalink
Fix ECDH-SS alg and AlgorithmManagerFactory construct method
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Feb 2, 2024
1 parent 2e0a0aa commit cd826e7
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 82 deletions.
10 changes: 10 additions & 0 deletions src/Library/Core/AlgorithmManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ class AlgorithmManagerFactory
{
private array $algorithms = [];

/**
* @param Algorithm[] $algorithms
*/
public function __construct(array $algorithms = [])
{
foreach ($algorithms as $algorithm) {
$this->add($algorithm->name(), $algorithm);
}
}

/**
* Adds an algorithm.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ public function getAgreementKey(
return ConcatKDF::generate($agreed_key, $algorithm, $encryptionKeyLength, $apu, $apv);
}

public function name(): string
{
return 'ECDH-ES';
}

public function getKeyManagementMode(): string
{
return self::MODE_AGREEMENT;
Expand Down
4 changes: 4 additions & 0 deletions src/Library/Encryption/Algorithm/KeyEncryption/ECDHES.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

final class ECDHES extends AbstractECDH
{
public function name(): string
{
return 'ECDH-ES';
}
}
5 changes: 5 additions & 0 deletions src/Library/Encryption/Algorithm/KeyEncryption/ECDHSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

final class ECDHSS extends AbstractECDH
{
public function name(): string
{
return 'ECDH-SS';
}

/**
* @param array<string, mixed> $complete_header
* @param array<string, mixed> $additional_header_values
Expand Down
3 changes: 1 addition & 2 deletions tests/Component/Core/AlgorithmManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public function iCannotGetAnAlgorithmThatDoesNotExist(): void
private function getAlgorithmManagerFactory(): AlgorithmManagerFactory
{
if ($this->algorithmManagerFactory === null) {
$this->algorithmManagerFactory = new AlgorithmManagerFactory();
$this->algorithmManagerFactory->add('foo', new FooAlgorithm());
$this->algorithmManagerFactory = new AlgorithmManagerFactory([new FooAlgorithm()]);
}

return $this->algorithmManagerFactory;
Expand Down
57 changes: 29 additions & 28 deletions tests/Component/Encryption/EncryptionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,35 @@ abstract class EncryptionTestCase extends TestCase
protected function getAlgorithmManagerFactory(): AlgorithmManagerFactory
{
if ($this->algorithmManagerFactory === null) {
$this->algorithmManagerFactory = new AlgorithmManagerFactory();
$this->algorithmManagerFactory->add('A128GCM', new A128GCM());
$this->algorithmManagerFactory->add('A192GCM', new A192GCM());
$this->algorithmManagerFactory->add('A256GCM', new A256GCM());
$this->algorithmManagerFactory->add('A128CBC-HS256', new A128CBCHS256());
$this->algorithmManagerFactory->add('A192CBC-HS384', new A192CBCHS384());
$this->algorithmManagerFactory->add('A256CBC-HS512', new A256CBCHS512());
$this->algorithmManagerFactory->add('A128GCMKW', new A128GCMKW());
$this->algorithmManagerFactory->add('A192GCMKW', new A192GCMKW());
$this->algorithmManagerFactory->add('A256GCMKW', new A256GCMKW());
$this->algorithmManagerFactory->add('A128KW', new A128KW());
$this->algorithmManagerFactory->add('A192KW', new A192KW());
$this->algorithmManagerFactory->add('A256KW', new A256KW());
$this->algorithmManagerFactory->add('dir', new Dir());
$this->algorithmManagerFactory->add('ECDH-ES', new ECDHES());
$this->algorithmManagerFactory->add('ECDH-ES+A128KW', new ECDHESA128KW());
$this->algorithmManagerFactory->add('ECDH-ES+A192KW', new ECDHESA192KW());
$this->algorithmManagerFactory->add('ECDH-ES+A256KW', new ECDHESA256KW());
$this->algorithmManagerFactory->add('ECDH-SS', new ECDHSS());
$this->algorithmManagerFactory->add('ECDH-SS+A128KW', new ECDHSSA128KW());
$this->algorithmManagerFactory->add('ECDH-SS+A192KW', new ECDHSSA192KW());
$this->algorithmManagerFactory->add('ECDH-SS+A256KW', new ECDHSSA256KW());
$this->algorithmManagerFactory->add('PBES2-HS256+A128KW', new PBES2HS256A128KW());
$this->algorithmManagerFactory->add('PBES2-HS384+A192KW', new PBES2HS384A192KW());
$this->algorithmManagerFactory->add('PBES2-HS512+A256KW', new PBES2HS512A256KW());
$this->algorithmManagerFactory->add('RSA1_5', new RSA15());
$this->algorithmManagerFactory->add('RSA-OAEP', new RSAOAEP());
$this->algorithmManagerFactory->add('RSA-OAEP-256', new RSAOAEP256());
$this->algorithmManagerFactory = new AlgorithmManagerFactory([
new A128GCM(),
new A192GCM(),
new A256GCM(),
new A128CBCHS256(),
new A192CBCHS384(),
new A256CBCHS512(),
new A128GCMKW(),
new A192GCMKW(),
new A256GCMKW(),
new A128KW(),
new A192KW(),
new A256KW(),
new Dir(),
new ECDHES(),
new ECDHESA128KW(),
new ECDHESA192KW(),
new ECDHESA256KW(),
new ECDHSS(),
new ECDHSSA128KW(),
new ECDHSSA192KW(),
new ECDHSSA256KW(),
new PBES2HS256A128KW(),
new PBES2HS384A192KW(),
new PBES2HS512A256KW(),
new RSA15(),
new RSAOAEP(),
new RSAOAEP256(),
]);
}

return $this->algorithmManagerFactory;
Expand Down
49 changes: 25 additions & 24 deletions tests/Component/NestedToken/NestedTokenTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,31 @@ abstract class NestedTokenTestCase extends TestCase
protected function getAlgorithmManagerFactory(): AlgorithmManagerFactory
{
if ($this->algorithmManagerFactory === null) {
$this->algorithmManagerFactory = new AlgorithmManagerFactory();
$this->algorithmManagerFactory->add('A128GCM', new A128GCM());
$this->algorithmManagerFactory->add('A192GCM', new A192GCM());
$this->algorithmManagerFactory->add('A256GCM', new A256GCM());
$this->algorithmManagerFactory->add('A128CBC-HS256', new A128CBCHS256());
$this->algorithmManagerFactory->add('A192CBC-HS384', new A192CBCHS384());
$this->algorithmManagerFactory->add('A256CBC-HS512', new A256CBCHS512());
$this->algorithmManagerFactory->add('A128GCMKW', new A128GCMKW());
$this->algorithmManagerFactory->add('A192GCMKW', new A192GCMKW());
$this->algorithmManagerFactory->add('A256GCMKW', new A256GCMKW());
$this->algorithmManagerFactory->add('A128KW', new A128KW());
$this->algorithmManagerFactory->add('A192KW', new A192KW());
$this->algorithmManagerFactory->add('A256KW', new A256KW());
$this->algorithmManagerFactory->add('dir', new Dir());
$this->algorithmManagerFactory->add('ECDH-ES', new ECDHES());
$this->algorithmManagerFactory->add('ECDH-ES+A128KW', new ECDHESA128KW());
$this->algorithmManagerFactory->add('ECDH-ES+A192KW', new ECDHESA192KW());
$this->algorithmManagerFactory->add('ECDH-ES+A256KW', new ECDHESA256KW());
$this->algorithmManagerFactory->add('PBES2-HS256+A128KW', new PBES2HS256A128KW());
$this->algorithmManagerFactory->add('PBES2-HS384+A192KW', new PBES2HS384A192KW());
$this->algorithmManagerFactory->add('PBES2-HS512+A256KW', new PBES2HS512A256KW());
$this->algorithmManagerFactory->add('RSA1_5', new RSA15());
$this->algorithmManagerFactory->add('RSA-OAEP', new RSAOAEP());
$this->algorithmManagerFactory->add('RSA-OAEP-256', new RSAOAEP256());
$this->algorithmManagerFactory = new AlgorithmManagerFactory([
new A128GCM(),
new A192GCM(),
new A256GCM(),
new A128CBCHS256(),
new A192CBCHS384(),
new A256CBCHS512(),
new A128GCMKW(),
new A192GCMKW(),
new A256GCMKW(),
new A128KW(),
new A192KW(),
new A256KW(),
new Dir(),
new ECDHES(),
new ECDHESA128KW(),
new ECDHESA192KW(),
new ECDHESA256KW(),
new PBES2HS256A128KW(),
new PBES2HS384A192KW(),
new PBES2HS512A256KW(),
new RSA15(),
new RSAOAEP(),
new RSAOAEP256(),
]);
}
return $this->algorithmManagerFactory;
}
Expand Down
9 changes: 5 additions & 4 deletions tests/Component/NestedToken/NestingTokenBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ private function getJWSSerializerManagerFactory(): JwsSerializer\JWSSerializerMa
private function getAlgorithmManagerFactory(): AlgorithmManagerFactory
{
if ($this->algorithmManagerFactory === null) {
$this->algorithmManagerFactory = new AlgorithmManagerFactory();
$this->algorithmManagerFactory->add('A128GCM', new A128GCM());
$this->algorithmManagerFactory->add('RSA-OAEP', new RSAOAEP());
$this->algorithmManagerFactory->add('PS256', new PS256());
$this->algorithmManagerFactory = new AlgorithmManagerFactory([
new A128GCM(),
new RSAOAEP(),
new PS256(),
]);
}

return $this->algorithmManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ private function getJWSVerifierFactory(): JWSVerifierFactory
private function getAlgorithmManagerFactory(): AlgorithmManagerFactory
{
if ($this->algorithmManagerFactory === null) {
$this->algorithmManagerFactory = new AlgorithmManagerFactory();
$this->algorithmManagerFactory->add('A128GCM', new A128GCM());
$this->algorithmManagerFactory->add('RSA-OAEP', new RSAOAEP());
$this->algorithmManagerFactory->add('PS256', new PS256());
$this->algorithmManagerFactory = new AlgorithmManagerFactory([
new A128GCM(),
new RSAOAEP(),
new PS256(),
]);
}

return $this->algorithmManagerFactory;
Expand Down
31 changes: 16 additions & 15 deletions tests/Component/Signature/SignatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@ abstract class SignatureTestCase extends TestCase
protected function getAlgorithmManagerFactory(): AlgorithmManagerFactory
{
if ($this->algorithmManagerFactory === null) {
$this->algorithmManagerFactory = new AlgorithmManagerFactory();
$this->algorithmManagerFactory->add('HS256', new HS256());
$this->algorithmManagerFactory->add('HS384', new HS384());
$this->algorithmManagerFactory->add('HS512', new HS512());
$this->algorithmManagerFactory->add('ES256', new ES256());
$this->algorithmManagerFactory->add('ES384', new ES384());
$this->algorithmManagerFactory->add('ES512', new ES512());
$this->algorithmManagerFactory->add('RS256', new RS256());
$this->algorithmManagerFactory->add('RS384', new RS384());
$this->algorithmManagerFactory->add('RS512', new RS512());
$this->algorithmManagerFactory->add('PS256', new PS256());
$this->algorithmManagerFactory->add('PS384', new PS384());
$this->algorithmManagerFactory->add('PS512', new PS512());
$this->algorithmManagerFactory->add('none', new None());
$this->algorithmManagerFactory->add('EdDSA', new EdDSA());
$this->algorithmManagerFactory = new AlgorithmManagerFactory([
new HS256(),
new HS384(),
new HS512(),
new ES256(),
new ES384(),
new ES512(),
new RS256(),
new RS384(),
new RS512(),
new PS256(),
new PS384(),
new PS512(),
new None(),
new EdDSA(),
]);
}

return $this->algorithmManagerFactory;
Expand Down

0 comments on commit cd826e7

Please sign in to comment.