Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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() )
Esempio n. 4
0
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())
Esempio n. 5
0
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
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
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
Esempio n. 9
0
def clearProfileContacts( profile, location='CSpaceProfiles' ):
    ps = profileSettings(location)
    ps.setData( profile.storeEntry + '/ContactList', '' )
Esempio n. 10
0
 def set(self, value):
     return profileSettings().setInt(self.entry, value)
Esempio n. 11
0
 def get(self):
     return profileSettings().getInt(self.entry, 1)
Esempio n. 12
0
def _storeUserPermissions( profile, data ) :
    entry = profile.storeEntry + '/Permissions'
    return profileSettings().setData( entry, data )
Esempio n. 13
0
def _loadUserPermissions( profile ) :
    entry = profile.storeEntry + '/Permissions'
    return profileSettings().getData( entry, '' )
Esempio n. 14
0
 def set( self, value ) :
     return profileSettings().setInt( self.entry, value )
Esempio n. 15
0
 def get( self ) :
     return profileSettings().getInt( self.entry, 1 )