Skip to content

Commit 06266c9

Browse files
committed
Cover the mgf1p key transport in the PHP -> WSS4J direction
The inbound side already reads a SHA-256 label under the mgf1p URI, the shape WSS4J emits. Nothing pinned that we emit it correctly: our own reader accepts either spelling, so a round trip stays green through a wrong wire format.
1 parent c07827f commit 06266c9

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/Wsse/EncryptionInteropTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use SoapInterop\Tests\Support\Oracle;
1010
use SoapInterop\Tests\Support\Wsse;
1111
use Soap\Psr18WsseMiddleware\Algorithm\DataEncryptionMethod;
12+
use Soap\Psr18WsseMiddleware\Algorithm\KeyEncryptionMethod;
13+
use Soap\Psr18WsseMiddleware\Algorithm\OaepHash;
1214
use Soap\Psr18WsseMiddleware\Algorithm\KeyTransportAlgorithm;
1315
use Soap\Psr18WsseMiddleware\WSSecurity\Exception\SecurityFault;
1416
use Soap\Psr18WsseMiddleware\WSSecurity\Inbound;
@@ -109,6 +111,30 @@ public static function phpEncDataProvider(): iterable
109111
yield 'AES-256-GCM, OAEP-SHA1' => [DataEncryptionMethod::AES256_GCM, KeyTransportAlgorithm::oaepSha1()];
110112
yield 'AES-256-CBC, OAEP-SHA1' => [DataEncryptionMethod::AES256_CBC, KeyTransportAlgorithm::oaepSha1()];
111113
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']);
112138
}
113139

114140
#[DataProvider('phpEncDataProvider')]

0 commit comments

Comments
 (0)