Use byte array instead of PubKeys, Use uid for mailbox msg, Improve storage data structure, Renamings, Cleanup

This commit is contained in:
Manfred Karrer 2016-02-22 23:20:20 +01:00
parent bb6334f6a0
commit 77511a43f5
101 changed files with 869 additions and 1074 deletions

View file

@ -41,16 +41,14 @@ public final class PubKeyRing implements Payload {
private static final Logger log = LoggerFactory.getLogger(PubKeyRing.class);
private final byte[] signaturePubKeyBytes;
private final byte[] encryptionPubKeyBytes;
transient private PublicKey signaturePubKey;
private final byte[] signaturePubKeyBytes;
transient private PublicKey encryptionPubKey;
private final byte[] encryptionPubKeyBytes;
public PubKeyRing(PublicKey signaturePubKey, PublicKey encryptionPubKey) {
this.signaturePubKey = signaturePubKey;
this.encryptionPubKey = encryptionPubKey;
this.signaturePubKeyBytes = new X509EncodedKeySpec(signaturePubKey.getEncoded()).getEncoded();
this.encryptionPubKeyBytes = new X509EncodedKeySpec(encryptionPubKey.getEncoded()).getEncoded();
}

View file

@ -19,24 +19,42 @@ package io.bitsquare.common.crypto;
import io.bitsquare.app.Version;
import io.bitsquare.common.wire.Payload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
public final class SealedAndSigned implements Payload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private static final Logger log = LoggerFactory.getLogger(SealedAndSigned.class);
public final byte[] encryptedSecretKey;
public final byte[] encryptedPayloadWithHmac;
public final byte[] signature;
public final PublicKey sigPublicKey;
public transient PublicKey sigPublicKey;
private final byte[] sigPublicKeyBytes;
public SealedAndSigned(byte[] encryptedSecretKey, byte[] encryptedPayloadWithHmac, byte[] signature, PublicKey sigPublicKey) {
this.encryptedSecretKey = encryptedSecretKey;
this.encryptedPayloadWithHmac = encryptedPayloadWithHmac;
this.signature = signature;
this.sigPublicKey = sigPublicKey;
this.sigPublicKeyBytes = new X509EncodedKeySpec(this.sigPublicKey.getEncoded()).getEncoded();
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
try {
in.defaultReadObject();
sigPublicKey = KeyFactory.getInstance(Sig.KEY_ALGO, "BC").generatePublic(new X509EncodedKeySpec(sigPublicKeyBytes));
} catch (Throwable t) {
log.error("Exception at readObject: " + t.getMessage());
t.printStackTrace();
}
}
@Override

View file

@ -197,7 +197,6 @@ public class FileManager<T> {
fileOutputStream = new FileOutputStream(tempFile);
objectOutputStream = new ObjectOutputStream(fileOutputStream);
// TODO ConcurrentModificationException happens sometimes at that line
objectOutputStream.writeObject(serializable);
// Attempt to force the bits to hit the disk. In reality the OS or hard disk itself may still decide
// to not write through to physical media for at least a few seconds, but this is the best we can do.