def _onIncoming( self, sslConn, peerKey, incomingName, peerKeyID, serviceName ) : assert self.sm.current() == self.ONLINE if not isValidUserName(incomingName) : sslAbort( sslConn ) return if not isValidServiceName(serviceName) : sslAbort( sslConn ) return contact = self.profile.getContactByPublicKey( peerKey ) if contact is None : contactName = peerKeyID else : contactName = contact.name if serviceName not in self.services : action = ACCESS_DENY else : action = self.permissions.execute( contactName, serviceName ) def onActionDone( result ) : self.sm.removeCallback( callbackId ) if action == ACCESS_DENY : actionOp = self._rejectIncoming( sslConn, onActionDone ) else: # elif action == ACCESS_ALLOW : actionOp = self._acceptIncoming( sslConn, serviceName, peerKey, contactName, peerKeyID, incomingName, onActionDone ) # else : # assert action == ACCESS_PROMPT # actionOp = self._promptIncoming( sslConn, serviceName, # peerKey, contactName, incomingName, onActionDone ) callbackId = self.sm.insertCallback( actionOp.cancel, src=self.ONLINE, single=True )
def on_createKeyButton_clicked(self): password = unicode(self.ui.password.text()).encode('utf8') if not password: self._showError('Please enter a password.') self.ui.password.setFocus() self.ui.password.selectAll() return password2 = unicode(self.ui.password2.text()).encode('utf8') if password != password2: self._showError('Re-entered password does not match.') self.ui.password2.setFocus() self.ui.password2.selectAll() return userName = unicode(self.ui.userName.text()).encode('utf8') if not userName: self._showError('Please enter a username.') self.ui.userName.setFocus() self.ui.userName.selectAll() return if not isValidUserName(userName): self._showError('Only lowercase alphabets(a-z), ' + 'digits(0-9), and underscore(\'_\') are allowed ' + 'in the username.') self.ui.userName.setFocus() self.ui.userName.selectAll() return self.userName = userName self.password = password self._doCreateKey()
def _onAddContactClicked( self ) : k = RSAKey() try : k.fromPEM_PublicKey( self.pemPublicKey ) except RSAError : self._showError( 'Invalid public key.' ) self.ui.publicKey.setFocus() self.ui.publicKey.selectAll() return if not isValidUserName(self.contactName) : self._showError( 'Only lowercase alphabets(a-z), ' + 'digits(0-9), and underscore(\'_\') are allowed ' + 'in the contact name.' ) self.ui.contactName.setFocus() self.ui.contactName.selectAll() return contact = self.profile.getContactByPublicKey( k ) if contact : self._showError( 'This public key is already present in ' + 'your contact list as \'%s\'.' % contact.name ) self.ui.publicKey.setFocus() self.ui.publicKey.selectAll() return contact = self.profile.getContactByName( self.contactName ) if contact : self._showError( 'This name is already present in your ' + 'contact list.\nPlease choose a different name.' ) self.ui.contactName.setFocus() self.ui.contactName.selectAll() return contact = Contact( k, self.contactName ) self.addContactCallback( contact ) self.accept()
def on_createKeyButton_clicked( self ) : password = unicode(self.ui.password.text()).encode('utf8') if not password : self._showError( 'Please enter a password.' ) self.ui.password.setFocus() self.ui.password.selectAll() return password2 = unicode(self.ui.password2.text()).encode('utf8') if password != password2 : self._showError( 'Re-entered password does not match.' ) self.ui.password2.setFocus() self.ui.password2.selectAll() return userName = unicode(self.ui.userName.text()).encode('utf8') if not userName : self._showError( 'Please enter a username.' ) self.ui.userName.setFocus() self.ui.userName.selectAll() return if not isValidUserName(userName) : self._showError( 'Only lowercase alphabets(a-z), ' + 'digits(0-9), and underscore(\'_\') are allowed ' + 'in the username.' ) self.ui.userName.setFocus() self.ui.userName.selectAll() return self.userName = userName self.password = password self._doCreateKey()
def _onAddContactClicked(self): k = RSAKey() try: k.fromPEM_PublicKey(self.pemPublicKey) except RSAError: self._showError('Invalid public key.') self.ui.publicKey.setFocus() self.ui.publicKey.selectAll() return if not isValidUserName(self.contactName): self._showError('Only lowercase alphabets(a-z), ' + 'digits(0-9), and underscore(\'_\') are allowed ' + 'in the contact name.') self.ui.contactName.setFocus() self.ui.contactName.selectAll() return contact = self.profile.getContactByPublicKey(k) if contact: self._showError('This public key is already present in ' + 'your contact list as \'%s\'.' % contact.name) self.ui.publicKey.setFocus() self.ui.publicKey.selectAll() return contact = self.profile.getContactByName(self.contactName) if contact: self._showError('This name is already present in your ' + 'contact list.\nPlease choose a different name.') self.ui.contactName.setFocus() self.ui.contactName.selectAll() return contact = Contact(k, self.contactName) self.addContactCallback(contact) self.accept()
def __init__( self, rsaKey, name, keyId, storeEntry ) : assert isValidUserName( name ) self.rsaKey = rsaKey self.name = name self.keyId = keyId self.storeEntry = storeEntry self.contactNames = {} self.contactKeys = {}
def __init__(self, rsaKey, name, keyId, storeEntry): assert isValidUserName(name) self.rsaKey = rsaKey self.name = name self.keyId = keyId self.storeEntry = storeEntry self.contactNames = {} self.contactKeys = {}
def onFetchKey( responseCode, data ) : if responseCode != 200 : op.notify( None ) return inp = StringIO.StringIO( data ) name = inp.readline().strip() pemPublicKey = inp.read() if name and not isValidUserName(name) : op.notify( None ) return op.notify( (name,pemPublicKey) )
def onFetchKey(responseCode, data): if responseCode != 200: op.notify(None) return inp = StringIO.StringIO(data) name = inp.readline().strip() pemPublicKey = inp.read() if name and not isValidUserName(name): op.notify(None) return op.notify((name, pemPublicKey))
def addKey(self, cname, key): if cname and not isValidUserName(cname): return self._error("Bad username.") k = RSAKey() try: k.fromPEM_PublicKey(pemPublicKey) except RSAError: return self._error("Bad PEM-encoded key.") contact = Contact(k, cname) self._onAddContact(contact)
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 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 _onLookupResponse(self, responseCode, data): if responseCode != 200: self._addOp.notify(None) return inp = StringIO.StringIO(data) name = inp.readline().strip() pemPublicKey = inp.read() if name and not isValidUserName(name): self._addOp.notify(None) return k = RSAKey() try: k.fromPEM_PublicKey(pemPublicKey) except RSAError: self._addOp.notify(None) contact = Contact(k, self._addOp.cname) self._addOp.notify(contact)
def _onUpdateNameClicked( self ) : newName = unicode(self.ui.name.text()).encode('utf8') assert newName != self.contact.name if not isValidUserName(newName) : self._showError( 'Only lowercase alphabets(a-z), ' + 'digits(0-9), and underscore(\'_\') are allowed ' + 'in the contact name.' ) self.ui.name.setFocus() self.ui.name.selectAll() return existing = self.profile.getContactByName( newName ) if existing : self._showError( 'The new name is already present in ' + 'your contact list.\n' + 'Please choose a different name.' ) self.ui.name.setFocus() self.ui.name.selectAll() return self.updateNameCallback( newName ) self._updateUI()
def _onUpdateNameClicked(self): newName = unicode(self.ui.name.text()).encode('utf8') assert newName != self.contact.name if not isValidUserName(newName): self._showError('Only lowercase alphabets(a-z), ' + 'digits(0-9), and underscore(\'_\') are allowed ' + 'in the contact name.') self.ui.name.setFocus() self.ui.name.selectAll() return existing = self.profile.getContactByName(newName) if existing: self._showError('The new name is already present in ' + 'your contact list.\n' + 'Please choose a different name.') self.ui.name.setFocus() self.ui.name.selectAll() return self.updateNameCallback(newName) self._updateUI()
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 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 _onIncoming(self, sslConn, peerKey, incomingName, serviceName): assert self.sm.current() == self.ONLINE if not isValidUserName(incomingName): sslAbort(sslConn) return if not isValidServiceName(serviceName): sslAbort(sslConn) return contact = self.profile.getContactByPublicKey(peerKey) if contact is None: contactName = '' else: contactName = contact.name if serviceName not in self.services: action = ACCESS_DENY else: action = self.permissions.execute(contactName, serviceName) def onActionDone(result): self.sm.removeCallback(callbackId) if action == ACCESS_DENY: actionOp = self._rejectIncoming(sslConn, onActionDone) elif action == ACCESS_ALLOW: actionOp = self._acceptIncoming(sslConn, serviceName, peerKey, contactName, incomingName, onActionDone) else: assert action == ACCESS_PROMPT actionOp = self._promptIncoming(sslConn, serviceName, peerKey, contactName, incomingName, onActionDone) callbackId = self.sm.insertCallback(actionOp.cancel, src=self.ONLINE, single=True)
def __init__( self, publicKey, name ) : assert isValidUserName( name ) self.publicKey = publicKey self.name = name self.publicKeyData = publicKey.toDER_PublicKey()
def changeContactName( self, oldName, newName ) : assert isValidUserName( newName ) c = self.contactNames.pop( oldName ) c.name = newName self.contactNames[newName] = c
def changeContactName(self, oldName, newName): assert isValidUserName(newName) c = self.contactNames.pop(oldName) c.name = newName self.contactNames[newName] = c
def __init__(self, publicKey, name): assert isValidUserName(name) self.publicKey = publicKey self.name = name self.publicKeyData = publicKey.toDER_PublicKey()