| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Jose\Component\KeyManagement\Analyzer; |
| 6 |
|
| 7 |
use Jose\Component\Core\JWKSet; |
| 8 |
|
| 9 |
final class MixedPublicAndPrivateKeys implements KeysetAnalyzer |
| 10 |
{ |
| 11 |
public function analyze(JWKSet $jwkset, MessageBag $bag): void |
| 12 |
{ |
| 13 |
if ($jwkset->count() === 0) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
$hasPublicKeys = false; |
| 18 |
$hasPrivateKeys = false; |
| 19 |
|
| 20 |
foreach ($jwkset as $jwk) { |
| 21 |
switch ($jwk->get('kty')) { |
| 22 |
case 'OKP': |
| 23 |
case 'RSA': |
| 24 |
case 'EC': |
| 25 |
if ($jwk->has('d')) { |
| 26 |
$hasPrivateKeys = true; |
| 27 |
} else { |
| 28 |
$hasPublicKeys = true; |
| 29 |
} |
| 30 |
|
| 31 |
break; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
if ($hasPrivateKeys && $hasPublicKeys) { |
| 36 |
$bag->add(Message::high('This key set mixes public and private keys.')); |
| 37 |
} |
| 38 |
} |
| 39 |
} |