Skip to content

Commit 58691e0

Browse files
committed
Promote various OpenSSL warnings into Errors
1 parent 9acabd8 commit 58691e0

10 files changed

+169
-142
lines changed

ext/openssl/openssl.c

+95-85
Large diffs are not rendered by default.

ext/openssl/tests/bug60632.phpt

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ $test_pubkey = $details['key'];
1919
$pubkey = openssl_pkey_get_public($test_pubkey);
2020
$encrypted = null;
2121
$ekeys = array();
22-
$result = openssl_seal('test phrase', $encrypted, $ekeys, array($pubkey), 'AES-256-CBC');
23-
echo "Done";
22+
23+
try {
24+
$result = openssl_seal('test phrase', $encrypted, $ekeys, array($pubkey), 'AES-256-CBC');
25+
} catch (\ValueError $e) {
26+
echo $e->getMessage() . \PHP_EOL;
27+
}
2428
?>
25-
--EXPECTF--
26-
Warning: openssl_seal(): Cipher algorithm requires an IV to be supplied as a sixth parameter in %s on line %d
27-
Done
29+
--EXPECT--
30+
openssl_seal(): Argument #6 ($iv) must provide an IV for chosen cipher algorithm

ext/openssl/tests/bug70438.phpt

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ $cipher = 'AES-128-CBC';
1414
$pub_key = "file://" . __DIR__ . "/public.key";
1515
$priv_key = "file://" . __DIR__ . "/private_rsa_1024.key";
1616

17-
openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key), $cipher);
17+
try {
18+
openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key), $cipher);
19+
} catch (\ValueError $e) {
20+
echo $e->getMessage() . \PHP_EOL;
21+
}
22+
1823
openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key), 'sparkles', $iv);
1924
openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key), $cipher, $iv);
2025
openssl_open($sealed, $decrypted, $ekeys[0], $priv_key, $cipher, $iv);
2126
echo $decrypted;
2227
?>
2328
--EXPECTF--
24-
Warning: openssl_seal(): Cipher algorithm requires an IV to be supplied as a sixth parameter in %s on line %d
29+
openssl_seal(): Argument #6 ($iv) must provide an IV for chosen cipher algorithm
2530

26-
Warning: openssl_seal(): Unknown signature algorithm. in %s on line %d
31+
Warning: openssl_seal(): Unknown signature algorithm in %s on line %d
2732
openssl_seal() test

ext/openssl/tests/cve-2013-6420.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var_dump($info['issuer']['emailAddress'], $info["validFrom_time_t"]);
1010
?>
1111
Done
1212
--EXPECTF--
13-
%s openssl_x509_parse(): Illegal length in timestamp in %s%ecve-2013-6420.php on line 3
13+
Warning: openssl_x509_parse(): Illegal length in timestamp in %s on line 3
1414
string(27) "[email protected]"
1515
int(-1)
1616
Done

ext/openssl/tests/openssl_csr_new_basic.phpt

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ openssl_csr_new() tests
88
$a = array();
99

1010
$conf = array('config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf');
11-
var_dump(openssl_csr_new(array(), $a, $conf, array()));
11+
12+
try {
13+
var_dump(openssl_csr_new(array(), $a, $conf, array()));
14+
var_dump($keyFailed);
15+
} catch (\ValueError $e) {
16+
echo $e->getMessage() . \PHP_EOL;
17+
}
1218

1319
// this leaks
1420
$a = array(1,2);
@@ -19,16 +25,11 @@ var_dump(openssl_csr_new($a, $b, $conf));
1925
$x = openssl_pkey_new($conf);
2026
var_dump(openssl_csr_new(["countryName" => "DE"], $x, $conf + ["x509_extensions" => 0xDEADBEEF]));
2127

