Commit Graph

107 Commits

Author SHA1 Message Date
akwizgran
005e7d5207 Added a random salt to prevent ID clashes between anonymous messages. 2011-09-13 17:56:44 +01:00
akwizgran
de5caca578 Basic database support for private messages. 2011-09-13 14:43:48 +01:00
akwizgran
2858c139fa Make the group field of messages optional.
Private messages have no group.
2011-09-13 14:17:22 +01:00
akwizgran
1d25b5a92e Use null instead of MessageId.NONE and AuthorId.NONE, as for other
optional fields.
2011-09-13 14:04:23 +01:00
akwizgran
70b1487140 Renamed user-defined tags "user-defined type identifiers". 2011-09-12 16:32:25 +01:00
akwizgran
fd2046d984 Renumbered object identifiers to reflect removal of OFFER_ID. 2011-09-12 16:23:55 +01:00
akwizgran
64548375cc Offer IDs no longer need to be calculated or echoed in requests.
The initiator flag in the transport protocol makes this unnecessary by
linking the two sides of a stream-mode connection, making it
impossible for an attacker to replay the responder's side of a
different connection.
2011-09-12 16:21:17 +01:00
akwizgran
7ed747b2a3 Added an initiator flag (bit 31) to the IV.
The flag is used to distinguish between the initiator and responder
directions of a stream-mode connection, allowing them to use the same
connection number without risking IV reuse.

The flag is also raised for batch-mode connections, which only have
one direction.
2011-09-07 17:21:52 +01:00
akwizgran
39be97a4d6 Order sendable messages by timestamp. Also fixed some comments. 2011-09-07 15:55:03 +01:00
akwizgran
bbf957cc94 We can squeeze in a few more subscriptions. 2011-09-07 14:06:35 +01:00
akwizgran
331e7e0547 Increased the maximum packet size to 1 MiB.
This should provide acceptable memory usage and database locking
granularity, while making subscription and transport updates large
enough for the incremental update issue to be kicked into the long
grass.

Removed awareness of the serialisation format from the protocol
component wherever possible, and added tests to ensure that the
constants defined in the protocol package's API are compatible with
the serialisation format.
2011-09-07 13:51:30 +01:00
akwizgran
9dea4d0299 The word "tag" was overloaded, so from now on use "tag" for the
predefined tags in the protocol and serial components, and "IV" for
the encrypted IVs used to identify connections in the transport
component.
2011-08-19 11:15:35 +02:00
akwizgran
2411e2008b Frame the encrypted data independently of inter-packet boundaries and
authenticate each frame before parsing its contents. Each connection
starts with a tag, followed by any number of frames, each starting
with the frame number (32 bits) and payload length (16 bits), and
ending with a MAC (256 bits).

Tags have the following format: 32 bits reserved, 16 bits for the
transport ID, 32 bits for the connection number, 32 bits (set to zero
in the tag) for the frame number, and 16 bits (set to zero in the tag)
for the block number. The tag is encrypted with the tag key in
ECB mode.

Frame numbers for each connection must start from zero and must be
contiguous and strictly increasing. Each frame is encrypted with the
frame key in CTR mode, using the plaintext tag with the appropriate
frame number to initialise the counter.

The maximum frame size is 64 KiB, including header and footer. The
maximum amount of data that can be sent over a connection is 2^32
frames - roughly 2^48 bytes, or 8 terabytes, with the maximum frame
size of 64 KiB. If that isn't sufficient we can add another 16 bits to
the frame counter.
2011-08-19 01:46:51 +02:00
akwizgran
4dd303d9e1 Changed maximum packet and message sizes in preparation for new
transport format.
2011-08-18 15:14:48 +02:00
akwizgran
5e0aadd373 Moved the subscription and transport timestamps out of the contacts
table so it's not necessary to hold a write lock on the (heavily used)
contacts table to update them.
2011-08-14 14:46:12 +02:00
akwizgran
2c13e35dc4 Calculate the timestamp outside the subscription/transport update
writer - this will allow it to be saved so new connections can work
out whether they should send updates.
2011-08-14 13:36:21 +02:00
akwizgran
4497774311 Derive separate keys for each direction. 2011-08-14 12:18:16 +02:00
akwizgran
254da2da27 Removed the restriction that transport updates have to be written in
delimited form.
2011-08-14 11:41:56 +02:00
akwizgran
c2b0f0ab5a Each request packet should contain the unique ID of the offer to which
it responds.
2011-08-13 17:46:19 +02:00
akwizgran
9d25a819d1 Decoupled ProtocolReader (which belongs in the protocol component)
from PacketReader (which belongs in the transport component).
2011-08-13 14:18:16 +02:00
akwizgran
5b6fecfb43 Updated FileReadWriteTest to use the transport component for
encrypting and decrypting packets. Moved the test to the main package
since it's an integration test for several components.
2011-08-12 23:24:24 +02:00
akwizgran
0504a2d6fd Implemented PacketReader, renamed Packet{Reader,Writer}Factory in the
protocol component to Protocol{Reader,Writer}Factory.
2011-08-12 21:55:22 +02:00
akwizgran
68b4760dfa Use a constant for the tag size. 2011-08-12 14:26:56 +02:00
akwizgran
7545a1cc8f Moved Bytes to the main package. Added a SharedSecret class to parse
encrypted secrets retrieved from the database.
2011-08-11 19:14:20 +01:00
akwizgran
df972e294d Support for decrypting shared secrets and deriving authentication and
encryption keys from them (untested).
2011-08-11 17:15:36 +01:00
akwizgran
3edfa5d1ba Call the listeners when contacts are added and removed. 2011-08-11 15:55:30 +01:00
akwizgran
151a360587 Store shared secrets in the database (the crypto component will be
responsible for wrapping/unwrapping them).
2011-08-11 15:41:52 +01:00
akwizgran
07b34cfbab Added a lock for the connectionWindows table and exposed
getConnectionWindow() and setConnectionWindow() through the
DatabaseComponent interface.
2011-08-11 15:19:32 +01:00
akwizgran
0e6638bad6 Retrieve the set of unseen connection numbers from a connection
window.
2011-08-11 13:58:11 +01:00
akwizgran
e0b86f1232 Moved ConnectionWindow into the transport module and implemented
window sliding (untested).
2011-08-11 13:22:23 +01:00
akwizgran
d5d03192e3 Basic connection window persistence. 2011-08-11 12:56:21 +01:00
akwizgran
3e913118f2 PacketWriterFactory. 2011-08-09 18:23:27 +01:00
akwizgran
f3f0c223c4 PacketWriter is implemented by two classes: PacketWriterImpl and
PacketEncrypter. The separation allows authentication and encryption
to be tested separately.
2011-08-09 17:50:54 +01:00
akwizgran
e9d0021f56 Added interfaces for reading and writing packets and recognising which
contact originated an incoming connection, and an implementation of
the PacketWriter interface.
2011-08-09 16:15:25 +01:00
akwizgran
c2045296eb Associate a timestamp with every subscription, indicating the earliest
acceptable timestamp of subscribed messages. For a new subscription,
the timestamp is initialised to the current time, so a new subscriber
to a group will not immediately receive any messages. (Subscribing to
a group is therefore more like joining a mailing list than joining a
Usenet group - you only receive messages written after you joined.)

