From: Sascha Silbe <sascha-pgp@silbe.org>
Subject: [PATCH] recreate corrupted key pair (#1568)
Recreate a corrupted key pair instead of leaving it alone and failing horribly
later.
Signed-off-by: Sascha Silbe <sascha-pgp@silbe.org>
---
src/jarabe/intro/window.py | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/jarabe/intro/window.py b/src/jarabe/intro/window.py
index 35c0cda..a3bfcd6 100644
a
|
b
|
|
15 | 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
16 | 16 | |
17 | 17 | import os |
| 18 | import os.path |
18 | 19 | import logging |
19 | 20 | from gettext import gettext as _ |
20 | 21 | import gconf |
… |
… |
import gobject |
25 | 26 | import hippo |
26 | 27 | |
27 | 28 | from sugar import env |
| 29 | from sugar import profile |
28 | 30 | from sugar.graphics import style |
29 | 31 | from sugar.graphics.icon import Icon |
30 | 32 | from sugar.graphics.entry import CanvasEntry |
… |
… |
def create_profile(name, color=None, pixbuf=None): |
49 | 51 | client.set_string("/desktop/sugar/user/nick", name) |
50 | 52 | client.set_string("/desktop/sugar/user/color", color.to_string()) |
51 | 53 | |
| 54 | if profile.get_pubkey() and profile.get_profile().privkey_hash: |
| 55 | logging.warning('Valid key pair found, skipping generation.') |
| 56 | return |
| 57 | |
52 | 58 | # Generate keypair |
53 | 59 | import commands |
54 | 60 | keypath = os.path.join(env.get_profile_path(), "owner.key") |
55 | | if not os.path.isfile(keypath): |
56 | | cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % keypath |
57 | | (s, o) = commands.getstatusoutput(cmd) |
58 | | if s != 0: |
59 | | logging.error("Could not generate key pair: %d %s", s, o) |
60 | | else: |
61 | | logging.error("Keypair exists, skip generation.") |
| 61 | |
| 62 | if os.path.exists(keypath): |
| 63 | os.rename(keypath, keypath+'.broken') |
| 64 | logging.warning('Existing private key %s moved to %s.broken', |
| 65 | keypath, keypath) |
| 66 | |
| 67 | if os.path.exists(keypath+'.pub'): |
| 68 | os.rename(keypath+'.pub', keypath+'.pub.broken') |
| 69 | logging.warning('Existing public key %s.pub moved to %s.pub.broken', |
| 70 | keypath, keypath) |
| 71 | |
| 72 | cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % keypath |
| 73 | (s, o) = commands.getstatusoutput(cmd) |
| 74 | if s != 0: |
| 75 | logging.error("Could not generate key pair: %d %s", s, o) |
| 76 | |
62 | 77 | |
63 | 78 | class _Page(hippo.CanvasBox): |
64 | 79 | __gproperties__ = { |