Skip to content

Commit 2d9c0c6

Browse files
author
ogorkun
committed
MC-38539: Introduce JWT wrapper
1 parent 7708daa commit 2d9c0c6

File tree

3 files changed

+429
-18
lines changed

3 files changed

+429
-18
lines changed

app/code/Magento/JwtFrameworkAdapter/Model/JweManager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public function build(JweInterface $jwe, EncryptionSettingsInterface $encryption
7878

7979
$sharedProtected = $this->extractHeaderData($jwe->getProtectedHeader());
8080
$sharedProtected['enc'] = $encryptionSettings->getContentEncryptionAlgorithm();
81+
if ($payload->getContentType()) {
82+
$sharedProtected['cty'] = $payload->getContentType();
83+
}
8184
if (!$jwe->getPerRecipientUnprotectedHeaders()) {
8285
$sharedProtected['alg'] = $encryptionSettings->getAlgorithmName();
8386
}

dev/tests/integration/testsuite/Magento/Framework/Jwt/JwtManagerTest.php

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,136 @@ public function getTokenVariants(): array
546546
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
547547
)
548548
]
549+
],
550+
'jwe-ECDH-ES-with-EC' => [
551+
$flatJwe,
552+
new JweEncryptionJwks(
553+
$jwkFactory->createEncryptEcdhEsWithEc($ecKeys[256][1]),
554+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
555+
),
556+
[
557+
new JweEncryptionJwks(
558+
$jwkFactory->createDecryptEcdhEsWithEc($ecKeys[256][0], 'pass'),
559+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
560+
)
561+
]
562+
],
563+
'jwe-ECDH-ES-A128-with-EC' => [
564+
$flatJwe,
565+
new JweEncryptionJwks(
566+
$jwkFactory->createEncryptEcdhEsA128kwWithEc($ecKeys[256][1]),
567+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
568+
),
569+
[
570+
new JweEncryptionJwks(
571+
$jwkFactory->createDecryptEcdhEsA128kwWithEc($ecKeys[256][0], 'pass'),
572+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
573+
)
574+
]
575+
],
576+
'jwe-ECDH-ES-A192-with-EC' => [
577+
$flatJwe,
578+
new JweEncryptionJwks(
579+
$jwkFactory->createEncryptEcdhEsA192kwWithEc($ecKeys[256][1]),
580+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
581+
),
582+
[
583+
new JweEncryptionJwks(
584+
$jwkFactory->createDecryptEcdhEsA192kwWithEc($ecKeys[256][0], 'pass'),
585+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
586+
)
587+
]
588+
],
589+
'jwe-ECDH-ES-A256-with-EC' => [
590+
$flatJwe,
591+
new JweEncryptionJwks(
592+
$jwkFactory->createEncryptEcdhEsA256kwWithEc($ecKeys[256][1]),
593+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
594+
),
595+
[
596+
new JweEncryptionJwks(
597+
$jwkFactory->createDecryptEcdhEsA256kwWithEc($ecKeys[256][0], 'pass'),
598+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128_HS256
599+
)
600+
]
601+
],
602+
'jwe-A128GCMKW' => [
603+
$flatJwe,
604+
new JweEncryptionJwks(
605+
$jwkFactory->createA128Gcmkw($sharedSecret),
606+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
607+
),
608+
[
609+
new JweEncryptionJwks(
610+
$jwkFactory->createA128Gcmkw($sharedSecret),
611+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
612+
)
613+
]
614+
],
615+
'jwe-A192GCMKW' => [
616+
$flatJwe,
617+
new JweEncryptionJwks(
618+
$jwkFactory->createA192Gcmkw($sharedSecret),
619+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
620+
),
621+
[
622+
new JweEncryptionJwks(
623+
$jwkFactory->createA192Gcmkw($sharedSecret),
624+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
625+
)
626+
]
627+
],
628+
'jwe-A256GCMKW' => [
629+
$flatJwe,
630+
new JweEncryptionJwks(
631+
$jwkFactory->createA256Gcmkw($sharedSecret),
632+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
633+
),
634+
[
635+
new JweEncryptionJwks(
636+
$jwkFactory->createA256Gcmkw($sharedSecret),
637+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
638+
)
639+
]
640+
],
641+
'jwe-PBES2-HS256+A128KW' => [
642+
$flatJwe,
643+
new JweEncryptionJwks(
644+
$jwkFactory->createPbes2Hs256A128kw($sharedSecret),
645+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
646+
),
647+
[
648+
new JweEncryptionJwks(
649+
$jwkFactory->createPbes2Hs256A128kw($sharedSecret),
650+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
651+
)
652+
]
653+
],
654+
'jwe-PBES2-HS384+A192KW' => [
655+
$flatJwe,
656+
new JweEncryptionJwks(
657+
$jwkFactory->createPbes2Hs384A192kw($sharedSecret),
658+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
659+
),
660+
[
661+
new JweEncryptionJwks(
662+
$jwkFactory->createPbes2Hs384A192kw($sharedSecret),
663+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
664+
)
665+
]
666+
],
667+
'jwe-PBES2-HS512+A256KW' => [
668+
$flatJwe,
669+
new JweEncryptionJwks(
670+
$jwkFactory->createPbes2Hs512A256kw($sharedSecret),
671+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
672+
),
673+
[
674+
new JweEncryptionJwks(
675+
$jwkFactory->createPbes2Hs512A256kw($sharedSecret),
676+
JweEncryptionSettingsInterface::CONTENT_ENCRYPTION_ALGO_A128GCM
677+
)
678+
]
549679
]
550680
];
551681
}

0 commit comments

Comments
 (0)