3131
3232use OC \Encryption \Exceptions \DecryptionFailedException ;
3333use OC \Encryption \Exceptions \EncryptionFailedException ;
34+ use OC \ServerNotAvailableException ;
3435use OCA \Encryption \Exceptions \MultiKeyDecryptException ;
3536use OCA \Encryption \Exceptions \MultiKeyEncryptException ;
3637use 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 ' , true );
104110 }
105111
106112 /**
@@ -302,6 +308,10 @@ protected function getKeySize($cipher) {
302308 * @return string
303309 */
304310 public function getLegacyCipher () {
311+ if (!$ this ->supportLegacy ) {
312+ throw new ServerNotAvailableException ('Legacy cipher is no longer supported! ' );
313+ }
314+
305315 return self ::LEGACY_CIPHER ;
306316 }
307317
@@ -395,7 +405,7 @@ public function decryptPrivateKey($privateKey, $password = '', $uid = '') {
395405 if (isset ($ header ['cipher ' ])) {
396406 $ cipher = $ header ['cipher ' ];
397407 } else {
398- $ cipher = self :: LEGACY_CIPHER ;
408+ $ cipher = $ this -> getLegacyCipher () ;
399409 }
400410
401411 if (isset ($ header ['keyFormat ' ])) {
@@ -574,6 +584,11 @@ private function hasSignature($catFile, $cipher) {
574584 $ meta = substr ($ catFile , -93 );
575585 $ signaturePosition = strpos ($ meta , '00sig00 ' );
576586
587+ // If we no longer support the legacy format then everything needs a signature
588+ if (!$ skipSignatureCheck && !$ this ->supportLegacy && $ signaturePosition === false ) {
589+ throw new GenericEncryptionException ('Missing Signature ' , $ this ->l ->t ('Missing Signature ' ));
590+ }
591+
577592 // enforce signature for the new 'CTR' ciphers
578593 if (!$ skipSignatureCheck && $ signaturePosition === false && stripos ($ cipher , 'ctr ' ) !== false ) {
579594 throw new GenericEncryptionException ('Missing Signature ' , $ this ->l ->t ('Missing Signature ' ));
0 commit comments