Ticket #1568: sugar-1568.patch

File sugar-1568.patch, 2.4 KB (added by sascha_silbe, 14 years ago)

recreate corrupted key pair

  • src/jarabe/intro/window.py

    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  
    1515# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1616
    1717import os
     18import os.path
    1819import logging
    1920from gettext import gettext as _
    2021import gconf
    import gobject 
    2526import hippo
    2627
    2728from sugar import env
     29from sugar import profile
    2830from sugar.graphics import style
    2931from sugar.graphics.icon import Icon
    3032from sugar.graphics.entry import CanvasEntry
    def create_profile(name, color=None, pixbuf=None): 
    4951    client.set_string("/desktop/sugar/user/nick", name)
    5052    client.set_string("/desktop/sugar/user/color", color.to_string())
    5153
     54    if profile.get_pubkey() and profile.get_profile().privkey_hash:
     55        logging.warning('Valid key pair found, skipping generation.')
     56        return
     57
    5258    # Generate keypair
    5359    import commands
    5460    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
    6277
    6378class _Page(hippo.CanvasBox):
    6479    __gproperties__ = {