Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • briar/briar
  • goapunk/briar
  • johndoe4221/briar
  • thomas/briar
4 results
Show changes
Commits on Source (2)
......@@ -25,6 +25,10 @@ import static org.briarproject.bramble.api.transport.TransportConstants.STREAM_H
import static org.briarproject.bramble.util.ByteUtils.INT_16_BYTES;
import static org.briarproject.bramble.util.ByteUtils.INT_64_BYTES;
/**
* See the BTP-Specs to understand whats going on here
* https://code.briarproject.org/briar/briar-spec/blob/master/protocols/BTP.md
*/
@NotThreadSafe
@NotNullByDefault
class StreamEncrypterImpl implements StreamEncrypter {
......@@ -81,9 +85,9 @@ class StreamEncrypterImpl implements StreamEncrypter {
FrameEncoder.encodeNonce(frameNonce, frameNumber, true);
try {
cipher.init(true, frameKey, frameNonce);
int encrypted = cipher.process(frameHeader, 0,
int encryptedLength = cipher.process(frameHeader, 0,
FRAME_HEADER_PLAINTEXT_LENGTH, frameCiphertext, 0);
if (encrypted != FRAME_HEADER_LENGTH) throw new RuntimeException();
if (encryptedLength != FRAME_HEADER_LENGTH) throw new RuntimeException();
} catch (GeneralSecurityException badCipher) {
throw new RuntimeException(badCipher);
}
......@@ -129,10 +133,10 @@ class StreamEncrypterImpl implements StreamEncrypter {
// Encrypt and authenticate the stream header key
try {
cipher.init(true, streamHeaderKey, streamHeaderNonce);
int encrypted = cipher.process(streamHeaderPlaintext, 0,
int encryptedLength = cipher.process(streamHeaderPlaintext, 0,
STREAM_HEADER_PLAINTEXT_LENGTH, streamHeaderCiphertext,
STREAM_HEADER_NONCE_LENGTH);
if (encrypted != STREAM_HEADER_PLAINTEXT_LENGTH + MAC_LENGTH)
if (encryptedLength != STREAM_HEADER_PLAINTEXT_LENGTH + MAC_LENGTH)
throw new RuntimeException();
} catch (GeneralSecurityException badCipher) {
throw new RuntimeException(badCipher);
......@@ -149,4 +153,4 @@ class StreamEncrypterImpl implements StreamEncrypter {
if (writeStreamHeader) writeStreamHeader();
out.flush();
}
}
\ No newline at end of file
}
......@@ -26,6 +26,11 @@ import static org.briarproject.bramble.api.sync.RecordTypes.REQUEST;
import static org.briarproject.bramble.api.sync.RecordTypes.VERSIONS;
import static org.briarproject.bramble.api.sync.SyncConstants.PROTOCOL_VERSION;
/**
* see the BSP-Specs
* https://code.briarproject.org/briar/briar-spec/blob/master/protocols/BSP.md
*/
@NotThreadSafe
@NotNullByDefault
class SyncRecordWriterImpl implements SyncRecordWriter {
......
......@@ -22,7 +22,7 @@ class StreamWriterImpl extends OutputStream implements StreamWriter {
private final StreamEncrypter encrypter;
private final byte[] payload;
/// length Stores how long the content that is currently in the buffer "payload" is.
private int length = 0;
StreamWriterImpl(StreamEncrypter encrypter) {
......@@ -68,6 +68,8 @@ class StreamWriterImpl extends OutputStream implements StreamWriter {
@Override
public void write(byte[] b, int off, int len) throws IOException {
//Frame Segmentation
// available = How much free space ther is at the end of the buffer "payload"
int available = payload.length - length;
while (available <= len) {
System.arraycopy(b, off, payload, length, available);
......
......@@ -63,6 +63,9 @@ class TransportKeyManagerImpl implements TransportKeyManager {
@GuardedBy("lock")
private final Map<KeySetId, MutableTransportKeySet> keys = new HashMap<>();
/**
* List of all Tags
*/
@GuardedBy("lock")
private final Map<Bytes, TagContext> inContexts = new HashMap<>();
@GuardedBy("lock")
......