From aaa53e78435a0b4427cf6f26b067f9fa909783a5 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Fri, 15 Mar 2019 13:05:14 +0530 Subject: [PATCH] Read data from event to decide if signature check should be enabled or not Read data from the event to decide if signature check should be disabled or not. Signed-off-by: Sujith H --- lib/AppInfo/Application.php | 3 ++- lib/Crypto/Crypt.php | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 0598f3cd..cba59964 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -145,7 +145,8 @@ function (IAppContainer $c) { return new Crypt($server->getLogger(), $server->getUserSession(), $server->getConfig(), - $server->getL10N($c->getAppName())); + $server->getL10N($c->getAppName()), + $server->getEventDispatcher()); } }); diff --git a/lib/Crypto/Crypt.php b/lib/Crypto/Crypt.php index 36b12741..bbbdf112 100644 --- a/lib/Crypto/Crypt.php +++ b/lib/Crypto/Crypt.php @@ -35,6 +35,8 @@ use OCP\IL10N; use OCP\ILogger; use OCP\IUserSession; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; /** * Class Crypt provides the encryption implementation of the default ownCloud @@ -77,6 +79,9 @@ class Crypt { /** @var IL10N */ private $l; + /** @var EventDispatcherInterface */ + private $eventDispatcher; + /** @var array */ private $supportedCiphersAndKeySize = [ 'AES-256-CTR' => 32, @@ -85,17 +90,28 @@ class Crypt { 'AES-128-CFB' => 16, ]; + /** + * This variable reads the custom event and updates the value accordingly + * Kindly do not manually edit the value of this variable. + * @var bool + */ + private $disableSignatureCheck = false; + /** * @param ILogger $logger * @param IUserSession $userSession * @param IConfig $config * @param IL10N $l */ - public function __construct(ILogger $logger, IUserSession $userSession, IConfig $config, IL10N $l) { + public function __construct(ILogger $logger, + IUserSession $userSession, + IConfig $config, IL10N $l, + EventDispatcherInterface $eventDispatcher) { $this->logger = $logger; $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : '"no user given"'; $this->config = $config; $this->l = $l; + $this->eventDispatcher = $eventDispatcher; $this->supportedKeyFormats = ['hash', 'password']; } @@ -451,9 +467,17 @@ protected function isValidPrivateKey($plainKey) { * @throws DecryptionFailedException */ public function symmetricDecryptFileContent($keyFileContents, $passPhrase, $cipher = self::DEFAULT_CIPHER, $version = 0, $position = 0) { + $this->eventDispatcher->addListener('files.aftersignaturemismatch', function (GenericEvent $event) { + if ($event->hasArgument('retryWithIgnoreSignature')) { + $this->disableSignatureCheck = $event->getArgument('retryWithIgnoreSignature'); + } else { + $this->disableSignatureCheck = false; + } + $event->stopPropagation(); + }, 10); $catFile = $this->splitMetaData($keyFileContents, $cipher); - if ($catFile['signature'] !== false) { + if (($catFile['signature'] !== false) && ($this->disableSignatureCheck === false)) { $this->checkSignature($catFile['encrypted'], $passPhrase . $version . $position, $catFile['signature']); }