def listProfiles(): ps = profileSettings() profiles = [] for entry in ps.listEntries(''): userName = ps.getData(entry + '/Name') keyId = ps.getData(entry + '/KeyID') profiles.append((userName, keyId, entry)) return profiles
def listProfiles(location='CSpaceProfiles') : ps = profileSettings(location) profiles = [] for entry in ps.listEntries('') : userName = ps.getData( entry+'/Name' ) keyId = ps.getData( entry+'/KeyID' ) profiles.append( (userName,keyId,entry) ) return profiles
def saveProfileContacts( profile, location='CSpaceProfiles' ) : out = StringIO.StringIO() for name in profile.getContactNames() : c = profile.getContactByName( name ) hexKey = hexEncode( c.publicKeyData ) print>>out, '%s:%s' % (name,hexKey) ps = profileSettings(location) ps.setData( profile.storeEntry + '/ContactList', out.getvalue() )
def saveProfileContacts(profile): out = StringIO.StringIO() for name in profile.getContactNames(): c = profile.getContactByName(name) hexKey = hexEncode(c.publicKeyData) print >> out, '%s:%s' % (name, hexKey) ps = profileSettings() ps.setData(profile.storeEntry + '/ContactList', out.getvalue())
def createProfile( rsaKey, password, userName, keyId, location='CSpaceProfiles' ) : assert isValidUserName( userName ) ps = profileSettings(location) baseEntry = userName entry = baseEntry suffix = 0 while ps.getData(entry+'/PrivateKey') : suffix += 1 entry = '%s-%d' % (baseEntry,suffix) encKey = rsaKey.toPEM_PrivateKey( password ) ps.setData( entry+'/PrivateKey', encKey ) ps.setData( entry+'/Name', userName ) if keyId is not None : ps.setData( entry+'/KeyID', keyId ) profile = Profile( rsaKey, userName, keyId, entry ) return profile
def createProfile(rsaKey, password, userName, keyId): assert isValidUserName(userName) ps = profileSettings() baseEntry = userName entry = baseEntry suffix = 0 while ps.getData(entry + '/PrivateKey'): suffix += 1 entry = '%s-%d' % (baseEntry, suffix) encKey = rsaKey.toPEM_PrivateKey(password) ps.setData(entry + '/PrivateKey', encKey) ps.setData(entry + '/Name', userName) if keyId is not None: ps.setData(entry + '/KeyID', keyId) profile = Profile(rsaKey, userName, keyId, entry) return profile
def loadProfile( entry, password, location='CSpaceProfiles') : ps = profileSettings(location) userName = ps.getData( entry+'/Name' ) keyId = ps.getData( entry+'/KeyID' ) encKey = ps.getData( entry+'/PrivateKey' ) rsaKey = RSAKey() try : rsaKey.fromPEM_PrivateKey( encKey, password ) except RSAError : return None profile = Profile( rsaKey, userName, keyId, entry ) contactsData = ps.getData( entry+'/ContactList', '' ) for line in contactsData.split('\n') : line = line.strip() if not line : continue name,hexKey = line.split(':') assert isValidUserName(name) pubKey = RSAKey() pubKey.fromDER_PublicKey( hexDecode(hexKey) ) contact = Contact( pubKey, name ) profile.addContact( contact ) return profile
def loadProfile(entry, password): ps = profileSettings() userName = ps.getData(entry + '/Name') keyId = ps.getData(entry + '/KeyID') encKey = ps.getData(entry + '/PrivateKey') rsaKey = RSAKey() try: rsaKey.fromPEM_PrivateKey(encKey, password) except RSAError: return None profile = Profile(rsaKey, userName, keyId, entry) contactsData = ps.getData(entry + '/ContactList', '') for line in contactsData.split('\n'): line = line.strip() if not line: continue name, hexKey = line.split(':') assert isValidUserName(name) pubKey = RSAKey() pubKey.fromDER_PublicKey(hexDecode(hexKey)) contact = Contact(pubKey, name) profile.addContact(contact) return profile
def clearProfileContacts( profile, location='CSpaceProfiles' ): ps = profileSettings(location) ps.setData( profile.storeEntry + '/ContactList', '' )
def set(self, value): return profileSettings().setInt(self.entry, value)
def get(self): return profileSettings().getInt(self.entry, 1)
def _storeUserPermissions( profile, data ) : entry = profile.storeEntry + '/Permissions' return profileSettings().setData( entry, data )
def _loadUserPermissions( profile ) : entry = profile.storeEntry + '/Permissions' return profileSettings().getData( entry, '' )
def set( self, value ) : return profileSettings().setInt( self.entry, value )
def get( self ) : return profileSettings().getInt( self.entry, 1 )