Skip to content

Commit b8ebb1a

Browse files
committed
More reverts
1 parent 61f25be commit b8ebb1a

10 files changed

+126
-172
lines changed

ext/openssl/openssl.c

+43-43
Original file line numberDiff line numberDiff line change
@@ -1553,12 +1553,6 @@ PHP_FUNCTION(openssl_spki_new)
15531553

15541554
PHP_OPENSSL_CHECK_SIZE_T_TO_INT(challenge_len, challenge, 2);
15551555

1556-
mdtype = php_openssl_get_evp_md_from_algo(algo);
1557-
if (!mdtype) {
1558-
zend_argument_value_error(3, "must be a valid signature algorithm");
1559-
RETURN_THROWS();
1560-
}
1561-
15621556
pkey = php_openssl_pkey_from_zval(zpkey, 0, challenge, challenge_len, &free_pkey);
15631557
if (pkey == NULL) {
15641558
if (!EG(exception)) {
@@ -1567,6 +1561,13 @@ PHP_FUNCTION(openssl_spki_new)
15671561
goto cleanup;
15681562
}
15691563

1564+
mdtype = php_openssl_get_evp_md_from_algo(algo);
1565+
1566+
if (!mdtype) {
1567+
php_error_docref(NULL, E_WARNING, "Unknown signature algorithm");
1568+
goto cleanup;
1569+
}
1570+
15701571
if ((spki = NETSCAPE_SPKI_new()) == NULL) {
15711572
php_openssl_store_errors();
15721573
php_error_docref(NULL, E_WARNING, "Unable to create new SPKAC");
@@ -1851,7 +1852,7 @@ zend_string* php_openssl_x509_fingerprint(X509 *peer, const char *method, zend_b
18511852
zend_string *ret;
18521853

18531854
if (!(mdtype = EVP_get_digestbyname(method))) {
1854-
zend_value_error("Unknown signature algorithm");
1855+
php_error_docref(NULL, E_WARNING, "Unknown signature algorithm");
18551856
return NULL;
18561857
} else if (!X509_digest(peer, mdtype, md, &n)) {
18571858
php_openssl_store_errors();
@@ -3820,7 +3821,7 @@ static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req
38203821
break;
38213822
#endif
38223823
default:
3823-
zend_value_error("Unsupported private key type");
3824+
php_error_docref(NULL, E_WARNING, "Unsupported private key type");
38243825
}
38253826
} else {
38263827
php_openssl_store_errors();
@@ -4212,7 +4213,7 @@ PHP_FUNCTION(openssl_pkey_new)
42124213
}
42134214

42144215
if (group == NULL) {
4215-
zend_argument_value_error(1, "must be a valid curve name");
4216+
php_error_docref(NULL, E_WARNING, "Unknown curve name");
42164217
goto clean_exit;
42174218
}
42184219

@@ -4342,10 +4343,9 @@ PHP_FUNCTION(openssl_pkey_export_to_file)
43424343
key = php_openssl_pkey_from_zval(zpkey, 0, passphrase, passphrase_len, &free_pkey);
43434344
if (key == NULL) {
43444345
if (!EG(exception)) {
4345-
// TypeError?
4346-
zend_argument_value_error(1, "cannot retrieve key");
4346+
php_error_docref(NULL, E_WARNING, "Cannot get key from parameter 1");
43474347
}
4348-
RETURN_THROWS();
4348+
RETURN_FALSE;
43494349
}
43504350

43514351
if (php_openssl_open_base_dir_chk(filename)) {
@@ -4429,9 +4429,9 @@ PHP_FUNCTION(openssl_pkey_export)
44294429
key = php_openssl_pkey_from_zval(zpkey, 0, passphrase, passphrase_len, &free_pkey);
44304430
if (key == NULL) {
44314431
if (!EG(exception)) {
4432-
zend_argument_value_error(1, "cannot retrieve key");
4432+
php_error_docref(NULL, E_WARNING, "Cannot get key from parameter 1");
44334433
}
4434-
RETURN_THROWS();
4434+
RETURN_FALSE;
44354435
}
44364436

44374437
PHP_SSL_REQ_INIT(&req);
@@ -4859,8 +4859,8 @@ PHP_FUNCTION(openssl_pbkdf2)
48594859
}
48604860

48614861
if (!digest) {
4862-
zend_argument_value_error(5, "must be a valid signature algorithm");
4863-
RETURN_THROWS();
4862+
php_error_docref(NULL, E_WARNING, "Unknown signature algorithm");
4863+
RETURN_FALSE;
48644864
}
48654865

48664866
out_buffer = zend_string_alloc(key_length, 0);
@@ -6545,9 +6545,9 @@ PHP_FUNCTION(openssl_sign)
65456545
pkey = php_openssl_pkey_from_zval(key, 0, "", 0, &free_pkey);
65466546
if (pkey == NULL) {
65476547
if (!EG(exception)) {
6548-
zend_argument_type_error(3, "cannot be coerced into a private key");
6548+
php_error_docref(NULL, E_WARNING, "Supplied key param cannot be coerced into a private key");
65496549
}
6550-
RETURN_THROWS();
6550+
RETURN_FALSE;
65516551
}
65526552

65536553
if (method == NULL || Z_TYPE_P(method) == IS_LONG) {
@@ -6563,8 +6563,8 @@ PHP_FUNCTION(openssl_sign)
65636563
RETURN_THROWS();
65646564
}
65656565
if (!mdtype) {
6566-
zend_argument_value_error(4, "must be a valid signature algorithm");
6567-
RETURN_THROWS();
6566+
php_error_docref(NULL, E_WARNING, "Unknown signature algorithm");
6567+
RETURN_FALSE;
65686568
}
65696569

65706570
siglen = EVP_PKEY_size(pkey);
@@ -6613,15 +6613,6 @@ PHP_FUNCTION(openssl_verify)
66136613

66146614
PHP_OPENSSL_CHECK_SIZE_T_TO_UINT(signature_len, signature, 2);
66156615

6616-
pkey = php_openssl_pkey_from_zval(key, 1, NULL, 0, &free_pkey);
6617-
if (pkey == NULL) {
6618-
if (!EG(exception)) {
6619-
zend_argument_type_error(3, "cannot be coerced into a public key");
6620-
}
6621-
RETURN_THROWS();
6622-
}
6623-
6624-
66256616
if (method == NULL || Z_TYPE_P(method) == IS_LONG) {
66266617
if (method != NULL) {
66276618
signature_algo = Z_LVAL_P(method);
@@ -6635,8 +6626,16 @@ PHP_FUNCTION(openssl_verify)
66356626
RETURN_THROWS();
66366627
}
66376628
if (!mdtype) {
6638-
zend_argument_value_error(4, "must be a valid signature algorithm");
6639-
RETURN_THROWS();
6629+
php_error_docref(NULL, E_WARNING, "Unknown signature algorithm");
6630+
RETURN_FALSE;
6631+
}
6632+
6633+
pkey = php_openssl_pkey_from_zval(key, 1, NULL, 0, &free_pkey);
6634+
if (pkey == NULL) {
6635+
if (!EG(exception)) {
6636+
php_error_docref(NULL, E_WARNING, "Supplied key param cannot be coerced into a public key");
6637+
}
6638+
RETURN_FALSE;
66406639
}
66416640

66426641
md_ctx = EVP_MD_CTX_create();
@@ -6688,8 +6687,8 @@ PHP_FUNCTION(openssl_seal)
66886687
if (method) {
66896688
cipher = EVP_get_cipherbyname(method);
66906689
if (!cipher) {
6691-
zend_argument_value_error(5, "must be a valid signature algorithm");
6692-
RETURN_THROWS();
6690+
php_error_docref(NULL, E_WARNING, "Unknown signature algorithm");
6691+
RETURN_FALSE;
66936692
}
66946693
} else {
66956694
cipher = EVP_rc4();
@@ -6816,16 +6815,16 @@ PHP_FUNCTION(openssl_open)
68166815
pkey = php_openssl_pkey_from_zval(privkey, 0, "", 0, &free_pkey);
68176816
if (pkey == NULL) {
68186817
if (!EG(exception)) {
6819-
zend_argument_type_error(4, "cannot coerce into a private key");
6818+
php_error_docref(NULL, E_WARNING, "Unable to coerce parameter 4 into a private key");
68206819
}
6821-
RETURN_THROWS();
6820+
RETURN_FALSE;
68226821
}
68236822

68246823
if (method) {
68256824
cipher = EVP_get_cipherbyname(method);
68266825
if (!cipher) {
6827-
zend_argument_value_error(5, "must be a valid signature algorithm");
6828-
RETURN_THROWS();
6826+
php_error_docref(NULL, E_WARNING, "Unknown signature algorithm");
6827+
RETURN_FALSE;
68296828
}
68306829
} else {
68316830
cipher = EVP_rc4();
@@ -6958,8 +6957,8 @@ PHP_FUNCTION(openssl_digest)
69586957
}
69596958
mdtype = EVP_get_digestbyname(method);
69606959
if (!mdtype) {
6961-
zend_argument_value_error(2, "must be a valid signature algorithm");
6962-
RETURN_THROWS();
6960+
php_error_docref(NULL, E_WARNING, "Unknown signature algorithm");
6961+
RETURN_FALSE;
69636962
}
69646963

69656964
siglen = EVP_MD_size(mdtype);
@@ -7218,7 +7217,7 @@ PHP_OPENSSL_API zend_string* php_openssl_encrypt(
72187217

72197218
cipher_type = EVP_get_cipherbyname(method);
72207219
if (!cipher_type) {
7221-
zend_value_error("Unknown cipher algorithm");
7220+
php_error_docref(NULL, E_WARNING, "Unknown cipher algorithm");
72227221
return NULL;
72237222
}
72247223

@@ -7334,7 +7333,7 @@ PHP_OPENSSL_API zend_string* php_openssl_decrypt(
73347333

73357334
cipher_type = EVP_get_cipherbyname(method);
73367335
if (!cipher_type) {
7337-
zend_value_error("Unknown cipher algorithm");
7336+
php_error_docref(NULL, E_WARNING, "Unknown cipher algorithm");
73387337
return NULL;
73397338
}
73407339

@@ -7420,6 +7419,7 @@ PHP_OPENSSL_API zend_long php_openssl_cipher_iv_length(const char *method)
74207419

74217420
cipher_type = EVP_get_cipherbyname(method);
74227421
if (!cipher_type) {
7422+
php_error_docref(NULL, E_WARNING, "Unknown cipher algorithm");
74237423
return -1;
74247424
}
74257425

@@ -7442,9 +7442,9 @@ PHP_FUNCTION(openssl_cipher_iv_length)
74427442
RETURN_THROWS();
74437443
}
74447444

7445+
/* Warning is emitted in php_openssl_cipher_iv_length */
74457446
if ((ret = php_openssl_cipher_iv_length(method)) == -1) {
7446-
zend_argument_value_error(1, "must be a valid cipher algorithm");
7447-
RETURN_THROWS();
7447+
RETURN_FALSE;
74487448
}
74497449

74507450
RETURN_LONG(ret);

ext/openssl/tests/bug38255.phpt

+14-20
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ if (!extension_loaded("openssl")) die("skip");
88
<?php
99
$pub_key_id = false;
1010
$signature = '';
11-
12-
try {
13-
$ok = openssl_verify("foo", $signature, $pub_key_id, OPENSSL_ALGO_MD5);
14-
} catch (\TypeError $e) {
15-
echo $e->getMessage() . \PHP_EOL;
16-
}
11+
$ok = openssl_verify("foo", $signature, $pub_key_id, OPENSSL_ALGO_MD5);
1712

1813
class test {
1914
function __toString() {
@@ -23,19 +18,18 @@ class test {
2318
$t = new test;
2419

2520

26-
try {
27-
var_dump(openssl_verify("foo", $signature, $pub_key_id, OPENSSL_ALGO_MD5));
28-
} catch (\TypeError $e) {
29-
echo $e->getMessage() . \PHP_EOL;
30-
}
31-
try {
32-
var_dump(openssl_verify("foo", $t, $pub_key_id, OPENSSL_ALGO_MD5));
33-
} catch (\TypeError $e) {
34-
echo $e->getMessage() . \PHP_EOL;
35-
}
21+
var_dump(openssl_verify("foo", $signature, $pub_key_id, OPENSSL_ALGO_MD5));
22+
var_dump(openssl_verify("foo", $t, $pub_key_id, OPENSSL_ALGO_MD5));
23+
24+
echo "Done\n";
3625

3726
?>
38-
--EXPECT--
39-
openssl_verify(): Argument #3 ($key) cannot be coerced into a public key
40-
openssl_verify(): Argument #3 ($key) cannot be coerced into a public key
41-
openssl_verify(): Argument #3 ($key) cannot be coerced into a public key
27+
--EXPECTF--
28+
Warning: openssl_verify(): Supplied key param cannot be coerced into a public key in %s on line %d
29+
30+
Warning: openssl_verify(): Supplied key param cannot be coerced into a public key in %s on line %d
31+
bool(false)
32+
33+
Warning: openssl_verify(): Supplied key param cannot be coerced into a public key in %s on line %d
34+
bool(false)
35+
Done

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ $crt = substr(__FILE__, 0, -4).'.crt';
88
$info = openssl_x509_parse("file://$crt");
99
var_dump($info['issuer']['emailAddress'], $info["validFrom_time_t"]);
1010
?>
11+
Done
1112
--EXPECTF--
12-
Warning: openssl_x509_parse(): Illegal length in timestamp in %s on line %d
13+
Warning: openssl_x509_parse(): Illegal length in timestamp in %s on line 3
1314
string(27) "[email protected]"
1415
int(-1)
16+
Done

ext/openssl/tests/openssl_decrypt_error.phpt

+16-29
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,13 @@ $iv = str_repeat("\0", openssl_cipher_iv_length($method));
1212

1313
$encrypted = openssl_encrypt($data, $method, $password);
1414
var_dump($encrypted); /* Not passing $iv should be the same as all-NULL iv, but with a warning */
15-
1615
var_dump(openssl_encrypt($data, $method, $password, 0, $iv));
17-
1816
var_dump(openssl_decrypt($encrypted, $method, $wrong));
19-
20-
try {
21-
var_dump(openssl_decrypt($encrypted, $wrong, $password));
22-
} catch (\ValueError $e) {
23-
echo $e->getMessage() . \PHP_EOL;
24-
}
25-
17+
var_dump(openssl_decrypt($encrypted, $wrong, $password));
2618
var_dump(openssl_decrypt($wrong, $method, $password));
27-
28-
try {
29-
var_dump(openssl_decrypt($wrong, $wrong, $password));
30-
} catch (\ValueError $e) {
31-
echo $e->getMessage() . \PHP_EOL;
32-
}
33-
try {
34-
var_dump(openssl_decrypt($encrypted, $wrong, $wrong));
35-
} catch (\ValueError $e) {
36-
echo $e->getMessage() . \PHP_EOL;
37-
}
38-
try {
39-
var_dump(openssl_decrypt($wrong, $wrong, $wrong));
40-
} catch (\ValueError $e) {
41-
echo $e->getMessage() . \PHP_EOL;
42-
}
19+
var_dump(openssl_decrypt($wrong, $wrong, $password));
20+
var_dump(openssl_decrypt($encrypted, $wrong, $wrong));
21+
var_dump(openssl_decrypt($wrong, $wrong, $wrong));
4322

4423
// invalid using of an authentication tag
4524
var_dump(openssl_encrypt($data, $method, $password, 0, $iv, $wrong));
@@ -49,11 +28,19 @@ Warning: openssl_encrypt(): Using an empty Initialization Vector (iv) is potenti
4928
string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
5029
string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
5130
bool(false)
52-
Unknown cipher algorithm
31+
32+
Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
33+
bool(false)
34+
bool(false)
35+
36+
Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
37+
bool(false)
38+
39+
Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
40+
bool(false)
41+
42+
Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
5343
bool(false)
54-
Unknown cipher algorithm
55-
Unknown cipher algorithm
56-
Unknown cipher algorithm
5744

5845
Warning: openssl_encrypt(): The authenticated tag cannot be provided for cipher that doesn not support AEAD in %s on line %d
5946
string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="

ext/openssl/tests/openssl_encrypt_error.phpt

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ $object = new stdclass;
1313
$arr = array(1);
1414

1515
// wrong parameters tests
16-
try {
17-
var_dump(openssl_encrypt($data, $wrong, $password));
18-
} catch (\ValueError $e) {
19-
echo $e->getMessage() . \PHP_EOL;
20-
}
16+
var_dump(openssl_encrypt($data, $wrong, $password));
2117

2218
// invalid using of an authentication tag
2319
var_dump(openssl_encrypt($data, $method, $password, 0, $iv, $wrong));
@@ -26,7 +22,8 @@ var_dump(openssl_encrypt($data, $method, $password, 0, $iv, $wrong));
2622
var_dump(openssl_encrypt($data, $method, $password, OPENSSL_DONT_ZERO_PAD_KEY, $iv));
2723
?>
2824
--EXPECTF--
29-
Unknown cipher algorithm
25+
Warning: openssl_encrypt(): Unknown cipher algorithm in %s on line %d
26+
bool(false)
3027

3128
Warning: openssl_encrypt(): The authenticated tag cannot be provided for cipher that doesn not support AEAD in %s on line %d
3229
string(44) "iPR4HulskuaP5Z6me5uImk6BqVyJG73+63tkPauVZYk="

0 commit comments

Comments
 (0)