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