mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Explicitly check length of proof of ownership.
This commit is contained in:
@@ -22,4 +22,8 @@ interface HandshakeConstants {
|
|||||||
*/
|
*/
|
||||||
String BOB_PROOF_LABEL = "org.briarproject.bramble.handshake/BOB_PROOF";
|
String BOB_PROOF_LABEL = "org.briarproject.bramble.handshake/BOB_PROOF";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the proof of ownership in bytes.
|
||||||
|
*/
|
||||||
|
int PROOF_BYTES = 32;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,11 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_PUBLIC_KEY_BYTES;
|
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_PUBLIC_KEY_BYTES;
|
||||||
|
import static org.briarproject.bramble.contact.HandshakeConstants.PROOF_BYTES;
|
||||||
import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_VERSION;
|
import static org.briarproject.bramble.contact.HandshakeConstants.PROTOCOL_VERSION;
|
||||||
import static org.briarproject.bramble.contact.HandshakeRecordTypes.EPHEMERAL_PUBLIC_KEY;
|
import static org.briarproject.bramble.contact.HandshakeRecordTypes.EPHEMERAL_PUBLIC_KEY;
|
||||||
import static org.briarproject.bramble.contact.HandshakeRecordTypes.PROOF_OF_OWNERSHIP;
|
import static org.briarproject.bramble.contact.HandshakeRecordTypes.PROOF_OF_OWNERSHIP;
|
||||||
|
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -128,11 +130,9 @@ class HandshakeManagerImpl implements HandshakeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PublicKey receivePublicKey(RecordReader r) throws IOException {
|
private PublicKey receivePublicKey(RecordReader r) throws IOException {
|
||||||
Record rec = readRecord(r, EPHEMERAL_PUBLIC_KEY);
|
byte[] key = readRecord(r, EPHEMERAL_PUBLIC_KEY).getPayload();
|
||||||
int length = rec.getPayload().length;
|
checkLength(key, 1, MAX_AGREEMENT_PUBLIC_KEY_BYTES);
|
||||||
if (length == 0 || length > MAX_AGREEMENT_PUBLIC_KEY_BYTES)
|
return new AgreementPublicKey(key);
|
||||||
throw new FormatException();
|
|
||||||
return new AgreementPublicKey(rec.getPayload());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendProof(RecordWriter w, byte[] proof) throws IOException {
|
private void sendProof(RecordWriter w, byte[] proof) throws IOException {
|
||||||
@@ -141,7 +141,9 @@ class HandshakeManagerImpl implements HandshakeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte[] receiveProof(RecordReader r) throws IOException {
|
private byte[] receiveProof(RecordReader r) throws IOException {
|
||||||
return readRecord(r, PROOF_OF_OWNERSHIP).getPayload();
|
byte[] proof = readRecord(r, PROOF_OF_OWNERSHIP).getPayload();
|
||||||
|
checkLength(proof, PROOF_BYTES, PROOF_BYTES);
|
||||||
|
return proof;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Record readRecord(RecordReader r, byte expectedType)
|
private Record readRecord(RecordReader r, byte expectedType)
|
||||||
|
|||||||
Reference in New Issue
Block a user