|
9 | 9 | use SoapInterop\Tests\Support\Oracle; |
10 | 10 | use SoapInterop\Tests\Support\Wsse; |
11 | 11 | use Soap\Psr18WsseMiddleware\Algorithm\DataEncryptionMethod; |
| 12 | +use Soap\Psr18WsseMiddleware\Algorithm\KeyEncryptionMethod; |
| 13 | +use Soap\Psr18WsseMiddleware\Algorithm\OaepHash; |
12 | 14 | use Soap\Psr18WsseMiddleware\Algorithm\KeyTransportAlgorithm; |
13 | 15 | use Soap\Psr18WsseMiddleware\WSSecurity\Exception\SecurityFault; |
14 | 16 | use Soap\Psr18WsseMiddleware\WSSecurity\Inbound; |
@@ -109,6 +111,30 @@ public static function phpEncDataProvider(): iterable |
109 | 111 | yield 'AES-256-GCM, OAEP-SHA1' => [DataEncryptionMethod::AES256_GCM, KeyTransportAlgorithm::oaepSha1()]; |
110 | 112 | yield 'AES-256-CBC, OAEP-SHA1' => [DataEncryptionMethod::AES256_CBC, KeyTransportAlgorithm::oaepSha1()]; |
111 | 113 | yield 'AES-256-GCM, OAEP-SHA256' => [DataEncryptionMethod::AES256_GCM, KeyTransportAlgorithm::oaepSha256()]; |
| 114 | + yield 'AES-256-GCM, mgf1p with a SHA-1 label' => [DataEncryptionMethod::AES256_GCM, KeyTransportAlgorithm::legacyMgf1p()]; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * The mirror of the inbound mgf1p row. That URI fixes the mask to MGF1-SHA1 while ds:DigestMethod still |
| 119 | + * sets the label hash, and a SHA-256 label under it is what WSS4J emits. Only a PHP-outbound row catches |
| 120 | + * getting the shape wrong: our own reader accepts either spelling, so a round trip stays green regardless. |
| 121 | + */ |
| 122 | + public function test_php_encrypted_with_legacy_mgf1p_and_sha256_is_decrypted_by_wss4j(): void |
| 123 | + { |
| 124 | + $encrypted = Wsse::encrypt( |
| 125 | + recipientCertFile: Oracle::certPath('java-server.crt'), |
| 126 | + keyTransport: KeyTransportAlgorithm::fromMethod(KeyEncryptionMethod::RSA_OAEP_MGF1P, OaepHash::Sha256), |
| 127 | + ); |
| 128 | + |
| 129 | + self::assertStringContainsString('rsa-oaep-mgf1p', $encrypted); |
| 130 | + self::assertStringContainsString('xmlenc#sha256', $encrypted); |
| 131 | + // The legacy URI takes no xenc11:MGF child at all; emitting one is what a strict peer refuses. |
| 132 | + self::assertStringNotContainsString('MGF', $encrypted); |
| 133 | + |
| 134 | + $response = Oracle::post('/decrypt', $encrypted); |
| 135 | + |
| 136 | + self::assertSame(200, $response['status'], 'oracle should decrypt mgf1p with a SHA-256 label: ' . $response['body']); |
| 137 | + self::assertStringContainsString(self::PLAINTEXT_MARKER, $response['body']); |
112 | 138 | } |
113 | 139 |
|
114 | 140 | #[DataProvider('phpEncDataProvider')] |
|
0 commit comments