Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AwsCredential | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/http-message. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @link https://github.com/php-fast-forward/http-message |
| 12 | * @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 13 | * @license https://opensource.org/licenses/MIT MIT License |
| 14 | */ |
| 15 | |
| 16 | namespace FastForward\Http\Message\Header\Authorization; |
| 17 | |
| 18 | /** |
| 19 | * Class AwsCredential. |
| 20 | * |
| 21 | * Represents the structured credential for AWS Signature Version 4 |
| 22 | * authentication. This credential is extracted from an `Authorization` |
| 23 | * header beginning with the scheme `AWS4-HMAC-SHA256`. |
| 24 | * |
| 25 | * AWS Signature Version 4 requires an HMAC-based signing process in which the |
| 26 | * client computes a derived signing key using its AWS secret access key, |
| 27 | * the request date, region, service name, and a fixed terminator string |
| 28 | * (`aws4_request`). The client then signs a canonical representation of the |
| 29 | * HTTP request. The server reconstructs this process and validates the |
| 30 | * signature to authenticate the request. |
| 31 | * |
| 32 | * Implementations using this class MUST treat all contained values as |
| 33 | * immutable authentication parameters. These values MUST NOT be modified |
| 34 | * internally, and callers SHOULD validate them strictly according to AWS |
| 35 | * signing rules. The `signature` value MUST be treated as opaque binary |
| 36 | * content encoded in hexadecimal; possession of a valid signature MAY allow |
| 37 | * unauthorized access if mishandled. |
| 38 | * |
| 39 | * Each property corresponds directly to fields parsed from the |
| 40 | * `Authorization` header: |
| 41 | * |
| 42 | * - **algorithm**: The signing algorithm identifier. For SigV4 this MUST be |
| 43 | * `"AWS4-HMAC-SHA256"`. |
| 44 | * - **credentialScope**: The hierarchical credential scope string in the form: |
| 45 | * `AccessKeyId/Date/Region/Service/aws4_request`. |
| 46 | * - **signedHeaders**: A semicolon-delimited list of header names included |
| 47 | * during canonicalization. The server MUST reconstruct these headers in |
| 48 | * exactly the same order for signature verification. |
| 49 | * - **signature**: A 64-character hexadecimal string representing the |
| 50 | * computed request signature. |
| 51 | */ |
| 52 | final class AwsCredential implements AuthorizationCredential |
| 53 | { |
| 54 | /** |
| 55 | * Creates a representation of the SigV4 credential parameters extracted |
| 56 | * from an Authorization header. |
| 57 | * |
| 58 | * All values passed to this constructor MUST come directly from the parsed |
| 59 | * header and MUST NOT be transformed semantically. Any additional |
| 60 | * normalization required for validation (e.g., canonical header |
| 61 | * reconstruction) MUST be performed by the caller or authentication |
| 62 | * subsystem. |
| 63 | * |
| 64 | * @param string $algorithm the SigV4 signing algorithm identifier |
| 65 | * @param string $credentialScope the credential scope string |
| 66 | * (`AccessKeyId/Date/Region/Service/aws4_request`) |
| 67 | * @param string $signedHeaders a semicolon-separated list of signed headers |
| 68 | * @param string $signature a 64-character hex-encoded signature |
| 69 | */ |
| 70 | public function __construct( |
| 71 | public readonly string $algorithm, |
| 72 | #[\SensitiveParameter] |
| 73 | public readonly string $credentialScope, |
| 74 | public readonly string $signedHeaders, |
| 75 | #[\SensitiveParameter] |
| 76 | public readonly string $signature, |
| 77 | ) {} |
| 78 | } |