@@ -940,8 +940,9 @@ static ENGINE *php_openssl_make_pkcs11_engine(const bool warn) /* {{{ */
940
940
941
941
engine = ENGINE_by_id ("pkcs11" );
942
942
if (engine == NULL ) {
943
- if (warn )
943
+ if (warn ) {
944
944
php_error_docref (NULL , E_WARNING , "Cannot load PKCS11 engine" );
945
+ }
945
946
php_openssl_store_errors ();
946
947
return NULL ;
947
948
}
@@ -960,8 +961,9 @@ static ENGINE *php_openssl_make_pkcs11_engine(const bool warn) /* {{{ */
960
961
}
961
962
}
962
963
if (!ENGINE_init (engine )) {
963
- if (warn )
964
+ if (warn ) {
964
965
php_error_docref (NULL , E_WARNING , "Cannot init PKCS11 engine" );
966
+ }
965
967
php_openssl_store_errors ();
966
968
return NULL ;
967
969
}
@@ -1439,7 +1441,7 @@ X509 *php_openssl_x509_from_str(zend_string *cert_str) {
1439
1441
cert = PEM_read_bio_X509 (in , NULL , NULL , NULL );
1440
1442
} else if (ZSTR_LEN (cert_str ) > 7 && memcmp (ZSTR_VAL (cert_str ), "pkcs11:" , sizeof ("pkcs11:" ) - 1 ) == 0 ) {
1441
1443
ENGINE * engine = php_openssl_make_pkcs11_engine (true);
1442
- struct {
1444
+ struct {
1443
1445
const char * s_slot_cert_id ;
1444
1446
X509 * cert ;
1445
1447
} parms = {
@@ -1448,8 +1450,9 @@ X509 *php_openssl_x509_from_str(zend_string *cert_str) {
1448
1450
};
1449
1451
int force_login = 0 ;
1450
1452
1451
- if (!engine )
1453
+ if (!engine ) {
1452
1454
return NULL ;
1455
+ }
1453
1456
1454
1457
if (!ENGINE_ctrl_cmd (engine , "LOAD_CERT_CTRL" , 0 , & parms , NULL , force_login )) {
1455
1458
ENGINE_finish (engine );
@@ -3644,9 +3647,10 @@ EVP_PKEY *php_openssl_pkey_from_zval(zval *val, int public_key, char *passphrase
3644
3647
ENGINE_finish (engine );
3645
3648
engine = NULL ;
3646
3649
}
3647
- /* val could be a certificate (file, pkcs11:, etc., let's try to extract the key */
3648
- if (!key )
3650
+ /* val could be a certificate (file, pkcs11:, etc., let's try to extract the key) */
3651
+ if (!key ) {
3649
3652
cert = php_openssl_x509_from_str (Z_STR_P (val ));
3653
+ }
3650
3654
3651
3655
if (cert ) {
3652
3656
free_cert = 1 ;
@@ -3672,27 +3676,27 @@ EVP_PKEY *php_openssl_pkey_from_zval(zval *val, int public_key, char *passphrase
3672
3676
ENGINE_finish (engine );
3673
3677
engine = NULL ;
3674
3678
} else {
3675
- BIO * in ;
3679
+ BIO * in ;
3676
3680
3677
- if (filename ) {
3678
- in = BIO_new_file (filename , PHP_OPENSSL_BIO_MODE_R (PKCS7_BINARY ));
3679
- } else {
3680
- in = BIO_new_mem_buf (Z_STRVAL_P (val ), (int )Z_STRLEN_P (val ));
3681
- }
3681
+ if (filename ) {
3682
+ in = BIO_new_file (filename , PHP_OPENSSL_BIO_MODE_R (PKCS7_BINARY ));
3683
+ } else {
3684
+ in = BIO_new_mem_buf (Z_STRVAL_P (val ), (int )Z_STRLEN_P (val ));
3685
+ }
3682
3686
3683
- if (in == NULL ) {
3684
- TMP_CLEAN ;
3685
- }
3686
- if (passphrase == NULL ) {
3687
- key = PEM_read_bio_PrivateKey (in , NULL , NULL , NULL );
3688
- } else {
3689
- struct php_openssl_pem_password password ;
3690
- password .key = passphrase ;
3691
- password .len = passphrase_len ;
3692
- key = PEM_read_bio_PrivateKey (in , NULL , php_openssl_pem_password_cb , & password );
3687
+ if (in == NULL ) {
3688
+ TMP_CLEAN ;
3689
+ }
3690
+ if (passphrase == NULL ) {
3691
+ key = PEM_read_bio_PrivateKey (in , NULL , NULL , NULL );
3692
+ } else {
3693
+ struct php_openssl_pem_password password ;
3694
+ password .key = passphrase ;
3695
+ password .len = passphrase_len ;
3696
+ key = PEM_read_bio_PrivateKey (in , NULL , php_openssl_pem_password_cb , & password );
3697
+ }
3698
+ BIO_free (in );
3693
3699
}
3694
- BIO_free (in );
3695
- } // TODO indent, just to please/ease the first round of code review
3696
3700
}
3697
3701
}
3698
3702
0 commit comments