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 | * @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 DigestCredential. |
| 20 | * |
| 21 | * Represents the parsed credential set for HTTP Digest Authentication |
| 22 | * (RFC 7616). Digest Authentication uses a challenge–response mechanism |
| 23 | * that avoids transmitting passwords in plaintext, but several fields |
| 24 | * remain highly sensitive because they directly participate in the |
| 25 | * hash computation or reflect secret client state. |
| 26 | * |
| 27 | * Implementations handling this class MUST treat the `response`, `cnonce`, |
| 28 | * `nonce`, and `nc` parameters as sensitive information. These values |
| 29 | * MUST NOT be logged, exposed, or included in error messages. While the |
| 30 | * original password is not transmitted, the combination of these fields |
| 31 | * MAY allow offline credential recovery if leaked. |
| 32 | * |
| 33 | * The `username`, `realm`, and `uri` fields generally do not contain |
| 34 | * secret information, though they SHOULD still be handled carefully. |
| 35 | */ |
| 36 | final class DigestCredential implements AuthorizationCredential |
| 37 | { |
| 38 | /** |
| 39 | * Creates a Digest Authentication credential. |
| 40 | * |
| 41 | * Sensitive parameters are annotated with `#[\SensitiveParameter]` to |
| 42 | * ensure that debugging output and exception traces do not reveal |
| 43 | * confidential values used in the authentication hash. |
| 44 | * |
| 45 | * @param string $username the username supplied by the client |
| 46 | * @param string $realm the challenge-provided realm value |
| 47 | * @param string $nonce the server-generated nonce used in hashing |
| 48 | * @param string $uri the requested URI |
| 49 | * @param string $response the computed digest response hash |
| 50 | * @param string $qop the quality of protection value |
| 51 | * @param string $nc the nonce count, incremented by the client |
| 52 | * @param string $cnonce the client-generated nonce |
| 53 | * @param null|string $opaque optional server-provided opaque value |
| 54 | * @param null|string $algorithm algorithm identifier, usually "MD5" |
| 55 | */ |
| 56 | public function __construct( |
| 57 | public readonly string $username, |
| 58 | public readonly string $realm, |
| 59 | #[\SensitiveParameter] |
| 60 | public readonly string $nonce, |
| 61 | public readonly string $uri, |
| 62 | #[\SensitiveParameter] |
| 63 | public readonly string $response, |
| 64 | public readonly string $qop, |
| 65 | #[\SensitiveParameter] |
| 66 | public readonly string $nc, |
| 67 | #[\SensitiveParameter] |
| 68 | public readonly string $cnonce, |
| 69 | public readonly ?string $opaque = null, |
| 70 | public readonly ?string $algorithm = null, |
| 71 | ) {} |
| 72 | } |