Skip to content

Commit af6abd9

Browse files
authored
Deleting Sensio Extra (#185)
* Deleting Sensio Extra * Safe for Cose fix
1 parent 6319817 commit af6abd9

18 files changed

+108
-25
lines changed

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"psr/http-message": "^1.0",
5555
"psr/log": "^1.1",
5656
"ramsey/uuid": "^3.8|^4.0",
57-
"sensio/framework-extra-bundle": "^5.2",
5857
"spomky-labs/base64url": "^2.0",
5958
"spomky-labs/cbor-bundle": "^2.0",
6059
"spomky-labs/cbor-php": "^1.1|^2.0",

phpstan.neon

+24
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@ parameters:
1111
- '#Parameter (.*) of class FG\\ASN1\\Universal\\Integer constructor expects int, string given\.#'
1212
- '#Instanceof between Symfony\\Component\\HttpFoundation\\Response and Symfony\\Component\\HttpFoundation\\Response will always evaluate to true\.#'
1313
- '#Parameter (.*) of class Jose\\Component\\Core\\AlgorithmManager constructor expects array\<Jose\\Component\\Core\\Algorithm\>\, array\<int\, object\> given\.#'
14+
- message: '#Function .* is unsafe to use\. .* Please add .* at the beginning of the file to use the variant provided by the .* library\.#'
15+
count: 1
16+
path: 'src/cose/src/Algorithm/ManagerFactory.php'
17+
- message: '#Function .* is unsafe to use\. .* Please add .* at the beginning of the file to use the variant provided by the .* library\.#'
18+
count: 1
19+
path: 'src/cose/src/Algorithm/Signature/ECDSA/ECDSA.php'
20+
- message: '#Function .* is unsafe to use\. .* Please add .* at the beginning of the file to use the variant provided by the .* library\.#'
21+
count: 2
22+
path: 'src/cose/src/Algorithm/Signature/ECDSA/ECSignature.php'
23+
- message: '#Function .* is unsafe to use\. .* Please add .* at the beginning of the file to use the variant provided by the .* library\.#'
24+
count: 1
25+
path: 'src/cose/src/Algorithm/Signature/RSA/PSSRSA.php'
26+
- message: '#Function .* is unsafe to use\. .* Please add .* at the beginning of the file to use the variant provided by the .* library\.#'
27+
count: 1
28+
path: 'src/cose/src/Algorithm/Signature/RSA/RSA.php'
29+
- message: '#Function .* is unsafe to use\. .* Please add .* at the beginning of the file to use the variant provided by the .* library\.#'
30+
count: 2
31+
path: 'src/cose/src/Key/Ec2Key.php'
32+
- message: '#Function .* is unsafe to use\. .* Please add .* at the beginning of the file to use the variant provided by the .* library\.#'
33+
count: 1
34+
path: 'src/cose/src/Key/Key.php'
35+
- message: '#Function .* is unsafe to use\. .* Please add .* at the beginning of the file to use the variant provided by the .* library\.#'
36+
count: 3
37+
path: 'src/cose/src/Key/RsaKey.php'
1438
checkMissingIterableValueType: false
1539
checkGenericClassInNonGenericObjectType: false
1640
treatPhpDocTypesAsCertain: false

src/cose/src/Algorithm/ManagerFactory.php

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Cose\Algorithm;
1515

1616
use Assert\Assertion;
17-
use function Safe\sprintf;
1817

1918
class ManagerFactory
2019
{

src/cose/src/Algorithm/Signature/ECDSA/ECDSA.php

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Cose\Algorithm\Signature\Signature;
1818
use Cose\Key\Ec2Key;
1919
use Cose\Key\Key;
20-
use function Safe\openssl_sign;
2120

2221
abstract class ECDSA implements Signature
2322
{

src/cose/src/Algorithm/Signature/ECDSA/ECSignature.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use InvalidArgumentException;
2020
use function mb_strlen;
2121
use function mb_substr;
22-
use function Safe\hex2bin;
2322
use function str_pad;
2423
use const STR_PAD_LEFT;
2524

@@ -53,12 +52,17 @@ public static function toAsn1(string $signature, int $length): string
5352
$totalLength = $lengthR + $lengthS + self::BYTE_SIZE + self::BYTE_SIZE;
5453
$lengthPrefix = $totalLength > self::ASN1_MAX_SINGLE_BYTE ? self::ASN1_LENGTH_2BYTES : '';
5554

56-
return hex2bin(
55+
$bin = hex2bin(
5756
self::ASN1_SEQUENCE
5857
.$lengthPrefix.dechex($totalLength)
5958
.self::ASN1_INTEGER.dechex($lengthR).$pointR
6059
.self::ASN1_INTEGER.dechex($lengthS).$pointS
6160
);
61+
if (false === $bin) {
62+
throw new InvalidArgumentException('Unable to convert into ASN.1');
63+
}
64+
65+
return $bin;
6266
}
6367

6468
public static function fromAsn1(string $signature, int $length): string
@@ -78,7 +82,12 @@ public static function fromAsn1(string $signature, int $length): string
7882
$pointR = self::retrievePositiveInteger(self::readAsn1Integer($message, $position));
7983
$pointS = self::retrievePositiveInteger(self::readAsn1Integer($message, $position));
8084

81-
return hex2bin(str_pad($pointR, $length, '0', STR_PAD_LEFT).str_pad($pointS, $length, '0', STR_PAD_LEFT));
85+
$bin = hex2bin(str_pad($pointR, $length, '0', STR_PAD_LEFT).str_pad($pointS, $length, '0', STR_PAD_LEFT));
86+
if (false === $bin) {
87+
throw new InvalidArgumentException('Unable to convert from ASN.1');
88+
}
89+
90+
return $bin;
8291
}
8392

8493
private static function octetLength(string $data): int

src/cose/src/Algorithm/Signature/RSA/PSSRSA.php

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use function ord;
2828
use function random_bytes;
2929
use RuntimeException;
30-
use function Safe\pack;
3130
use function str_pad;
3231
use function str_repeat;
3332

src/cose/src/Algorithm/Signature/RSA/RSA.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Cose\Algorithm\Signature\Signature;
1818
use Cose\Key\Key;
1919
use Cose\Key\RsaKey;
20-
use function Safe\openssl_sign;
20+
use InvalidArgumentException;
2121

2222
abstract class RSA implements Signature
2323
{
@@ -26,7 +26,9 @@ public function sign(string $data, Key $key): string
2626
$key = $this->handleKey($key);
2727
Assertion::true($key->isPrivate(), 'The key is not private');
2828

29-
openssl_sign($data, $signature, $key->asPem(), $this->getHashAlgorithm());
29+
if (false === openssl_sign($data, $signature, $key->asPem(), $this->getHashAlgorithm())) {
30+
throw new InvalidArgumentException('Unable to sign the data');
31+
}
3032

3133
return $signature;
3234
}

src/cose/src/Key/Ec2Key.php

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use FG\ASN1\Universal\ObjectIdentifier;
2222
use FG\ASN1\Universal\OctetString;
2323
use FG\ASN1\Universal\Sequence;
24-
use function Safe\sprintf;
2524

2625
class Ec2Key extends Key
2726
{

src/cose/src/Key/Key.php

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use function array_key_exists;
1717
use Assert\Assertion;
18-
use function Safe\sprintf;
1918

2019
class Key
2120
{

src/cose/src/Key/RsaKey.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
use FG\ASN1\Universal\NullObject;
2222
use FG\ASN1\Universal\ObjectIdentifier;
2323
use FG\ASN1\Universal\Sequence;
24-
use function Safe\sprintf;
25-
use function Safe\unpack;
24+
use InvalidArgumentException;
2625

2726
class RsaKey extends Key
2827
{
@@ -189,7 +188,12 @@ public function asPem(): string
189188

190189
private function fromBase64ToInteger(string $value): string
191190
{
192-
$hex = current(unpack('H*', $value));
191+
$data = unpack('H*', $value);
192+
if (false === $data) {
193+
throw new InvalidArgumentException('Unable to convert to an integer');
194+
}
195+
196+
$hex = current($data);
193197

194198
return BigInteger::fromBase($hex, 16)->toBase(10);
195199
}

src/symfony/composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
}
1717
],
1818
"require": {
19-
"sensio/framework-extra-bundle": "^5.2",
2019
"spomky-labs/cbor-bundle": "^2.0",
2120
"symfony/config": "^4.4|^5.0",
2221
"symfony/dependency-injection": "^4.4|^5.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2020 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Webauthn\Bundle\DependencyInjection\Compiler;
15+
16+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
19+
final class HttpMessageFactoryCompilerPass implements CompilerPassInterface
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function process(ContainerBuilder $container): void
25+
{
26+
if (!$container->hasDefinition('sensio_framework_extra.psr7.http_message_factory')) {
27+
$container->setAlias('sensio_framework_extra.psr7.http_message_factory', 'webauthn.http.factory');
28+
}
29+
}
30+
}

src/symfony/src/DependencyInjection/WebauthnExtension.php

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function load(array $configs, ContainerBuilder $container): void
8888

8989
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
9090
$loader->load('services.php');
91+
$loader->load('http_message_factory.php');
9192
$loader->load('cose.php');
9293
$loader->load('security.php');
9394

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2020 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
15+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
16+
17+
return static function (ContainerConfigurator $container): void {
18+
$container = $container->services()->defaults()
19+
->private()
20+
->autoconfigure()
21+
->autowire()
22+
;
23+
24+
$container->set('webauthn.http.factory')
25+
->class(PsrHttpFactory::class)
26+
;
27+
};
28+
//sensio_framework_extra.psr7.http_message_factory

src/symfony/src/WebauthnBundle.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Webauthn\Bundle\DependencyInjection\Compiler\DynamicRouteCompilerPass;
2727
use Webauthn\Bundle\DependencyInjection\Compiler\EnforcedSafetyNetApiKeyVerificationCompilerPass;
2828
use Webauthn\Bundle\DependencyInjection\Compiler\ExtensionOutputCheckerCompilerPass;
29+
use Webauthn\Bundle\DependencyInjection\Compiler\HttpMessageFactoryCompilerPass;
2930
use Webauthn\Bundle\DependencyInjection\Compiler\LoggerSetterCompilerPass;
3031
use Webauthn\Bundle\DependencyInjection\Compiler\MetadataStatementRepositorySetterCompilerPass;
3132
use Webauthn\Bundle\DependencyInjection\WebauthnExtension;
@@ -56,6 +57,7 @@ public function build(ContainerBuilder $container): void
5657
$container->addCompilerPass(new CounterCheckerSetterCompilerPass());
5758
$container->addCompilerPass(new CertificateChainCheckerSetterCompilerPass());
5859
$container->addCompilerPass(new MetadataStatementRepositorySetterCompilerPass());
60+
$container->addCompilerPass(new HttpMessageFactoryCompilerPass());
5961

6062
$this->registerMappings($container);
6163

tests/symfony/config/config.yml

-7
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,6 @@ webauthn:
267267
http_client: '@nyholm.psr7.psr17_factory'
268268
request_factory: '@nyholm.psr7.psr18_factory'
269269

270-
271-
sensio_framework_extra:
272-
router:
273-
annotations: false
274-
psr_message:
275-
enabled: true
276-
277270
security:
278271
providers:
279272
default:

tests/symfony/functional/AppKernel.php

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Webauthn\Bundle\Tests\Functional;
1515

1616
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
17-
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
1817
use SpomkyLabs\CborBundle\SpomkyLabsCborBundle;
1918
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
2019
use Symfony\Bundle\MonologBundle\MonologBundle;
@@ -44,7 +43,6 @@ public function registerBundles(): array
4443
new DoctrineBundle(),
4544
new SecurityBundle(),
4645
new MonologBundle(),
47-
new SensioFrameworkExtraBundle(),
4846

4947
new WebauthnBundle(),
5048
];

tests/symfony/functional/Profile/TransportBindingProfileCreationTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ public function aValidRequestProcessedWithMinimalOptions(): void
185185
$client = self::createClient([], ['HTTPS' => 'on']);
186186
$client->request(Request::METHOD_POST, '/attestation/options', [], [], ['CONTENT_TYPE' => 'application/json', 'HTTP_HOST' => 'test.com'], json_encode($content));
187187
$response = $client->getResponse();
188-
dump($response->getContent());
189188
$data = json_decode($response->getContent(), true);
190189

191190
static::assertArrayHasKey('status', $data);

0 commit comments

Comments
 (0)