22-
23-
echo "Done\n";
2428
?>
2529
--EXPECTF--
26-
Warning: openssl_csr_new(): Key array must be of the form array(0 => key, 1 => phrase) in %s on line %d
27-
2830
Warning: openssl_csr_new(): add1_attr_by_txt challengePassword_min -> 4 (failed; check error queue and value of string_mask OpenSSL option if illegal characters are reported) in %s on line %d
29-
bool(false)
31+
Key array must be of the form array(0 => key, 1 => phrase)
3032
object(OpenSSLCertificateSigningRequest)#%d (0) {
3133
}
3234
object(OpenSSLCertificateSigningRequest)#%d (0) {
3335
}
34-
Done

ext/openssl/tests/openssl_csr_sign_basic.phpt

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ try {
5050
echo $exception->getMessage() . "\n";
5151
}
5252

53-
var_dump(openssl_csr_sign($csr, null, array(), 365));
53+
try {
54+
var_dump(openssl_csr_sign($csr, null, array(), 365));
55+
} catch (ValueError $exception) {
56+
echo $exception->getMessage() . "\n";
57+
}
5458
var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg));
5559
?>
5660
--EXPECTF--
@@ -73,10 +77,6 @@ Warning: openssl_csr_sign(): X.509 Certificate Signing Request cannot be retriev
7377
bool(false)
7478
openssl_csr_sign(): Argument #1 ($csr) must be of type OpenSSLCertificateSigningRequest|string, array given
7579
openssl_csr_sign(): Argument #2 ($cacert) must be of type OpenSSLCertificate|string|null, array given
76-
77-
Warning: openssl_csr_sign(): Key array must be of the form array(0 => key, 1 => phrase) in %s on line %d
78-
79-
Warning: openssl_csr_sign(): Cannot get private key from parameter 3 in %s on line %d
80-
bool(false)
80+
Key array must be of the form array(0 => key, 1 => phrase)
8181
object(OpenSSLCertificate)#%d (0) {
8282
}

ext/openssl/tests/openssl_pkcs7_sign_basic.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ bool(true)
4040
bool(true)
4141
bool(true)
4242

43-
Warning: openssl_pkcs7_sign(): Error opening input file %s in %s on line %d
43+
Warning: openssl_pkcs7_sign(): Error opening input file wrong! in %s on line %d
4444
bool(false)
4545

46-
Warning: openssl_pkcs7_sign(): Error opening input file %s in %s on line %d
46+
Warning: openssl_pkcs7_sign(): Error opening input file ! in %s on line %d
4747
bool(false)
4848

49-
Warning: openssl_pkcs7_sign(): Error opening output file %s in %s on line %d
49+
Warning: openssl_pkcs7_sign(): Error opening output file ! in %s on line %d
5050
bool(false)
5151

5252
Warning: openssl_pkcs7_sign(): X.509 Certificate cannot be retrieved in %s on line %d

ext/openssl/tests/openssl_private_decrypt_basic.phpt

+9-8
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ var_dump(openssl_private_decrypt($encrypted, $output2, $wrong));
1616
var_dump($output2);
1717
var_dump(openssl_private_decrypt($wrong, $output3, $privkey));
1818
var_dump($output3);
19-
var_dump(openssl_private_decrypt($encrypted, $output4, array($privkey)));
20-
var_dump($output4);
19+
20+
try {
21+
var_dump(openssl_private_decrypt($encrypted, $output4, array($privkey)));
22+
var_dump($output4);
23+
} catch (\ValueError $e) {
24+
echo $e->getMessage() . \PHP_EOL;
25+
}
26+
2127
var_dump(openssl_private_decrypt($encrypted, $output5, array($privkey, "")));
2228
var_dump($output5);
2329
?>
@@ -30,11 +36,6 @@ bool(false)
3036
NULL
3137
bool(false)
3238
NULL
33-
34-
Warning: openssl_private_decrypt(): Key array must be of the form array(0 => key, 1 => phrase) in %s on line %d
35-
36-
Warning: openssl_private_decrypt(): key parameter is not a valid private key in %s on line %d
37-
bool(false)
38-
NULL
39+
Key array must be of the form array(0 => key, 1 => phrase)
3940
bool(true)
4041
string(32) "Testing openssl_public_decrypt()"

