3232
3333use OC \Encryption \Exceptions \DecryptionFailedException ;
3434use OC \Encryption \Exceptions \EncryptionFailedException ;
35+ use OC \ServerNotAvailableException ;
3536use OCA \Encryption \Exceptions \MultiKeyDecryptException ;
3637use OCA \Encryption \Exceptions \MultiKeyEncryptException ;
3738use OCP \Encryption \Exceptions \GenericEncryptionException ;
@@ -89,6 +90,9 @@ class Crypt {
8990 'AES-128-CFB ' => 16 ,
9091 ];
9192
93+ /** @var bool */
94+ private $ supportLegacy ;
95+
9296 /**
9397 * @param ILogger $logger
9498 * @param IUserSession $userSession
@@ -101,6 +105,8 @@ public function __construct(ILogger $logger, IUserSession $userSession, IConfig
101105 $ this ->config = $ config ;
102106 $ this ->l = $ l ;
103107 $ this ->supportedKeyFormats = ['hash ' , 'password ' ];
108+
109+ $ this ->supportLegacy = $ this ->config ->getSystemValueBool ('encryption.legacy_format_support ' , false );
104110 }
105111
106112 /**
@@ -299,6 +305,10 @@ protected function getKeySize($cipher) {
299305 * @return string
300306 */
301307 public function getLegacyCipher () {
308+ if (!$ this ->supportLegacy ) {
309+ throw new ServerNotAvailableException ('Legacy cipher is no longer supported! ' );
310+ }
311+
302312 return self ::LEGACY_CIPHER ;
303313 }
304314
@@ -391,7 +401,7 @@ public function decryptPrivateKey($privateKey, $password = '', $uid = '') {
391401 if (isset ($ header ['cipher ' ])) {
392402 $ cipher = $ header ['cipher ' ];
393403 } else {
394- $ cipher = self :: LEGACY_CIPHER ;
404+ $ cipher = $ this -> getLegacyCipher () ;
395405 }
396406
397407 if (isset ($ header ['keyFormat ' ])) {
@@ -570,6 +580,11 @@ private function hasSignature($catFile, $cipher) {
570580 $ meta = substr ($ catFile , -93 );
571581 $ signaturePosition = strpos ($ meta , '00sig00 ' );
572582
583+ // If we no longer support the legacy format then everything needs a signature
584+ if (!$ skipSignatureCheck && !$ this ->supportLegacy && $ signaturePosition === false ) {
585+ throw new GenericEncryptionException ('Missing Signature ' , $ this ->l ->t ('Missing Signature ' ));
586+ }
587+
573588 // enforce signature for the new 'CTR' ciphers
574589 if (!$ skipSignatureCheck && $ signaturePosition === false && stripos ($ cipher , 'ctr ' ) !== false ) {
575590 throw new GenericEncryptionException ('Missing Signature ' , $ this ->l ->t ('Missing Signature ' ));
0 commit comments