Commits

Jason R. Coombs committed b7aea42

Removed CryptedFileKeyring migration support

Comments (0)

Files changed (2)

   the files should already have been migrated to their new proper locations.
   If upgrading from 0.7.x or earlier, the files will have to be migrated
   manually.
+* Removed CryptedFileKeyring migration support. To maintain an existing
+  CryptedFileKeyring, one must first upgrade to 0.9.2 or later and access the
+  keyring before upgrading to 1.0 to retain the existing keyring.
 
 ----
 0.10

keyring/backend.py

         """
         Convert older keyrings to the current format.
         """
-        self.__convert_0_9_0(keyring_password)
-        self.__convert_0_9_1(keyring_password)
-
-    def __convert_0_9_1(self, keyring_password):
-        """
-        Convert keyring from the 0.9.1 format to the current format.
-        """
-        with open(self.file_path) as f:
-            encoded_lines = list(f)
-        try:
-            head, data = [line.decode('base64') for line in encoded_lines]
-        except Exception:
-            # not an 0.9.1 formatted file
-            return
-
-        print("Keyring from 0.9.1 detected. Upgrading...")
-
-        salt = head[:self.block_size]
-        IV = head[self.block_size:]
-
-        if keyring_password is None:
-            keyring_password = getpass.getpass(
-                "Please input your password for the keyring: ")
-
-        cipher = self._create_cipher(keyring_password, salt, IV)
-
-        config_file = io.StringIO(cipher.decrypt(data))
-        config = configparser.RawConfigParser()
-        try:
-            config.readfp(config_file)
-        except configparser.Error:
-            sys.stderr.write("Wrong password for the keyring.\n")
-            raise ValueError("Wrong password")
-
-        self.keyring_key = keyring_password
-
-        # wipe the existing file
-        os.remove(self.file_path)
-
-        self.set_password('keyring-setting', 'password reference',
-            'password reference value')
-
-        for service in config.sections():
-            for user in config.options(service):
-                password = config.get(service, user).decode('utf-8')
-                service = keyring.util.escape.unescape(service)
-                user = keyring.util.escape.unescape(user)
-                self.set_password(service, user, password)
-
-        print("File upgraded successfully")
-
-    def __convert_0_9_0(self, keyring_password):
-        """
-        Convert keyring from the 0.9.0 and earlier format to the current
-        format.
-        """
-        KEYRING_SETTING = 'keyring-setting'
-        CRYPTED_PASSWORD = 'crypted-password'
-
-        try:
-            config = configparser.RawConfigParser()
-            config.read(self.file_path)
-            config.get(KEYRING_SETTING, CRYPTED_PASSWORD)
-        except Exception:
-            return
-
-        print("Keyring from 0.9.0 or earlier detected. Upgrading...")
-
-        import crypt
-
-        if keyring_password is None:
-            keyring_password = getpass.getpass(
-                "Please input your password for the keyring: ")
-
-        hashed = crypt.crypt(keyring_password, keyring_password)
-        if config.get(KEYRING_SETTING, CRYPTED_PASSWORD) != hashed:
-            sys.stderr.write("Wrong password for the keyring.\n")
-            raise ValueError("Wrong password")
-
-        self.keyring_key = keyring_password
-        config.remove_option(KEYRING_SETTING, CRYPTED_PASSWORD)
-        with open(self.file_path, 'w') as f:
-            config.write(f)
-        self.set_password('keyring-setting', 'password reference',
-            'password reference value')
-
-        from Crypto.Cipher import AES
-        password = keyring_password + (
-            self.block_size - len(keyring_password) % self.block_size
-            ) * self.pad_char
-
-        for service in config.sections():
-            for user in config.options(service):
-                cipher = AES.new(password, AES.MODE_CFB,
-                    '\0' * AES.block_size)
-                password_c = config.get(service, user).decode('base64')
-                service = keyring.util.escape.unescape(service)
-                user = keyring.util.escape.unescape(user)
-                password_p = cipher.decrypt(password_c)
-                self.set_password(service, user, password_p)
-
-        print("File upgraded successfully")
-
 
 class Win32CryptoKeyring(BasicFileKeyring):
     """Win32 Cryptography Keyring"""