mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Added TestDatabaseModule so tests can specify their own DB configuration. The modules are currently too tightly coupled - see whether any dependencies can be removed.
39 lines
1.2 KiB
Java
39 lines
1.2 KiB
Java
package net.sf.briar.transport;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import javax.crypto.Cipher;
|
|
import javax.crypto.Mac;
|
|
import javax.crypto.SecretKey;
|
|
|
|
import net.sf.briar.api.crypto.CryptoComponent;
|
|
import net.sf.briar.api.transport.ConnectionReader;
|
|
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
|
|
|
import com.google.inject.Inject;
|
|
|
|
class ConnectionReaderFactoryImpl implements ConnectionReaderFactory {
|
|
|
|
private final CryptoComponent crypto;
|
|
|
|
@Inject
|
|
ConnectionReaderFactoryImpl(CryptoComponent crypto) {
|
|
this.crypto = crypto;
|
|
}
|
|
|
|
public ConnectionReader createConnectionReader(InputStream in,
|
|
byte[] encryptedIv, byte[] secret) {
|
|
// Create the decrypter
|
|
Cipher ivCipher = crypto.getIvCipher();
|
|
Cipher frameCipher = crypto.getFrameCipher();
|
|
SecretKey ivKey = crypto.deriveIncomingIvKey(secret);
|
|
SecretKey frameKey = crypto.deriveIncomingFrameKey(secret);
|
|
ConnectionDecrypter decrypter = new ConnectionDecrypterImpl(in,
|
|
encryptedIv, ivCipher, frameCipher, ivKey, frameKey);
|
|
// Create the reader
|
|
Mac mac = crypto.getMac();
|
|
SecretKey macKey = crypto.deriveIncomingMacKey(secret);
|
|
return new ConnectionReaderImpl(decrypter, mac, macKey);
|
|
}
|
|
}
|