~yujiri/libsufec

9104cfca6609f7246bbe937b651e534dbdd4135c — Evin Yulo 2 years ago ab5a30d
protocol update: server sends the number of recipient keys, not length
1 files changed, 3 insertions(+), 8 deletions(-)

M src/server.rs
M src/server.rs => src/server.rs +3 -8
@@ 36,16 36,11 @@ pub fn send(
	// Send recipient ID.
	stream.send(&recipient.0)?;
	// Read recipient's keys.
	let keys_length = stream.receive(4)?.try_into().unwrap();
	let keys_length = u32::from_be_bytes(keys_length) as usize;
	if keys_length == 0 {
	let num_keys = stream.receive(1)?[0];
	if num_keys == 0 {
		return Err(ServerError::RecipientNotFound);
	}
	// If we got an evil length, return error so we don't panic trying to convert the chunks to keys.
	if keys_length % PUBLICKEYBYTES != 0 {
		return Err(ServerError::BadServer("invalid recipient keys"));
	}
	let keys_buf = stream.receive(keys_length)?;
	let keys_buf = stream.receive(num_keys as usize * PUBLICKEYBYTES)?;
	let keys = keys_buf.chunks(PUBLICKEYBYTES).map(|k| PublicKey::from_slice(k).unwrap());
	for (i, key) in keys.enumerate() {
		let copy = encrypt_message(account, &recipient, &key, &message);