From 7603b237998d7225839b4eeb565a5f25bdd5d5fb Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 31 Jan 2020 19:32:16 +0100 Subject: [PATCH 1/3] Fix secure Mail addon --- securemail/securemail.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/securemail/securemail.php b/securemail/securemail.php index 1ec1aa7b..b45a91bc 100644 --- a/securemail/securemail.php +++ b/securemail/securemail.php @@ -116,6 +116,8 @@ function securemail_settings_post(App &$a, array &$b) */ function securemail_emailer_send_prepare(App &$a, IEmail &$email) { + DI::logger()->warning('start securemail', ['email' => $email]); + if (empty($email->getRecipientUid())) { return; } @@ -124,6 +126,7 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) $enable_checked = DI::pConfig()->get($uid, 'securemail', 'enable'); if (!$enable_checked) { + DI::logger()->warning('No check!!', ['email' => $email]); return; } @@ -133,12 +136,17 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) $marker = empty($matches[1]) ? 'MESSAGE' : $matches[1]; $public_key = OpenPGP::unarmor($public_key_ascii, $marker); + DI::logger()->warning('public key', ['public_key' => $public_key]); + $key = OpenPGP_Message::parse($public_key); $data = new OpenPGP_LiteralDataPacket($email->getMessage(true), [ 'format' => 'u', 'filename' => 'encrypted.gpg' ]); + + DI::logger()->warning('data', ['data' => $data]); + try { $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data])); $armored_encrypted = wordwrap( @@ -148,10 +156,10 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) true ); - $email = Friendica\Object\EMail::createFromPrototype($email, [ - 'textVersion' => $armored_encrypted, - 'htmlVersion' => null, - ]); + $email = $email->withMessage($armored_encrypted, null); + + DI::logger()->warning('End securemail', ['email' => $email]); + } catch (Exception $e) { DI::logger()->warning('Encryption failed.', ['email' => $email, 'exception' => $e]); } From 81dc1e5eb1bc4a42fa485cb668b200a63fb1feaa Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 31 Jan 2020 19:40:50 +0100 Subject: [PATCH 2/3] fix logger settings --- securemail/securemail.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/securemail/securemail.php b/securemail/securemail.php index b45a91bc..6833c885 100644 --- a/securemail/securemail.php +++ b/securemail/securemail.php @@ -116,7 +116,7 @@ function securemail_settings_post(App &$a, array &$b) */ function securemail_emailer_send_prepare(App &$a, IEmail &$email) { - DI::logger()->warning('start securemail', ['email' => $email]); + DI::logger()->debug('start securemail', ['email' => $email]); if (empty($email->getRecipientUid())) { return; @@ -126,7 +126,7 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) $enable_checked = DI::pConfig()->get($uid, 'securemail', 'enable'); if (!$enable_checked) { - DI::logger()->warning('No check!!', ['email' => $email]); + DI::logger()->debug('No check', ['email' => $email]); return; } @@ -136,8 +136,6 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) $marker = empty($matches[1]) ? 'MESSAGE' : $matches[1]; $public_key = OpenPGP::unarmor($public_key_ascii, $marker); - DI::logger()->warning('public key', ['public_key' => $public_key]); - $key = OpenPGP_Message::parse($public_key); $data = new OpenPGP_LiteralDataPacket($email->getMessage(true), [ @@ -145,8 +143,6 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) 'filename' => 'encrypted.gpg' ]); - DI::logger()->warning('data', ['data' => $data]); - try { $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data])); $armored_encrypted = wordwrap( @@ -158,7 +154,7 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) $email = $email->withMessage($armored_encrypted, null); - DI::logger()->warning('End securemail', ['email' => $email]); + DI::logger()->debug('End securemail', ['email' => $email]); } catch (Exception $e) { DI::logger()->warning('Encryption failed.', ['email' => $email, 'exception' => $e]); From c185bab92206700ebd8ff7c3dcf8537aca803524 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 31 Jan 2020 19:43:34 +0100 Subject: [PATCH 3/3] Fix logging --- securemail/securemail.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/securemail/securemail.php b/securemail/securemail.php index 6833c885..115ba472 100644 --- a/securemail/securemail.php +++ b/securemail/securemail.php @@ -116,8 +116,6 @@ function securemail_settings_post(App &$a, array &$b) */ function securemail_emailer_send_prepare(App &$a, IEmail &$email) { - DI::logger()->debug('start securemail', ['email' => $email]); - if (empty($email->getRecipientUid())) { return; } @@ -126,7 +124,7 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) $enable_checked = DI::pConfig()->get($uid, 'securemail', 'enable'); if (!$enable_checked) { - DI::logger()->debug('No check', ['email' => $email]); + DI::logger()->debug('No securemail enabled.'); return; } @@ -154,8 +152,6 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email) $email = $email->withMessage($armored_encrypted, null); - DI::logger()->debug('End securemail', ['email' => $email]); - } catch (Exception $e) { DI::logger()->warning('Encryption failed.', ['email' => $email, 'exception' => $e]); }