Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 2... Línea 2...
2
namespace Aws\Signature;
2
namespace Aws\Signature;
Línea 3... Línea 3...
3
 
3
 
4
use Aws\Credentials\CredentialsInterface;
4
use Aws\Credentials\CredentialsInterface;
5
use AWS\CRT\Auth\Signable;
5
use AWS\CRT\Auth\Signable;
-
 
6
use AWS\CRT\Auth\SignatureType;
6
use AWS\CRT\Auth\SignatureType;
7
use AWS\CRT\Auth\SignedBodyHeaderType;
7
use AWS\CRT\Auth\Signing;
8
use AWS\CRT\Auth\Signing;
8
use AWS\CRT\Auth\SigningAlgorithm;
9
use AWS\CRT\Auth\SigningAlgorithm;
9
use AWS\CRT\Auth\SigningConfigAWS;
10
use AWS\CRT\Auth\SigningConfigAWS;
10
use AWS\CRT\Auth\StaticCredentialsProvider;
11
use AWS\CRT\Auth\StaticCredentialsProvider;
Línea 444... Línea 445...
444
            $req['body'],
445
            $req['body'],
445
            $req['version']
446
            $req['version']
446
        );
447
        );
447
    }
448
    }
Línea 448... Línea 449...
448
 
449
 
449
    private function verifyCRTLoaded()
450
    protected function verifyCRTLoaded()
450
    {
451
    {
451
        if (!extension_loaded('awscrt')) {
452
        if (!extension_loaded('awscrt')) {
452
            throw new CommonRuntimeException(
453
            throw new CommonRuntimeException(
453
                "AWS Common Runtime for PHP is required to use Signature V4A"
454
                "AWS Common Runtime for PHP is required to use Signature V4A"
454
                . ".  Please install it using the instructions found at"
455
                . ".  Please install it using the instructions found at"
455
                . " https://github.com/aws/aws-sdk-php/blob/master/CRT_INSTRUCTIONS.md"
456
                . " https://github.com/aws/aws-sdk-php/blob/master/CRT_INSTRUCTIONS.md"
456
            );
457
            );
457
        }
458
        }
Línea 458... Línea 459...
458
    }
459
    }
459
 
460
 
460
    private function createCRTStaticCredentialsProvider($credentials)
461
    protected function createCRTStaticCredentialsProvider($credentials)
461
    {
462
    {
462
        return new StaticCredentialsProvider([
463
        return new StaticCredentialsProvider([
463
            'access_key_id' => $credentials->getAccessKeyId(),
464
            'access_key_id' => $credentials->getAccessKeyId(),
464
            'secret_access_key' => $credentials->getSecretKey(),
465
            'secret_access_key' => $credentials->getSecretKey(),
465
            'session_token' => $credentials->getSecurityToken(),
466
            'session_token' => $credentials->getSecurityToken(),
Línea 466... Línea 467...
466
        ]);
467
        ]);
467
    }
468
    }
468
 
469
 
469
    private function removeIllegalV4aHeaders(&$request)
470
    private function removeIllegalV4aHeaders(&$request)
470
    {
471
    {
471
        $illegalV4aHeaders = [
472
        static $illegalV4aHeaders = [
472
            self::AMZ_CONTENT_SHA256_HEADER,
473
            self::AMZ_CONTENT_SHA256_HEADER,
-
 
474
            'aws-sdk-invocation-id',
473
            "aws-sdk-invocation-id",
475
            'aws-sdk-retry',
474
            "aws-sdk-retry",
476
            'x-amz-region-set',
Línea 475... Línea 477...
475
            'x-amz-region-set'
477
            'transfer-encoding'
476
        ];
478
        ];
477
        $storedHeaders = [];
479
        $storedHeaders = [];
478
 
480
 
479
        foreach ($illegalV4aHeaders as $header) {
481
        foreach ($illegalV4aHeaders as $header) {
480
            if ($request->hasHeader($header)){
482
            if ($request->hasHeader($header)) {
Línea 498... Línea 500...
498
 
500
 
499
    /**
501
    /**
500
     * @param CredentialsInterface $credentials
502
     * @param CredentialsInterface $credentials
501
     * @param RequestInterface $request
503
     * @param RequestInterface $request
-
 
504
     * @param $signingService
502
     * @param $signingService
505
     * @param SigningConfigAWS|null $signingConfig
503
     * @return RequestInterface
506
     * @return RequestInterface
-
 
507
     */
504
     */
508
    protected function signWithV4a(
-
 
509
        CredentialsInterface $credentials,
-
 
510
        RequestInterface $request,
-
 
511
        $signingService,
505
    protected function signWithV4a(CredentialsInterface $credentials, RequestInterface $request, $signingService)
512
        ?SigningConfigAWS $signingConfig = null
506
    {
513
    ){
507
        $this->verifyCRTLoaded();
-
 
508
        $credentials_provider = $this->createCRTStaticCredentialsProvider($credentials);
514
        $this->verifyCRTLoaded();
509
        $signingConfig = new SigningConfigAWS([
515
        $signingConfig = $signingConfig ?? new SigningConfigAWS([
510
            'algorithm' => SigningAlgorithm::SIGv4_ASYMMETRIC,
516
            'algorithm' => SigningAlgorithm::SIGv4_ASYMMETRIC,
511
            'signature_type' => SignatureType::HTTP_REQUEST_HEADERS,
517
            'signature_type' => SignatureType::HTTP_REQUEST_HEADERS,
512
            'credentials_provider' => $credentials_provider,
518
            'credentials_provider' => $this->createCRTStaticCredentialsProvider($credentials),
-
 
519
            'signed_body_value' => $this->getPayload($request),
-
 
520
            'should_normalize_uri_path' => true,
513
            'signed_body_value' => $this->getPayload($request),
521
            'use_double_uri_encode' => true,
514
            'region' => "*",
522
            'region' => $this->region,
515
            'service' => $signingService,
523
            'service' => $signingService,
516
            'date' => time(),
524
            'date' => time(),
Línea 517... Línea 525...
517
        ]);
525
        ]);