Create separate plugins for connection methods
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user