def create_profile(name, color=None): if not color: color = XoColor() client = gconf.client_get_default() client.set_string('/desktop/sugar/user/nick', name) client.set_string('/desktop/sugar/user/color', color.to_string()) client.suggest_sync() if profile.get_pubkey() and profile.get_profile().privkey_hash: logging.info('Valid key pair found, skipping generation.') return # Generate keypair import commands keypath = os.path.join(env.get_profile_path(), 'owner.key') if os.path.exists(keypath): os.rename(keypath, keypath + '.broken') logging.warning('Existing private key %s moved to %s.broken', keypath, keypath) if os.path.exists(keypath + '.pub'): os.rename(keypath + '.pub', keypath + '.pub.broken') logging.warning('Existing public key %s.pub moved to %s.pub.broken', keypath, keypath) cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, ) (s, o) = commands.getstatusoutput(cmd) if s != 0: logging.error('Could not generate key pair: %d %s', s, o)
def _get_id(self): """Determine a unique identifier for the user or machine. On XOs, the serial number will be used. On other systems the SHA-1 hash of the public key will be used. """ try: return file('/ofw/mfg-data/SN').read().rstrip('\0\n') except IOError: logging.debug('Not running on XO') return hashlib.sha1(profile.get_pubkey()).hexdigest()
class Instance: key = profile.get_pubkey() keyHash = util.sha_data(key) keyHashPrintable = util.printable_hash(keyHash) instancePath = None def __init__(self, ca): self.__class__.instancePath = os.path.join(ca.get_activity_root(), "instance") recreateTmp()
def generate_unique_id(): """Generate an id based on the user's nick name and their public key (Based on schema used by IRC activity). """ nick = profile.get_nick_name() pubkey = profile.get_pubkey() m = hashlib.sha1() m.update(pubkey) hexhash = m.hexdigest() nick_letters = "".join([x for x in nick if x.isalpha()]) if not nick_letters: nick_letters = 'XO' return nick_letters + '_' + hexhash[:4]