Skip to content

Commit

Permalink
added error handling while calling get_encryption_key_data.
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Nissle <[email protected]>
  • Loading branch information
dennisnissle committed Apr 14, 2021
1 parent 9487621 commit acd1764
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
14 changes: 14 additions & 0 deletions includes/class-wc-gzd-secret-box-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public static function encrypt( $message, $encryption_type = '' ) {
$key_data = self::get_encryption_key_data( $encryption_type );
$nonce = random_bytes( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES );

if ( is_wp_error( $key_data ) ) {
return $key_data;
}

return base64_encode( $key_data['salt'] . $nonce . sodium_crypto_secretbox( $message, $nonce, $key_data['key'] ) );
} catch ( \Exception $e ) {
return self::log_error( new WP_Error( 'encrypt-error', sprintf( 'Error while encrypting data: %s', wc_print_r( $e, true ) ) ) );
Expand Down Expand Up @@ -113,6 +117,11 @@ public static function decrypt( $cipher, $encryption_type = '' ) {

$salt = mb_substr( $decoded, 0, SODIUM_CRYPTO_PWHASH_SALTBYTES, '8bit' );
$key_data = self::get_encryption_key_data( $salt, $encryption_type );

if ( is_wp_error( $key_data ) ) {
return $key_data;
}

$key = $key_data['key'];
$nonce = mb_substr( $decoded, SODIUM_CRYPTO_PWHASH_SALTBYTES, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit' );
$ciphertext = mb_substr( $decoded, SODIUM_CRYPTO_PWHASH_SALTBYTES + SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit' );
Expand All @@ -123,6 +132,11 @@ public static function decrypt( $cipher, $encryption_type = '' ) {
*/
if ( $plain === false ) {
$key_data = self::get_encryption_key_data( $salt, $encryption_type, true );

if ( is_wp_error( $key_data ) ) {
return $key_data;
}

$key = $key_data['key'];
$plain = sodium_crypto_secretbox_open( $ciphertext, $nonce, $key );
}
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 5.4
Tested up to: 5.7
WC requires at least: 3.9
WC tested up to: 5.2
Stable tag: 3.4.1
Stable tag: 3.4.2
Requires PHP: 5.6
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -186,6 +186,9 @@ Bug reports may be filed via our [GitHub repository](https://github.com/vendider
6. Edit pdf documents (Pro)

== Changelog ==
= 3.4.2 =
* Secret box helper error improvements

= 3.4.1 =
* Fixed load error while accessing shipping provider settings

Expand Down
4 changes: 2 additions & 2 deletions woocommerce-germanized.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Germanized for WooCommerce
* Plugin URI: https://www.vendidero.de/woocommerce-germanized
* Description: Germanized for WooCommerce extends WooCommerce to become a legally compliant store in the german market.
* Version: 3.4.1
* Version: 3.4.2
* Author: vendidero
* Author URI: https://vendidero.de
* Requires at least: 4.9
Expand Down Expand Up @@ -69,7 +69,7 @@ final class WooCommerce_Germanized {
*
* @var string
*/
public $version = '3.4.1';
public $version = '3.4.2';

/**
* @var WooCommerce_Germanized $instance of the plugin
Expand Down

0 comments on commit acd1764

Please sign in to comment.