~yujiri/libsufec-java

7c233c787c6c9ce2bdf2722b38847f1f7852b5d9 — Yujiri 3 months ago 8249195
protocol update

* address wire format changed
* server-side timestamps removed
* length only sent before the first copy of a message
M src/main/java/jsufec/Connection.java => src/main/java/jsufec/Connection.java +4 -6
@@ 68,7 68,9 @@ public class Connection {
			keysBuffer.get(keyBytes);
			Key key = Key.fromBytes(keyBytes);
			byte[] ciphertext = Crypto.encryptMessage(this.ls, this.account, recipient.id, key, message);
			this.encrypted.send(ByteConv.intToBytes(ciphertext.length));
			if (i == 0) {
				this.encrypted.send(ByteConv.intToBytes(ciphertext.length));
			}
			this.encrypted.send(ciphertext);
		}
		this.encrypted.receive(1);


@@ 103,18 105,14 @@ public class Connection {
		byte[] lengthBytes = this.encrypted.receive(4);
		ByteBuffer lengthBuffer = ByteBuffer.wrap(lengthBytes);
		int payloadLength = lengthBuffer.getInt();
		if (payloadLength < 8) {
			throw new BadServerException("transmission has invalid length");
		}
		byte[] payloadBytes = this.encrypted.receive(payloadLength);
		ByteBuffer payloadBuffer = ByteBuffer.wrap(payloadBytes);
		Date timestamp = new Date(payloadBuffer.getLong());
		byte[] messageBytes = new byte[payloadLength - Long.BYTES];
		payloadBuffer.get(messageBytes);
		byte[] confirmation = {0};
		this.encrypted.send(confirmation);
		DecryptionResult decrypted = Crypto.decryptMessage(this.ls, messageBytes,
			this.account, this.newEphSec, this.oldEphSec);
		return new MessageReceived(timestamp, decrypted.sender, decrypted.message);
		return new MessageReceived(decrypted.sender, decrypted.message);
	}
}

M src/main/java/jsufec/MessageReceived.java => src/main/java/jsufec/MessageReceived.java +1 -5
@@ 1,13 1,9 @@
package jsufec;

import java.util.Date;

public class MessageReceived {
	public Date timestamp;
	public SufecAddr sender;
	public Message message;
	public MessageReceived(Date timestamp, SufecAddr sender, Message message) {
		this.timestamp = timestamp;
	public MessageReceived(SufecAddr sender, Message message) {
		this.sender = sender;
		this.message = message;
	}

M src/main/java/jsufec/SufecAddr.java => src/main/java/jsufec/SufecAddr.java +3 -4
@@ 17,10 17,9 @@ public class SufecAddr {
	public byte[] toBytes() {
		byte[] idBytes = this.id.getAsBytes();
		byte[] atBytes = this.at.getBytes(StandardCharsets.UTF_8);
		byte[] output = new byte[Box.PUBLICKEYBYTES + 1 + atBytes.length];
		System.arraycopy(idBytes, 0, output, 0, Box.PUBLICKEYBYTES);
		output[Box.PUBLICKEYBYTES] = (byte) atBytes.length;
		System.arraycopy(atBytes, 0, output, Box.PUBLICKEYBYTES + 1, atBytes.length);
		byte[] output = new byte[idBytes.length + atBytes.length];
		System.arraycopy(idBytes, 0, output, 0, idBytes.length);
		System.arraycopy(atBytes, 0, output, idBytes.length, atBytes.length);
		return output;
	}
	public static SufecAddr fromBytes(ByteBuffer bytes) {