Merge lp:~bac/launchpadlib/bug-745801 into lp:launchpadlib

Proposed by Brad Crittenden
Status: Merged
Approved by: j.c.sackett
Approved revision: 127
Merged at revision: 128
Proposed branch: lp:~bac/launchpadlib/bug-745801
Merge into: lp:launchpadlib
Diff against target: 81 lines (+26/-4)
1 file modified
src/launchpadlib/credentials.py (+26/-4)
To merge this branch: bzr merge lp:~bac/launchpadlib/bug-745801
Reviewer Review Type Date Requested Status
j.c.sackett (community) Needs Information
Review via email: mp+82560@code.launchpad.net

Commit message

Encode the serialized credentials before saving.

Description of the change

Since some users experienced problems saving the configuration containing lplib keys into their keyring, this branch base64 encodes the values before putting into the keyring in an attempt to avoid freaking out the Gnome keyring or KDE wallet.

When decoding credentials a test is made to see if we have an unencoded string to provide backwards compatibility.

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

I think this looks fine.

I'm a little confused about the addition of krdebug; it seems a little irregular to have a file like this living in the root directory, esp as it seems to be meant as a debug tool while working on this branch.

Was this definitely intended to be added?

review: Needs Information
Revision history for this message
Brad Crittenden (bac) wrote :

Jonathan, you're correct about the debug file. I had it there for a user affected by this bug to use to gather some data. It will not be submitted.

Thanks for the review.

lp:~bac/launchpadlib/bug-745801 updated
128. By Brad Crittenden

Removed debugging script

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/launchpadlib/credentials.py'
2--- src/launchpadlib/credentials.py 2011-11-10 15:29:38 +0000
3+++ src/launchpadlib/credentials.py 2011-11-17 22:23:23 +0000
4@@ -36,6 +36,11 @@
5 from urllib import urlencode
6 from urlparse import urljoin
7 import webbrowser
8+import ConfigParser
9+from base64 import (
10+ b64decode,
11+ b64encode,
12+ )
13
14 import simplejson
15
16@@ -69,6 +74,8 @@
17
18 URI_TOKEN_FORMAT = "uri"
19 DICT_TOKEN_FORMAT = "dict"
20+ ITEM_SEPARATOR = '<BR>'
21+ NEWLINE = '\n'
22
23 def serialize(self):
24 """Turn this object into a string.
25@@ -77,7 +84,12 @@
26 """
27 sio = StringIO()
28 self.save(sio)
29- return sio.getvalue()
30+ serialized = sio.getvalue()
31+ # Some users have reported problems with corrupted keyrings, both in
32+ # Gnome and KDE, when newlines are included in the password. Avoid
33+ # this problem by base 64 encoding the serialized value.
34+ serialized = b64encode(serialized)
35+ return serialized
36
37 @classmethod
38 def from_string(cls, value):
39@@ -86,6 +98,8 @@
40 This should probably be moved into OAuthAuthorizer.
41 """
42 credentials = cls()
43+ if 'consumer_key' not in value:
44+ value = b64decode(value)
45 credentials.load(StringIO(value))
46 return credentials
47
48@@ -121,7 +135,7 @@
49 oauth_signature_method='PLAINTEXT',
50 oauth_signature='&')
51 url = web_root + request_token_page
52- headers = {'Referer' : web_root}
53+ headers = {'Referer': web_root}
54 if token_format == self.DICT_TOKEN_FORMAT:
55 headers['Accept'] = 'application/json'
56 response, content = httplib2.Http().request(
57@@ -310,8 +324,9 @@
58 def do_save(self, credentials, unique_key):
59 """Store newly-authorized credentials in the keyring."""
60 self._ensure_keyring_imported()
61+ serialized = credentials.serialize()
62 keyring.set_password(
63- 'launchpadlib', unique_key, credentials.serialize())
64+ 'launchpadlib', unique_key, serialized)
65
66 def do_load(self, unique_key):
67 """Retrieve credentials from the keyring."""
68@@ -320,7 +335,14 @@
69 'launchpadlib', unique_key)
70 if credential_string is not None:
71 credential_string = credential_string.encode('utf8')
72- return Credentials.from_string(credential_string)
73+ try:
74+ credentials = Credentials.from_string(credential_string)
75+ return credentials
76+ except ConfigParser.NoOptionError as noe:
77+ print "OOPS"
78+ print "%r" % credential_string
79+ print noe
80+ return None
81 return None
82
83

Subscribers

People subscribed via source and target branches