Review main Merged

80394[FEATURE] Introduce class to generate/validate HMAC hashes

Torben Hansen CR +2 V +2 Hard +323 −0 updated 01/23/24, 17:18

Commit message

The `GeneralUtility::hmac()` function is used in several places
to create HMAC hashes for a given string and optional additional
secret.

Extbase has the class `HashService`, which also provides the
ability to create a HMAC for a given string, but without the
possibility to add an additional secret. The missing possibility
to use an additional secret is suboptimal in terms of security,
since generated HMAC hashes will be equal for the same input
in different contexts.

This change introduces a new class, which combines the
functionality of `GeneralUtility::hmac()` and Extbase
`HashService` but with the requirement, that an additional
secret is always mandatory.

The class will be used in follow up patches, where
`GeneralUtility::hmac()` and Extbase `HashService` will be
deprecated.

Review

  • Code review CR +2 Done
    • Oliver Hader +2
    • Oliver Klee +1
    • Andreas Kienast +1
  • Verified V +2 Done
    • Oliver Hader +2
    • Oliver Klee +1
    • Andreas Kienast +1
    • core-ci +1 CI

Issues 1

Files 6

Review log 3142

Show 1117 earlier messages
  1. Torben Hansen uploaded patch set 1 08/04/23, 14:25

  2. core-ci voted on patch set 1 V +1 08/04/23, 14:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45073

  3. Torben Hansen updated the commit message in patch set 2 V +1 09/26/23, 17:29

  4. core-ci voted on patch set 2 V +1 09/26/23, 17:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47198

  5. Torben Hansen rebased onto patch set 3 V +1 11/01/23, 18:16

  6. core-ci voted on patch set 3 V +1 11/01/23, 18:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48449

  7. Torben Hansen rebased onto patch set 4 V +1 01/04/24, 06:09

  8. core-ci voted on patch set 4 V +1 01/04/24, 06:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51094

  9. Torben Hansen uploaded patch set 5 V +1 01/05/24, 14:41

  10. core-ci voted on patch set 5 V +1 01/05/24, 14:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51138

  11. Simon Schaufelberger commented on patch set 5 01/05/24, 19:19

    Hash.php:38

    this variable can be easily inlined
  12. Torben Hansen uploaded patch set 6 V +1 01/06/24, 09:09

  13. Torben Hansen commented on patch set 5 01/06/24, 09:09

    Hash.php:38 Reply

    Done
  14. core-ci voted on patch set 6 V +1 01/06/24, 09:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51149

  15. Oliver Klee commented on patch set 6 V +1 01/06/24, 09:29

    Looks generally very good! I've added some remark get this changes polished before it goes in.

    Hash.php:32

    Let's help the developers via PHPStan here: ```php @param non-empty string $additionalSecret ```

    Hash.php:45

    ```php @param non-empty string $additionalSecret ```

    Hash.php:53

    ```php @param non-empty string $additionalSecret ```

    Hash.php:63

    ```php @param non-empty string $string @param non-empty string $additionalSecret ```

    EmptyAdditionalSecretException.php:25

    Should we make it final?

    InvalidHashStringException.php:25

    Should we make it final?

    HashTest.php:42

    The assertNotEmpty is redundant with the more specific check in the next line. I suggest removing the assertNotEmpty check.

    HashTest.php:54

    In general, please let's use the type-safe `assertSame` wherever possible instead (for all `assertEquals` calls in this file).
  16. Torben Hansen uploaded patch set 7 V +1 01/06/24, 17:25

  17. Torben Hansen commented on patch set 6 01/06/24, 17:26

    Hash.php:32 Reply

    Done

    Hash.php:45 Reply

    Done

    Hash.php:53 Reply

    Done

    Hash.php:63 Reply

    Done

    EmptyAdditionalSecretException.php:25 Reply

    Acknowledged

    InvalidHashStringException.php:25 Reply

    Acknowledged

    HashTest.php:42 Reply

    Done

    HashTest.php:54 Reply

    Done
  1. core-ci voted on patch set 7 V -1 01/06/24, 17:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51169

  2. Torben Hansen commented on patch set 7 01/06/24, 17:36

    @typo3-coding@oliverklee.de Should we add the new phpstan failures due to the `non-empty-string` attribute to the phpstan baseline?
  3. Oliver Klee commented on patch set 7 01/06/24, 18:04

    Reply

    Yes, please. (At least for the warning in production code.) For the warning in the test, we usually add a comment like this: ```php // @phpstan-ignore-next-line We are explicitly testing a contract violation here. ```
  4. Oliver Klee commented on patch set 7 01/06/24, 18:20

    Reply

    For the production code warning, it might also make sense to add another `non-empty-string` annotation (cannot check right now).
  5. Oliver Klee commented on patch set 7 CR -1 01/06/24, 20:32

    Reply

    On it.
  6. Oliver Klee uploaded patch set 8 CR -1 V -1 01/06/24, 20:35

  7. Oliver Klee commented on patch set 7 CR -1 01/06/24, 20:35

    Reply

    Done
  8. Oliver Klee voted on patch set 8 CR +1 V +1 01/06/24, 20:36

  9. core-ci voted on patch set 8 V +1 01/06/24, 20:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51170

  10. Andreas Kienast commented on patch set 8 01/17/24, 08:36

    Hash.php:37

    Would it make sense to use `__METHOD__` instead to make clear by reading it's a reference to this class method?

    Hash.php:59

    It feels strange to have the `$hmac` attribute between `$string` and `$additionalSecret`. I'd rather place it at the start or at the end of the parameter list.
  11. Torben Hansen uploaded patch set 9 CR +1 V +1 01/18/24, 06:44

  12. Torben Hansen commented on patch set 9 01/18/24, 06:44

    Hash.php:37 Reply

    Done

    Hash.php:59 Reply

    Done
  13. core-ci voted on patch set 9 V +1 01/18/24, 06:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51721

  14. Oliver Klee voted on patch set 9 CR +1 V +1 01/18/24, 08:46

  15. Benjamin Franzke commented on patch set 9 CR -1 01/18/24, 09:19

    Sorry to interrupt, but please make `TYPO3\CMS\Core\Crypto\Hash` a service in order to be able to use dependency injection (will be needed for configuration retrieval at some point). That means: no `static` method calls please.
  16. Torben Hansen uploaded patch set 10 CR +1 V +1 01/18/24, 18:54

  17. core-ci voted on patch set 10 V -1 01/18/24, 18:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51781

  18. Torben Hansen uploaded patch set 11 V -1 01/18/24, 19:58

  19. Torben Hansen commented on patch set 10 01/18/24, 19:58

    Reply

    Refactored the class to a service.
  20. core-ci voted on patch set 11 V +1 01/18/24, 20:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51782

  21. Oliver Klee voted on patch set 11 CR +1 V +1 01/18/24, 22:07

  22. Andreas Kienast voted on patch set 11 CR +1 V +1 01/19/24, 07:43

  23. Oliver Hader voted on patch set 11 CR +1 V +1 01/23/24, 17:17

  24. Oliver Hader voted on patch set 11 CR +2 V +2 01/23/24, 17:18

  25. Oliver Hader merged patch set 12 01/23/24, 17:18