mirror of
https://github.com/friendica/friendica
synced 2025-05-03 14:24:09 +02:00
[Composer] Upgrade to phpseclib version 3
- Create custom Key file format for Salmon Magic key - Remove obsolete pemToME and MEtoPem Crypto methods - Remove unused newECKeypair Crypto method - Switch to constant-time Base64 encode/decode in Base64Url Strings methods
This commit is contained in:
parent
a3fb499735
commit
55640eec87
13 changed files with 241 additions and 173 deletions
105
tests/src/Protocol/SalmonTest.php
Normal file
105
tests/src/Protocol/SalmonTest.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Protocol;
|
||||
|
||||
use Friendica\Protocol\Salmon;
|
||||
|
||||
class SalmonTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function dataMagic(): array
|
||||
{
|
||||
return [
|
||||
'salmon' => [
|
||||
'magic' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/salmon-public-magic'),
|
||||
'pem' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/salmon-public-pem'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataMagic
|
||||
*
|
||||
* @param $magic
|
||||
* @param $pem
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testSalmonKey($magic, $pem)
|
||||
{
|
||||
$this->assertEquals($magic, Salmon::salmonKey($pem));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataMagic
|
||||
*
|
||||
* @param $magic
|
||||
* @param $pem
|
||||
* @return void
|
||||
*/
|
||||
public function testMagicKeyToPem($magic, $pem)
|
||||
{
|
||||
$this->assertEquals($pem, Salmon::magicKeyToPem($magic));
|
||||
}
|
||||
|
||||
public function dataMagicFailure(): array
|
||||
{
|
||||
return [
|
||||
'empty string' => [
|
||||
'magic' => '',
|
||||
],
|
||||
'Missing algo' => [
|
||||
'magic' => 'tvsoBZbLUvqWs-0d8C5hVQLjLCjjxyZb17Rm8_9FDqBYUigBSFDcJCzG27FM-zuddwpgJB0vDuPKQnt59kKRsw.AQAB',
|
||||
],
|
||||
'Missing modulus' => [
|
||||
'magic' => 'RSA.AQAB',
|
||||
],
|
||||
'Missing exponent' => [
|
||||
'magic' => 'RSA.tvsoBZbLUvqWs-0d8C5hVQLjLCjjxyZb17Rm8_9FDqBYUigBSFDcJCzG27FM-zuddwpgJB0vDuPKQnt59kKRsw',
|
||||
],
|
||||
'Missing key parts' => [
|
||||
'magic' => 'RSA.',
|
||||
],
|
||||
'Too many parts' => [
|
||||
'magic' => 'RSA.tvsoBZbLUvqWs-0d8C5hVQLjLCjjxyZb17Rm8_9FDqBYUigBSFDcJCzG27FM-zuddwpgJB0vDuPKQnt59kKRsw.AQAB.AQAB',
|
||||
],
|
||||
'Wrong encoding' => [
|
||||
'magic' => 'RSA.tvsoBZbLUvqWs-0d8C5hVQLjLCjjxyZb17Rm8/9FDqBYUigBSFDcJCzG27FM+zuddwpgJB0vDuPKQnt59kKRsw.AQAB',
|
||||
],
|
||||
'Wrong algo' => [
|
||||
'magic' => 'ECDSA.tvsoBZbLUvqWs-0d8C5hVQLjLCjjxyZb17Rm8_9FDqBYUigBSFDcJCzG27FM-zuddwpgJB0vDuPKQnt59kKRsw.AQAB',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataMagicFailure
|
||||
*
|
||||
* @param $magic
|
||||
* @return void
|
||||
*/
|
||||
public function testMagicKeyToPemFailure($magic)
|
||||
{
|
||||
$this->expectException(\Throwable::class);
|
||||
|
||||
Salmon::magicKeyToPem($magic);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue