Encrypt and save crash reports, send them the next time TorPlugin start

Will currently fail at runtime; requires a public key and a server onion.
This commit is contained in:
str4d
2016-03-31 11:11:55 +00:00
parent 28086cd359
commit d545aaa892
18 changed files with 342 additions and 32 deletions

View File

@@ -18,6 +18,7 @@ import org.briarproject.util.ByteUtils;
import org.briarproject.util.StringUtils;
import org.spongycastle.crypto.AsymmetricCipherKeyPair;
import org.spongycastle.crypto.CipherParameters;
import org.spongycastle.crypto.CryptoException;
import org.spongycastle.crypto.Digest;
import org.spongycastle.crypto.agreement.ECDHCBasicAgreement;
import org.spongycastle.crypto.digests.SHA256Digest;
@@ -28,6 +29,7 @@ import org.spongycastle.crypto.params.ECPrivateKeyParameters;
import org.spongycastle.crypto.params.ECPublicKeyParameters;
import org.spongycastle.crypto.params.KeyParameter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
@@ -438,6 +440,18 @@ class CryptoComponentImpl implements CryptoComponent {
}
}
public String encryptToKey(byte[] publicKey, byte[] plaintext) {
MessageEncrypter encrypter = new MessageEncrypter(secureRandom);
try {
byte[] ciphertext = encrypter.encrypt(publicKey, plaintext);
return AsciiArmour.wrap(ciphertext, 70);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (CryptoException e) {
throw new RuntimeException(e);
}
}
// Key derivation function based on a pseudo-random function - see
// NIST SP 800-108, section 5.1
private byte[] macKdf(SecretKey key, byte[]... inputs) {

View File

@@ -70,6 +70,14 @@ public class MessageEncrypter {
return generator.generateKeyPair();
}
byte[] encrypt(byte[] keyBytes, byte[] plaintext)
throws IOException, CryptoException {
InputStream in = new ByteArrayInputStream(keyBytes);
ECPublicKeyParameters publicKey =
(ECPublicKeyParameters) parser.readKey(in);
return encrypt(publicKey, plaintext);
}
byte[] encrypt(ECPublicKeyParameters pubKey, byte[] plaintext)
throws CryptoException {
IESEngine engine = getEngine();
@@ -159,10 +167,7 @@ public class MessageEncrypter {
}
// Encrypt a decrypted message
InputStream in = new FileInputStream(args[1]);
byte[] b = StringUtils.fromHexString(readFully(in).trim());
in = new ByteArrayInputStream(b);
ECPublicKeyParameters publicKey =
(ECPublicKeyParameters) encrypter.parser.readKey(in);
byte[] publicKey = StringUtils.fromHexString(readFully(in).trim());
String message = readFully(System.in);
byte[] plaintext = message.getBytes(Charset.forName("UTF-8"));
byte[] ciphertext = encrypter.encrypt(publicKey, plaintext);