ext/openssl/tests/openssl_public_decrypt_basic.phpt

+16-14
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@ var_dump(openssl_public_decrypt($encrypted, $output2, $wrong));
1616
var_dump($output2);
1717
var_dump(openssl_public_decrypt($wrong, $output3, $pubkey));
1818
var_dump($output3);
19-
var_dump(openssl_public_decrypt($encrypted, $output4, array()));
20-
var_dump($output4);
21-
var_dump(openssl_public_decrypt($encrypted, $output5, array($pubkey)));
19+
20+
try {
21+
var_dump(openssl_public_decrypt($encrypted, $output4, array()));
22+
var_dump($output4);
23+
} catch (\ValueError $e) {
24+
echo $e->getMessage() . \PHP_EOL;
25+
}
26+
27+
try {
28+
var_dump(openssl_public_decrypt($encrypted, $output5, array($pubkey)));
29+
var_dump($output4);
30+
} catch (\ValueError $e) {
31+
echo $e->getMessage() . \PHP_EOL;
32+
}
2233
var_dump($output5);
2334
var_dump(openssl_public_decrypt($encrypted, $output6, array($pubkey, "")));
2435
var_dump($output6);
@@ -32,17 +43,8 @@ bool(false)
3243
NULL
3344
bool(false)
3445
NULL
35-
36-
Warning: openssl_public_decrypt(): Key array must be of the form array(0 => key, 1 => phrase) in %s on line %d
37-
38-
Warning: openssl_public_decrypt(): key parameter is not a valid public key in %s on line %d
39-
bool(false)
40-
NULL
41-
42-
Warning: openssl_public_decrypt(): Key array must be of the form array(0 => key, 1 => phrase) in %s on line %d
43-
44-
Warning: openssl_public_decrypt(): key parameter is not a valid public key in %s on line %d
45-
bool(false)
46+
Key array must be of the form array(0 => key, 1 => phrase)
47+
Key array must be of the form array(0 => key, 1 => phrase)
4648
NULL
4749
bool(true)
4850
string(32) "Testing openssl_public_decrypt()"

ext/openssl/tests/openssl_seal_basic.phpt

+15-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ $c = array(1);
1111
$d = array(1);
1212

1313
var_dump(openssl_seal($a, $b, $c, $d));
14-
var_dump(openssl_seal($a, $a, $a, array()));
14+
15+
try {
16+
var_dump(openssl_seal($a, $a, $a, array()));
17+
} catch (\ValueError $e) {
18+
echo $e->getMessage() . \PHP_EOL;
19+
}
1520

1621
// tests with cert
1722
$data = "openssl_open() test";
@@ -21,26 +26,26 @@ $wrong = "wrong";
2126
var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key))); // no output
2227
var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key))); // no output
2328
var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key, $wrong)));
24-
var_dump(openssl_seal($data, $sealed, $ekeys, array()));
29+
30+
try {
31+
var_dump(openssl_seal($data, $sealed, $ekeys, array()));
32+
} catch (\ValueError $e) {
33+
echo $e->getMessage() . \PHP_EOL;
34+
}
35+
2536
var_dump(openssl_seal($data, $sealed, $ekeys, array($wrong)));
2637

27-
echo "Done\n";
2838
?>
2939
--EXPECTF--
3040
Warning: openssl_seal(): Not a public key (1th member of pubkeys) in %s on line %d
3141
bool(false)
32-
33-
Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d
34-
bool(false)
42+
openssl_seal(): Argument #4 ($pubkeys) cannot be empty
3543
int(19)
3644
int(19)
3745

3846
Warning: openssl_seal(): Not a public key (2th member of pubkeys) in %s on line %d
3947
bool(false)
40-
41-
Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d
42-
bool(false)
48+
openssl_seal(): Argument #4 ($pubkeys) cannot be empty
4349

4450
Warning: openssl_seal(): Not a public key (1th member of pubkeys) in %s on line %d
4551
bool(false)
46-
Done

0 commit comments

Comments
 (0)