Exemplo n.º 1
0
    def do_scan_msg_1(self, object, identity):
        try:
            decrypted = identity.decrypt(object.payload)
            msg = objtypes.MsgData.from_bytes(decrypted)
        except:
            pass
        else:
            if msg.encoding in [
                    objtypes.Encoding.trivial, objtypes.Encoding.simple
            ]:
                simple = objtypes.SimpleMessage.from_bytes(msg.message)
                channel = wallet.Address(4, config.NETWORK_STREAM,
                                         msg.ripe).to_bytes()
                creator = wallet.Address(
                    4, config.NETWORK_STREAM,
                    crypto.to_ripe(msg.verkey, msg.enckey)).to_bytes()
                reply = simple.subject[0:4] == 'Re: '
                if reply:
                    simple.subject = simple.subject[4:]

                for t in self.list.threads:
                    if t.channel == channel and t.subject == simple.subject:
                        thread = t
                        if not reply:
                            thread.creator = creator
                        break
                else:
                    if not reply:
                        thread = self.list.new_thread(channel, creator,
                                                      simple.subject)
                    else:
                        thread = self.list.new_thread(channel, b'',
                                                      simple.subject)
                if len(thread.longest) < len(simple.body):
                    thread.longest = simple.body
                if not reply:
                    for c in thread.comments:
                        if c.parent_text == '' and c.text == simple.body:
                            comment = c
                            comment.creator = creator
                            break
                    else:
                        comment = thread.new_comment('', creator, simple.body)
                else:
                    bodies = reversed(simple.body.split('\n' + 54 * '-' +
                                                        '\n'))
                    parent_text = ''
                    for i, body in enumerate(bodies):
                        for c in thread.comments:
                            if c.text == body:
                                comment = c
                                comment.parent_text = parent_text
                                break
                        else:
                            comment = thread.new_comment(
                                parent_text, b'', body)
                        parent_text = body
                    comment.creator = creator
Exemplo n.º 2
0
 def new_identity(self, name, type, sigkey, deckey):
     verkey = crypto.priv_to_pub(sigkey)
     enckey = crypto.priv_to_pub(deckey)
     ripe = crypto.to_ripe(verkey, enckey)
     self.names.set(ripe, name)
     address = Address(4, config.NETWORK_STREAM, ripe)
     self._db.execute('insert into identities (address, name, sigkey, deckey) values (?, ?, ?, ?)',
             (address.to_bytes(), type, sigkey, deckey))
     self._db.execute('insert into profiles (address, name, verkey, enckey) values (?, ?, ?, ?)',
             (address.to_bytes(), type, b'\x04'+verkey, b'\x04'+enckey))
     identity = Identity2(self._db, address)
     for func in self.on_add_identity:
         func(identity)
     return identity
Exemplo n.º 3
0
    def do_scan_msg_1(self, object, identity):
        try:
            decrypted = identity.decrypt(object.payload)
            msg = objtypes.MsgData.from_bytes(decrypted)
        except:
            pass
        else:
            if msg.encoding in [objtypes.Encoding.trivial, objtypes.Encoding.simple]:
                simple = objtypes.SimpleMessage.from_bytes(msg.message)
                channel = wallet.Address(4, config.NETWORK_STREAM, msg.ripe).to_bytes()
                creator = wallet.Address(4, config.NETWORK_STREAM, crypto.to_ripe(msg.verkey, msg.enckey)).to_bytes()
                reply = simple.subject[0:4] == 'Re: '
                if reply:
                    simple.subject = simple.subject[4:]

                for t in self.list.threads:
                    if t.channel == channel and t.subject == simple.subject:
                        thread = t
                        if not reply:
                            thread.creator = creator
                        break
                else:
                    if not reply:
                        thread = self.list.new_thread(channel, creator, simple.subject)
                    else:
                        thread = self.list.new_thread(channel, b'', simple.subject)
                if len(thread.longest) < len(simple.body):
                    thread.longest = simple.body
                if not reply:
                    for c in thread.comments:
                        if c.parent_text == '' and c.text == simple.body:
                            comment = c
                            comment.creator = creator
                            break
                    else:
                        comment = thread.new_comment('', creator, simple.body)
                else:
                    bodies = reversed(simple.body.split('\n'+54*'-'+'\n'))
                    parent_text = ''
                    for i, body in enumerate(bodies):
                        for c in thread.comments:
                            if c.text == body:
                                comment = c
                                comment.parent_text = parent_text
                                break
                        else:
                            comment = thread.new_comment(parent_text, b'', body)
                        parent_text = body
                    comment.creator = creator
Exemplo n.º 4
0
 def new_deterministic(self, name, type, text):
     for i in range(0, 2**64, 2):
         s1 = serialize.Serializer()
         s1.str(text)
         s1.vint(i)
         sigkey = crypto.sha512(s1.data)[0:32]
         s2 = serialize.Serializer()
         s2.str(text)
         s2.vint(i + 1)
         deckey = crypto.sha512(s2.data)[0:32]
         verkey = crypto.priv_to_pub(sigkey)
         enckey = crypto.priv_to_pub(deckey)
         ripe = crypto.to_ripe(verkey, enckey)
         if ripe[0:1] == b'\x00':
             return self.new_identity(name, type, sigkey, deckey)
Exemplo n.º 5
0
 def new_deterministic(self, name, type, text):
     for i in range(0, 2**64, 2):
         s1 = serialize.Serializer()
         s1.str(text)
         s1.vint(i)
         sigkey = crypto.sha512(s1.data)[0:32]
         s2 = serialize.Serializer()
         s2.str(text)
         s2.vint(i + 1)
         deckey = crypto.sha512(s2.data)[0:32]
         verkey = crypto.priv_to_pub(sigkey)
         enckey = crypto.priv_to_pub(deckey)
         ripe = crypto.to_ripe(verkey, enckey)
         if ripe[0:1] == b'\x00':
             return self.new_identity(name, type, sigkey, deckey)
Exemplo n.º 6
0
 def new_identity(self, name, type, sigkey, deckey):
     verkey = crypto.priv_to_pub(sigkey)
     enckey = crypto.priv_to_pub(deckey)
     ripe = crypto.to_ripe(verkey, enckey)
     self.names.set(ripe, name)
     address = Address(4, config.NETWORK_STREAM, ripe)
     self._db.execute(
         'insert into identities (address, name, sigkey, deckey) values (?, ?, ?, ?)',
         (address.to_bytes(), type, sigkey, deckey))
     self._db.execute(
         'insert into profiles (address, name, verkey, enckey) values (?, ?, ?, ?)',
         (address.to_bytes(), type, b'\x04' + verkey, b'\x04' + enckey))
     identity = Identity2(self._db, address)
     for func in self.on_add_identity:
         func(identity)
     return identity