From a72175ff68de54fac9f50136b29f9d156400a5a7 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 26 Feb 2007 00:24:48 +0000 Subject: Create separate plugins for connection methods --- (limited to 'sugar/profile.py') diff --git a/sugar/profile.py b/sugar/profile.py index 43f3657..f34e390 100644 --- a/sugar/profile.py +++ b/sugar/profile.py @@ -19,6 +19,7 @@ import logging from ConfigParser import ConfigParser from sugar import env +from sugar import util from sugar.graphics.xocolor import XoColor class _Profile(object): @@ -26,6 +27,7 @@ class _Profile(object): self.name = None self.color = None self.pubkey = None + self.privkey_hash = None self._load() def update(self): @@ -45,6 +47,7 @@ class _Profile(object): del cp self._load_pubkey() + self._hash_private_key() def _load_pubkey(self): self.pubkey = None @@ -68,6 +71,32 @@ class _Profile(object): if not self.pubkey: logging.error("Error parsing public key.") + def _hash_private_key(self): + self.privkey_hash = None + + key_path = os.path.join(env.get_profile_path(), 'owner.key') + try: + f = open(key_path, "r") + lines = f.readlines() + f.close() + except IOError, e: + logging.error("Error reading private key: %s" % e) + return + + key = "" + for l in lines: + l = l.strip() + if l.startswith("-----BEGIN DSA PRIVATE KEY-----"): + continue + if l.startswith("-----END DSA PRIVATE KEY-----"): + continue + key += l + if not len(key): + logging.error("Error parsing public key.") + + # hash it + key_hash = util._sha_data(key) + self.privkey_hash = util.printable_hash(key_hash) def get_nick_name(): return _profile.name @@ -78,6 +107,9 @@ def get_color(): def get_pubkey(): return _profile.pubkey +def get_private_key_hash(): + return _profile.privkey_hash + def update(): _profile.update() -- cgit v0.9.1