]> git.mxchange.org Git - friendica.git/commitdiff
Reverting RINO crypto code to php-encryption version 1.2
authorHypolite Petovan <mrpetovan@gmail.com>
Thu, 9 Nov 2017 08:20:18 +0000 (03:20 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Thu, 9 Nov 2017 08:20:18 +0000 (03:20 -0500)
mod/dfrn_notify.php
src/Protocol/DFRN.php

index 7397b415a54a5269ea32c918b928fbe6a63662a1..15cda13adf6c43ceb38c281ddf4a2a78909135ae 100644 (file)
@@ -183,9 +183,8 @@ function dfrn_notify_post(App $a) {
                                break;
                        case 2:
                                try {
-                                       $FinalKey = \Defuse\Crypto\Key::loadFromAsciiSafeString(bin2hex($final_key));
-                                       $data = \Defuse\Crypto\Crypto::decrypt(hex2bin($data), $FinalKey);
-                               } catch (\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { // VERY IMPORTANT
+                                       $data = \Crypto::decrypt(hex2bin($data), $final_key);
+                               } catch (\InvalidCiphertextException $ex) { // VERY IMPORTANT
                                        /*
                                         * Either:
                                         *   1. The ciphertext was modified by the attacker,
@@ -195,9 +194,12 @@ function dfrn_notify_post(App $a) {
                                         */
                                        logger('The ciphertext has been tampered with!');
                                        xml_status(0, 'The ciphertext has been tampered with!');
-                               } catch (\Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
+                               } catch (\CryptoTestFailedException $ex) {
                                        logger('Cannot safely perform dencryption');
                                        xml_status(0, 'CryptoTestFailed');
+                               } catch (\CannotPerformOperationException $ex) {
+                                       logger('Cannot safely perform decryption');
+                                       xml_status(0, 'Cannot safely perform decryption');
                                }
                                break;
                        default:
index 7f37f9839b1fda38d1bdee8b3b7b404aec06fa51..1009d075df9398264ac7af00196e5ad8d4c97f31 100644 (file)
@@ -1296,17 +1296,22 @@ class DFRN
                                case 2:
                                        // RINO 2 based on php-encryption
                                        try {
-                                               $KeyObject = \Defuse\Crypto\Key::createNewRandomKey();
-                                       } catch (\Defuse\Crypto\Exception\CryptoException $ex) {
+                                               $key = \Crypto::createNewRandomKey();
+                                       } catch (\CryptoTestFailedException $ex) {
                                                logger('Cannot safely create a key');
                                                return -4;
+                                       } catch (\CannotPerformOperationException $ex) {
+                                               logger('Cannot safely create a key');
+                                               return -5;
                                        }
                                        try {
-                                               $data = \Defuse\Crypto\Crypto::encrypt($postvars['data'], $KeyObject);
-                                               $key = $KeyObject->saveToAsciiSafeString();
-                                       } catch (\Defuse\Crypto\Exception\CryptoException $ex) {
+                                               $data = Crypto::encrypt($postvars['data'], $key);
+                                       } catch (\CryptoTestFailedException $ex) {
                                                logger('Cannot safely perform encryption');
                                                return -6;
+                                       } catch (\CannotPerformOperationException $ex) {
+                                               logger('Cannot safely perform encryption');
+                                               return -7;
                                        }
                                        break;
                                default: