[Python-modules-commits] r24717 - in packages/python-keyring/trunk/debian (4 files)

mitya57-guest at users.alioth.debian.org mitya57-guest at users.alioth.debian.org
Mon Jun 10 13:44:53 UTC 2013


    Date: Monday, June 10, 2013 @ 13:44:52
  Author: mitya57-guest
Revision: 24717

Added convert-crypto-keyring script for conversion of pre-0.9 Crypto
keyrings to the new format.

Added:
  packages/python-keyring/trunk/debian/convert-crypto-keyring
Modified:
  packages/python-keyring/trunk/debian/NEWS
  packages/python-keyring/trunk/debian/changelog
  packages/python-keyring/trunk/debian/python-keyring.install

Modified: packages/python-keyring/trunk/debian/NEWS
===================================================================
--- packages/python-keyring/trunk/debian/NEWS	2013-06-10 08:48:47 UTC (rev 24716)
+++ packages/python-keyring/trunk/debian/NEWS	2013-06-10 13:44:52 UTC (rev 24717)
@@ -1,9 +1,10 @@
 python-keyring (1.4-1) unstable; urgency=low
 
   * This version no longer supports conversion of pre-0.9 Crypto-based
-    keyring files. Version in wheezy (0.9.3-1) automatically converts
-    these files when you use it, so if you were using python-keyring in
-    wheezy, you are not affected. Otherwise, if you used Crypto backend,
-    you should convert these files manually (i.e. by using version 0.9).
+    keyring files. Version in wheezy (0.7.1-1+deb7u1) automatically
+    converts these files when you use it, so if you were using
+    python-keyring in wheezy, you are not affected. Otherwise, if you
+    used Crypto backend, you should convert these files manually using
+    /usr/bin/convert-crypto-keyring script from python-keyring package.
 
  -- Dmitry Shachnev <mitya57 at gmail.com>  Mon, 10 Jun 2013 11:49:16 +0400

Modified: packages/python-keyring/trunk/debian/changelog
===================================================================
--- packages/python-keyring/trunk/debian/changelog	2013-06-10 08:48:47 UTC (rev 24716)
+++ packages/python-keyring/trunk/debian/changelog	2013-06-10 13:44:52 UTC (rev 24717)
@@ -7,6 +7,8 @@
 
   [ Dmitry Shachnev ]
   * New upstream release (closes: #697215).
+  * Added convert-crypto-keyring script for conversion of pre-0.9 Crypto
+    keyrings to the new format.
   * Switch debian/watch to use .tar.bz2 archives from BitBucket, rather than
     .zip archives from PyPI; drop unzip build-dependency.
   * Recommend python[3]-secretstorage, as the default backend now uses it.

Added: packages/python-keyring/trunk/debian/convert-crypto-keyring
===================================================================
--- packages/python-keyring/trunk/debian/convert-crypto-keyring	                        (rev 0)
+++ packages/python-keyring/trunk/debian/convert-crypto-keyring	2013-06-10 13:44:52 UTC (rev 24717)
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+
+# This script is based on code in python-keyring < 1.0
+# Original authors: Jason R. Coombs, Kang Zhang, Sebastian Ramacher
+# Adopted to use as a stand-alone script by Dmitry Shachnev
+
+"""
+Convert keyring from the 0.9.0 and earlier format to the current
+format.
+"""
+
+import getpass
+import crypt
+import sys
+
+try:
+    from configparser import RawConfigParser
+except ImportError:
+    from ConfigParser import RawConfigParser
+
+from Crypto.Cipher import AES
+from keyring.backends.file import EncryptedKeyring
+from keyring.util.escape import unescape
+
+KEYRING_SETTING = 'keyring-setting'
+CRYPTED_PASSWORD = 'crypted-password'
+
+if len(sys.argv) > 1:
+    file_path = sys.argv[1]
+else:
+    sys.exit('Usage: %s [file name]' % sys.argv[0])
+
+config = RawConfigParser()
+config.read(file_path)
+config.get(KEYRING_SETTING, CRYPTED_PASSWORD)
+
+keyring = EncryptedKeyring(file_path)
+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")
+
+keyring.keyring_key = keyring_password
+config.remove_option(KEYRING_SETTING, CRYPTED_PASSWORD)
+with open(file_path, 'w') as f:
+    config.write(f)
+keyring.set_password('keyring-setting', 'password reference',
+    'password reference value')
+
+password = keyring_password + (
+    keyring.block_size - len(keyring_password) % keyring.block_size
+    ) * keyring.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 = unescape(service)
+        user = unescape(user)
+        password_p = cipher.decrypt(password_c)
+        keyring.set_password(service, user, password_p)
+
+print("File upgraded successfully")


Property changes on: packages/python-keyring/trunk/debian/convert-crypto-keyring
___________________________________________________________________
Added: svn:executable
   + *

Modified: packages/python-keyring/trunk/debian/python-keyring.install
===================================================================
--- packages/python-keyring/trunk/debian/python-keyring.install	2013-06-10 08:48:47 UTC (rev 24716)
+++ packages/python-keyring/trunk/debian/python-keyring.install	2013-06-10 13:44:52 UTC (rev 24717)
@@ -1 +1,2 @@
 usr/lib/python2*
+debian/convert-crypto-keyring usr/bin/




More information about the Python-modules-commits mailing list