There's something wrong with the V5 broadcast signature. I'm not quite shure what it is, so I made a test.
This commit is contained in:
parent
b4683bba68
commit
35996019a2
@ -67,14 +67,15 @@ public class Plaintext implements Streamable {
|
||||
}
|
||||
|
||||
public static Plaintext.Builder readWithoutSignature(Type type, InputStream in) throws IOException {
|
||||
long version = Decode.varInt(in);
|
||||
return new Builder(type)
|
||||
.addressVersion(Decode.varInt(in))
|
||||
.addressVersion(version)
|
||||
.stream(Decode.varInt(in))
|
||||
.behaviorBitfield(Decode.int32(in))
|
||||
.publicSigningKey(Decode.bytes(in, 64))
|
||||
.publicEncryptionKey(Decode.bytes(in, 64))
|
||||
.nonceTrialsPerByte(Decode.varInt(in))
|
||||
.extraBytes(Decode.varInt(in))
|
||||
.nonceTrialsPerByte(version >= 3 ? Decode.varInt(in) : 0)
|
||||
.extraBytes(version >= 3 ? Decode.varInt(in) : 0)
|
||||
.destinationRipe(type == Type.MSG ? Decode.bytes(in, 20) : null)
|
||||
.encoding(Decode.varInt(in))
|
||||
.message(Decode.varBytes(in))
|
||||
@ -136,8 +137,10 @@ public class Plaintext implements Streamable {
|
||||
Encode.int32(from.getPubkey().getBehaviorBitfield(), out);
|
||||
out.write(from.getPubkey().getSigningKey(), 1, 64);
|
||||
out.write(from.getPubkey().getEncryptionKey(), 1, 64);
|
||||
if (from.getVersion() >= 3) {
|
||||
Encode.varInt(from.getPubkey().getNonceTrialsPerByte(), out);
|
||||
Encode.varInt(from.getPubkey().getExtraBytes(), out);
|
||||
}
|
||||
if (type == Type.MSG) {
|
||||
out.write(to.getRipe());
|
||||
}
|
||||
|
@ -47,6 +47,21 @@ public abstract class Broadcast extends ObjectPayload implements Encrypted, Plai
|
||||
return address.getVersion() < 4 ? 4 : 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSigned() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getSignature() {
|
||||
return plaintext.getSignature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSignature(byte[] signature) {
|
||||
plaintext.setSignature(signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStream() {
|
||||
return stream;
|
||||
|
@ -52,16 +52,6 @@ public class V4Broadcast extends Broadcast {
|
||||
plaintext.write(out, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getSignature() {
|
||||
return plaintext.getSignature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSignature(byte[] signature) {
|
||||
plaintext.setSignature(signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(OutputStream out) throws IOException {
|
||||
encrypted.write(out);
|
||||
|
@ -27,21 +27,28 @@ import org.junit.Test;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DecryptionTest {
|
||||
@Test
|
||||
public void ensureV4BroadcastIsDecryptedCorrectly() throws IOException, DecryptionFailedException {
|
||||
BitmessageAddress address = new BitmessageAddress("BM-2D9Vc5rFxxR5vTi53T9gkLfemViHRMVLQZ");
|
||||
TestUtils.loadPubkey(address);
|
||||
ObjectMessage objectMessage = TestUtils.loadObjectMessage(5, "V4Broadcast.payload");
|
||||
V4Broadcast broadcast = (V4Broadcast) objectMessage.getPayload();
|
||||
broadcast.decrypt(new BitmessageAddress("BM-2D9Vc5rFxxR5vTi53T9gkLfemViHRMVLQZ"));
|
||||
broadcast.decrypt(address);
|
||||
assertEquals("Test-Broadcast", broadcast.getPlaintext().getSubject());
|
||||
assertTrue(objectMessage.isSignatureValid(address.getPubkey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureV5BroadcastIsDecryptedCorrectly() throws IOException, DecryptionFailedException {
|
||||
BitmessageAddress address = new BitmessageAddress("BM-2cXxfcSetKnbHJX2Y85rSkaVpsdNUZ5q9h");
|
||||
TestUtils.loadPubkey(address);
|
||||
ObjectMessage objectMessage = TestUtils.loadObjectMessage(5, "V5Broadcast.payload");
|
||||
V5Broadcast broadcast = (V5Broadcast) objectMessage.getPayload();
|
||||
broadcast.decrypt(new BitmessageAddress("BM-2cXxfcSetKnbHJX2Y85rSkaVpsdNUZ5q9h"));
|
||||
broadcast.decrypt(address);
|
||||
assertEquals("Test-Broadcast", broadcast.getPlaintext().getSubject());
|
||||
assertTrue(objectMessage.isSignatureValid(address.getPubkey()));
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package ch.dissem.bitmessage.utils;
|
||||
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.ObjectMessage;
|
||||
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
||||
import ch.dissem.bitmessage.entity.payload.V4Pubkey;
|
||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
||||
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
||||
@ -76,4 +77,10 @@ public class TestUtils {
|
||||
address.setPubkey((V4Pubkey) object.getPayload());
|
||||
return address;
|
||||
}
|
||||
|
||||
public static void loadPubkey(BitmessageAddress address) throws IOException {
|
||||
byte[] bytes = getBytes(address.getAddress() + ".pubkey");
|
||||
Pubkey pubkey = Factory.readPubkey(address.getVersion(), address.getStream(), new ByteArrayInputStream(bytes), bytes.length, false);
|
||||
address.setPubkey(pubkey);
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user