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