Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| DigestCredential | |
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 | * @copyright Copyright (c) 2025-2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | * @license https://opensource.org/licenses/MIT MIT License |
| 13 | * |
| 14 | * @see https://github.com/php-fast-forward/http-message |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\Http\Message\Header\Authorization; |
| 20 | |
| 21 | use SensitiveParameter; |
| 22 | |
| 23 | /** |
| 24 | * Class DigestCredential. |
| 25 | * |
| 26 | * Represents the parsed credential set for HTTP Digest Authentication |
| 27 | * (RFC 7616). Digest Authentication uses a challenge–response mechanism |
| 28 | * that avoids transmitting passwords in plaintext, but several fields |
| 29 | * remain highly sensitive because they directly participate in the |
| 30 | * hash computation or reflect secret client state. |
| 31 | * |
| 32 | * Implementations handling this class MUST treat the `response`, `cnonce`, |
| 33 | * `nonce`, and `nc` parameters as sensitive information. These values |
| 34 | * MUST NOT be logged, exposed, or included in error messages. While the |
| 35 | * original password is not transmitted, the combination of these fields |
| 36 | * MAY allow offline credential recovery if leaked. |
| 37 | * |
| 38 | * The `username`, `realm`, and `uri` fields generally do not contain |
| 39 | * secret information, though they SHOULD still be handled carefully. |
| 40 | */ |
| 41 | final readonly class DigestCredential implements AuthorizationCredential |
| 42 | { |
| 43 | /** |
| 44 | * Creates a Digest Authentication credential. |
| 45 | * |
| 46 | * Sensitive parameters are annotated with `#[\SensitiveParameter]` to |
| 47 | * ensure that debugging output and exception traces do not reveal |
| 48 | * confidential values used in the authentication hash. |
| 49 | * |
| 50 | * @param string $username the username supplied by the client |
| 51 | * @param string $realm the challenge-provided realm value |
| 52 | * @param string $nonce the server-generated nonce used in hashing |
| 53 | * @param string $uri the requested URI |
| 54 | * @param string $response the computed digest response hash |
| 55 | * @param string $qop the quality of protection value |
| 56 | * @param string $nc the nonce count, incremented by the client |
| 57 | * @param string $cnonce the client-generated nonce |
| 58 | * @param string|null $opaque optional server-provided opaque value |
| 59 | * @param string|null $algorithm algorithm identifier, usually "MD5" |
| 60 | */ |
| 61 | public function __construct( |
| 62 | public string $username, |
| 63 | public string $realm, |
| 64 | #[SensitiveParameter] |
| 65 | public string $nonce, |
| 66 | public string $uri, |
| 67 | #[SensitiveParameter] |
| 68 | public string $response, |
| 69 | public string $qop, |
| 70 | #[SensitiveParameter] |
| 71 | public string $nc, |
| 72 | #[SensitiveParameter] |
| 73 | public string $cnonce, |
| 74 | public ?string $opaque = null, |
| 75 | public ?string $algorithm = null, |
| 76 | ) {} |
| 77 | } |