Once the database fills up and starts expiring messages, the
timestamps of subscriptions are updated so that contacts need not send
messages that would expire immediately. This is done using the
*approximate* timestamp of the oldest message in the database, to
avoid revealing the presence or absence of any particular message.
2011-08-05 13:34:58 +01:00
akwizgran
5cb4075cfd Added the ability to store transport configuration details in the
database - unlike transport properties, these are not shared with
contacts. For example, when using email as a transport, the address
for sending and receiving emails would be a transport property, while
the username and password for the email server would be transport
configuration details. Transport plugins can update their
configuration details atomically.

Also clarified the terminology for transport and subscription updates.
2011-08-04 13:41:41 +01:00
akwizgran
ec29c4d1d3 Changed the format of transport properties from (key, value) pairs to
(transport name, key, value) triples. This makes it possible for each
transport plugin to update its locally stored properties atomically.
2011-08-04 11:07:28 +01:00
akwizgran
93ee4d004e Reduced maximum public key lengths to reasonable lengths for ECDSA. 2011-08-03 21:08:09 +01:00
akwizgran
c90a18278b Allow a maximum length to be specified when reading strings or byte
arrays, check it before allocating the buffer, and always specify the
maximum length when reading untrusted data - otherwise
CountingConsumer will reject the packet, but not before we've tried to
allocate a buffer of the specified size (up to 2 GB).
2011-08-03 19:29:30 +01:00
akwizgran
7baefb3e7b Updated the transport plugin API. 2011-08-03 16:13:13 +01:00
akwizgran
6e7d5a06b2 API for batch-mode and stream-mode transport plugins. 2011-08-02 15:09:24 +01:00
akwizgran
2740b2b002 s/transport details/transport properties/g 2011-08-02 13:08:44 +01:00
akwizgran
0e48f4ba55 Listeners for local transport updates. 2011-08-02 09:44:15 +01:00
akwizgran
ff0909a0e9 Listeners for subscription changes. 2011-08-02 09:22:54 +01:00
akwizgran
cee4956b37 If no messages are added to a batch, don't call BatchWriter.finish() -
this allows the caller to avoid creating an empty packet by delaying
creation of the packet's header and trailer until something's written
to the packet's body. Changed the return semantics of
DatabaseComponent.generateBatch(ContactId, BatchWriter,
Collection<MessageId>) so that the IDs of messages considered for
inclusion in the batch but no longer sendable are also returned - this
allows the caller to remove them from the set of requested IDs.
2011-07-28 11:17:33 +01:00
akwizgran
adee3e121c Added support for registering listeners with the database that are
called when new messages are available, and a new method
hasSendableMessages(ContactId) that listeners can call to see whether
it's worth trying to create a batch.
2011-07-27 20:27:43 +01:00
akwizgran
e93fbe0b20 Implemented subscription visibility. If a subscription is not visible
to a contact, do not accept, offer, or send messages belonging to that
group to or from that contact, and do not list that group in
subscription updates sent to that contact.
2011-07-27 16:43:19 +01:00
akwizgran
b161e5ed1d Request reader and unit test. 2011-07-27 11:06:54 +01:00
akwizgran
9e78837055 Implemented OfferWriter and RequestWriter, made all the writers
reusable (though not thread-safe), and guiced the readers.
2011-07-26 21:36:55 +01:00
akwizgran
8ba5b46d59 More unit tests for DatabaseComponent. 2011-07-26 18:11:57 +01:00