def _doGetPubKey( self, words ) : if len(words) > 1 : self._writeError( 'Malformed request' ) return if not self.session.isOnline() : self._writeError( 'Not online' ) return if len(words) == 0 : keyData = self.session.getProfile().rsaKey.toDER_PublicKey() self._writeResult( [hexEncode(keyData)] ) return contact = self.session.getProfile().getContactByName( words[0] ) if contact is None : self._writeError( 'Unknown contact' ) return self._writeResult( [hexEncode(contact.publicKeyData)] )
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 addIncoming( self, sslConn, peerKey ) : while True : connectionId = hexEncode( rand_bytes(8) ) if connectionId not in self.connections : break def onTimeout() : self._onTimeout( connectionId ) timerOp = self.reactor.callLater( 30, onTimeout ) self.connections[connectionId] = (sslConn,peerKey,timerOp) return connectionId
def _doGetIncomingPubKey( self, words ) : if len(words) != 1 : self._writeError( 'Malformed request' ) return connectionId = words[0] peerKey = self.incoming.getPeerKey( connectionId ) if not peerKey : self._writeError( 'Invalid connection' ) return self._writeResult( [hexEncode(peerKey.toDER_PublicKey())] )
def _doGetContactPubKeys( self, words ) : if len(words) != 0 : self._writeError( 'Malformed request' ) return if not self.session.isOnline() : self._writeError( 'Not online' ) return out = [] profile = self.session.getProfile() for name in profile.getContactNames() : c = profile.getContactByName( name ) out.extend( [c.name,hexEncode(c.publicKeyData)] ) self._writeResult( out )
def contactinfo(self, buddy): if self.status != self.ONLINE: return self._error("Not online.") if buddy not in self.profile.contactNames: return self._error("Bad buddy name: %s" % buddy) contact = self.profile.contactNames[buddy] contactKey = hexEncode(contact.publicKeyData) if hasattr(contact, "status"): contactStatus = contact.status else: contactStatus = -1 return [contact.name, contactKey, self.STATII[contactStatus]]