tree checksum vpatch file split hunks

all signers:

antecedents: genesis 9990-keep-ephemeral-ports-open 9989-show-wot-nicks

press order:

genesis
9992-handle-edge-cases-add-feedback
9991-improved-logging
9990-keep-ephemeral-ports-open
9989-show-wot-nicks
9988-hash-dedup

patch:

- 25A41366C0D57C2FA6EAABA61E0BDB07E77B9F48D09FB7FEA1D65296FCC68C8B8836F954B13DE8EE071061A6F49BF8DB89E958EC7B961AC974926F5163694C21
+ 2BEBEB6EE55F0941C567E114EE01352F18F96D02AC4E2F037B9CED7E71C219CC2ED51AC615D28E22244C5E07F136EC7CE1FB565C7217C62DE4708AEE4D8B05D5
blatta/lib/infosec.py
(37 . 7)(37 . 7)
5 def __init__(self, server=None):
6 self.server = server
7
8 def pack(self, peer, message):
9 def get_message_bytes(self, message, peer=None):
10 try:
11 timestamp = message.timestamp
12 except:
(52 . 14)(52 . 9)
14 else:
15 int_ts = timestamp
16
17 key_bytes = base64.b64decode(peer.get_key())
18 signing_key = key_bytes[:32]
19 cipher_key = key_bytes[32:]
20
21 # let's generate the self_chain value from the last message or set it to zero if
22 # there this is the first message
23
24
25 if message.original:
26 if command == DIRECT:
27 self_chain = self.server.state.get_last_message_hash(message.speaker, peer.peer_id)
(75 . 21)(70 . 21)
29 # pack message bytes
30
31 message_bytes = struct.pack(MESSAGE_PACKET_FORMAT, int_ts, self_chain, net_chain, speaker, message.body)
32 return message_bytes
33
34 # log messages
35 def pack(self, peer, message):
36 key_bytes = base64.b64decode(peer.get_key())
37 signing_key = key_bytes[:32]
38 cipher_key = key_bytes[32:]
39
40 if message.original:
41 if command == DIRECT:
42 self.server.state.log(message.speaker, message_bytes, peer.peer_id)
43 elif command == BROADCAST:
44 self.server.state.log(message.speaker, message_bytes)
45 message_bytes = self.get_message_bytes(message, peer)
46
47 # pack packet bytes
48
49 nonce = self._generate_nonce(16)
50 bounces = message.bounces
51 version = 0xfe
52 red_packet_bytes = struct.pack(RED_PACKET_FORMAT, nonce, bounces, version, command, self._pad(message_bytes, MAX_MESSAGE_LENGTH))
53 red_packet_bytes = struct.pack(RED_PACKET_FORMAT, nonce, bounces, version, message.command, self._pad(message_bytes, MAX_MESSAGE_LENGTH))
54
55 # encrypt packet
56
(104 . 9)(99 . 6)
58
59 signed_packet_bytes = struct.pack(BLACK_PACKET_FORMAT, black_packet_bytes, signature_bytes)
60
61 # we want to ignore this ts if it is sent back to us
62
63 self.server.recent.insert(int_ts)
64 return signed_packet_bytes
65
66 def unpack(self, peer, black_packet):
(148 . 16)(140 . 18)
68 if command == IGNORE:
69 return Message({"speaker": speaker, "error_code": IGNORED})
70
71
72 # check timestamp
73
74 if(int_ts not in self._ts_range()):
75 return Message({ "error_code": STALE_PACKET }, self.server)
76
77 if(self.server.recent.has(int_ts)):
78 # check for duplicates
79
80 message_hash = binascii.hexlify(hashlib.sha256(message_bytes).digest())
81 if(self.server.state.is_duplicate_message(message_hash)):
82 return Message({ "error_code": DUPLICATE_PACKET }, self.server)
83 else:
84 self.server.recent.insert(int_ts)
85 self.server.state.add_to_dedup_queue(message_hash)
86
87 # check self_chain
88
- 42717C9441E8B3E62B53CA92879CBB9929EE1625046C622ACDFE7063F52941CF9DC40B7448726691A5946ACF6250E54E79E3156A509CC0507EE374A9C214EF27
+ E763BB836EBA69AEDEBD4D4ADFDD8820E1A173F16E1FD493DDD16BF6D41718155C20EE38073570D2AEB0144EA281B6FBCC5DDDE48D5CA60CB01A0B08103DD1F5
blatta/lib/peer.py
(24 . 9)(24 . 9)
93
94 def send(self, msg):
95 try:
96 signed_packet_bytes = self.infosec.pack(self, msg)
97 if msg.command != IGNORE:
98 self.server.print_debug("packing message: %s" % msg.body)
99 signed_packet_bytes = self.infosec.pack(self, msg)
100 self.socket.sendto(signed_packet_bytes, (self.address, self.port))
101 self.server.print_debug("[%s:%d] <- %s" % (self.address,
102 self.port,
- 9B025BEFC73016D689BA87A93ADD4F57DC2E08B9825E29E8E6CC57D4E0A6983CCF0AFFE9449186D7742F60E3F88EAB24AF883CF12928EA828D7DCFD1DB2DB49C
+
blatta/lib/ringbuffer.py
(1 . 9)(0 . 0)
107 class Ringbuffer(object):
108 def __init__(self, size):
109 self.data = [False]*size
110 self._cursor = 0
111 def insert(self, item):
112 self.data[self._cursor] = item
113 self._cursor = (self._cursor + 1) % len(self.data)
114 def has(self, item):
115 return item in self.data
- F36BF2D21B07D0A2E017B7C0A1F7C8784DED0A4539F2E6CB9DAC2B834F2909686B0AB3CFA28A64B35DB83C16018B049F99DA69B4EEB61EF238C5FE90555927E3
+ 16E7971B6EAB7483A4060D5CAE5111DEC2F61618A2022620343EF7AA3FCEDEE87CC6499C9F9978215C315FDE958E70FA7810F50967E97DD299CD98842118C12D
blatta/lib/server.py
(1 . 4)(1 . 4)
120 VERSION = "9989"
121 VERSION = "9988"
122
123 import os
124 import select
(9 . 6)(9 . 7)
126 import time
127 import string
128 import binascii
129 import hashlib
130 import datetime
131 from datetime import datetime
132 from lib.client import Client
(24 . 7)(25 . 6)
134 from lib.infosec import Infosec
135 from lib.peer import Peer
136 from lib.message import Message
137 from lib.ringbuffer import Ringbuffer
138 from funcs import *
139 from commands import BROADCAST
140 from commands import DIRECT
(63 . 7)(63 . 6)
142 self.channels = {} # irc_lower(Channel name) --> Channel instance.
143 self.clients = {} # Socket --> Client instance..peers = ""
144 self.nicknames = {} # irc_lower(Nickname) --> Client instance.
145 self.recent = Ringbuffer(100)
146 if self.logdir:
147 create_directory(self.logdir)
148 if self.statedir:
(207 . 11)(206 . 22)
150 message.original = True
151 if message.command == DIRECT:
152 peer = self.state.get_peer_by_handle(message.handle)
153 message_bytes = self.infosec.get_message_bytes(message, peer)
154 message_hash = binascii.hexlify(hashlib.sha256(message_bytes).digest())
155 self.state.add_to_dedup_queue(message_hash)
156
157 self.state.log(message.speaker, message_bytes, peer.peer_id)
158 if peer and (peer.get_key() != None):
159 peer.send(message)
160 else:
161 self.print_debug("Discarding message to unknown handle or handle with no key: %s" % message.handle)
162 else:
163 message.timestamp = int(time.time())
164 message_bytes = self.infosec.get_message_bytes(message)
165 if message.command != IGNORE:
166 self.state.log(message.speaker, message_bytes)
167 message_hash = binascii.hexlify(hashlib.sha256(message_bytes).digest())
168 self.state.add_to_dedup_queue(message_hash)
169 for peer in self.state.get_peers():
170 if peer.get_key() != None:
171 peer.send(message)
(228 . 14)(238 . 13)
173
174
175 def sendrubbish(self):
176 for peer in self.state.get_peers():
177 for socket in self.clients:
178 self.peer_message(Message({
179 "speaker": self.clients[socket].nickname,
180 "command": IGNORE,
181 "bounces": 0,
182 "body": self.infosec.gen_rubbish_body()
183 }, self))
184 for socket in self.clients:
185 self.peer_message(Message({
186 "speaker": self.clients[socket].nickname,
187 "command": IGNORE,
188 "bounces": 0,
189 "body": self.infosec.gen_rubbish_body()
190 }, self))
191
192 def start(self):
193 # Setup UDP first
- CF7A79184DC4F229361A26A8DB0901BBCC915EC3C46C7D8A41177A5DDA82E50AACA1AB94C324239251EC1FC148B6C14CB9FB967D4EB08223FA6679D15BAC599A
+ ACD5EAFFDBA356D5B2B2E0CE494E3BE8AED35CCF0B96F9605BFD73FD3F758286F1908D043274A5480AC02C2D270550E1B061B32C0856E521A4EABA2F9F6B29F3
blatta/lib/state.py
(35 . 6)(35 . 10)
198 message_bytes blob not null,\
199 created_at datetime default current_timestamp)")
200
201 self.cursor.execute("create table if not exists dedup_queue(\
202 hash text not null,\
203 created_at datetime default current_timestamp)")
204
205 def get_at(self, handle=None):
206 at = []
207 if handle == None:
(60 . 6)(64 . 22)
209 return at
210
211
212 def is_duplicate_message(self, message_hash):
213 self.cursor.execute("delete from dedup_queue where created_at < datetime(current_timestamp, '-1 hour')")
214 self.conn.commit()
215 result = self.cursor.execute("select hash from dedup_queue where hash=?",
216 (message_hash,)).fetchone()
217 if(result != None):
218 return True
219 else:
220 return False
221
222 def add_to_dedup_queue(self, message_hash):
223 self.cursor.execute("insert into dedup_queue(hash)\
224 values(?)",
225 (message_hash,))
226 self.conn.commit()
227
228 def get_last_message_hash(self, handle, peer_id=None):
229 if peer_id:
230 message_bytes = self.cursor.execute("select message_bytes from logs\