xref: /PHP-8.0/ext/openssl/tests/bug71917.phpt (revision 26dfce7f)
1--TEST--
2Bug #71917: openssl_open() returns junk on envelope < 16 bytes
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip openssl not loaded");
6?>
7--FILE--
8<?php
9function test($envkey) {
10    $publicKey = "file://" . __DIR__ . "/public.key";
11    $privateKey = "file://" . __DIR__ . "/private_rsa_1024.key";
12    openssl_public_encrypt($envkey, $envelope, $publicKey);
13    $sealed = openssl_encrypt(
14        'plaintext',
15        'rc4', $envkey,
16        OPENSSL_RAW_DATA | OPENSSL_DONT_ZERO_PAD_KEY
17    );
18    openssl_open($sealed, $output, $envelope, $privateKey, 'rc4');
19    var_dump($output === 'plaintext');
20}
21
22// works - key of 16 bytes
23test('1234567890123456i');
24// fails - key of 15 bytes
25test('123456789012345');
26?>
27--EXPECT--
28bool(true)
29bool(true)
30