Fixed system test and added some fixes for Java backwards compatibility
This commit is contained in:
@ -133,21 +133,20 @@ internal open class DefaultMessageListener(
|
||||
}
|
||||
|
||||
protected fun receive(objectMessage: ObjectMessage, broadcast: Broadcast) {
|
||||
val tag = if (broadcast is V5Broadcast) broadcast.tag else null
|
||||
for (subscription in ctx.addressRepository.getSubscriptions(broadcast.version)) {
|
||||
if (tag != null && !Arrays.equals(tag, subscription.tag)) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
broadcast.decrypt(subscription.publicDecryptionKey)
|
||||
if (!objectMessage.isSignatureValid(broadcast.plaintext!!.from.pubkey!!)) {
|
||||
LOG.warn("Broadcast with IV " + objectMessage.inventoryVector + " was successfully decrypted, but signature check failed. Ignoring.")
|
||||
} else {
|
||||
receive(objectMessage.inventoryVector, broadcast.plaintext!!)
|
||||
val tag = (broadcast as? V5Broadcast)?.tag
|
||||
ctx.addressRepository.getSubscriptions(broadcast.version)
|
||||
.filter { tag == null || Arrays.equals(tag, it.tag) }
|
||||
.forEach {
|
||||
try {
|
||||
broadcast.decrypt(it.publicDecryptionKey)
|
||||
if (!objectMessage.isSignatureValid(broadcast.plaintext!!.from.pubkey!!)) {
|
||||
LOG.warn("Broadcast with IV " + objectMessage.inventoryVector + " was successfully decrypted, but signature check failed. Ignoring.")
|
||||
} else {
|
||||
receive(objectMessage.inventoryVector, broadcast.plaintext!!)
|
||||
}
|
||||
} catch (_: DecryptionFailedException) {
|
||||
}
|
||||
} catch (_: DecryptionFailedException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected fun receive(iv: InventoryVector, msg: Plaintext) {
|
||||
|
@ -36,14 +36,14 @@ import java.util.*
|
||||
import java.util.Collections
|
||||
import kotlin.collections.HashSet
|
||||
|
||||
fun message(encoding: Plaintext.Encoding, subject: String, body: String): ByteArray = when (encoding) {
|
||||
internal fun message(encoding: Plaintext.Encoding, subject: String, body: String): ByteArray = when (encoding) {
|
||||
SIMPLE -> "Subject:$subject\nBody:$body".toByteArray()
|
||||
EXTENDED -> Message.Builder().subject(subject).body(body).build().zip()
|
||||
TRIVIAL -> (subject + body).toByteArray()
|
||||
IGNORE -> ByteArray(0)
|
||||
}
|
||||
|
||||
fun ackData(type: Plaintext.Type, ackData: ByteArray?): ByteArray? {
|
||||
internal fun ackData(type: Plaintext.Type, ackData: ByteArray?): ByteArray? {
|
||||
if (ackData != null) {
|
||||
return ackData
|
||||
} else if (type == MSG) {
|
||||
@ -67,6 +67,7 @@ class Plaintext private constructor(
|
||||
val conversationId: UUID = UUID.randomUUID(),
|
||||
var inventoryVector: InventoryVector? = null,
|
||||
var signature: ByteArray? = null,
|
||||
sent: Long? = null,
|
||||
val received: Long? = null,
|
||||
var initialHash: ByteArray? = null,
|
||||
ttl: Long = TTL.msg,
|
||||
@ -117,7 +118,7 @@ class Plaintext private constructor(
|
||||
}
|
||||
|
||||
val encoding: Encoding? by lazy { Encoding.fromCode(encodingCode) }
|
||||
var sent: Long? = null
|
||||
var sent: Long? = sent
|
||||
private set
|
||||
var retries: Int = 0
|
||||
private set
|
||||
@ -145,9 +146,9 @@ class Plaintext private constructor(
|
||||
type = type,
|
||||
from = from,
|
||||
to = to,
|
||||
encoding = encoding.code,
|
||||
encodingCode = encoding.code,
|
||||
message = message,
|
||||
ackMessage = ackData(type, ackData),
|
||||
ackData = ackData(type, ackData),
|
||||
conversationId = conversationId,
|
||||
inventoryVector = inventoryVector,
|
||||
signature = signature,
|
||||
@ -214,9 +215,9 @@ class Plaintext private constructor(
|
||||
type = type,
|
||||
from = from,
|
||||
to = to,
|
||||
encoding = encoding.code,
|
||||
encoding = encoding,
|
||||
message = message(encoding, subject, body),
|
||||
ackMessage = ackData(type, ackData),
|
||||
ackData = ackData(type, ackData),
|
||||
conversationId = conversationId,
|
||||
inventoryVector = null,
|
||||
signature = null,
|
||||
@ -248,6 +249,7 @@ class Plaintext private constructor(
|
||||
conversationId = builder.conversation ?: UUID.randomUUID(),
|
||||
inventoryVector = builder.inventoryVector,
|
||||
signature = builder.signature,
|
||||
sent = builder.sent,
|
||||
received = builder.received,
|
||||
initialHash = null,
|
||||
ttl = builder.ttl,
|
||||
|
@ -195,7 +195,7 @@ class CryptoBox : Streamable {
|
||||
companion object {
|
||||
private val LOG = LoggerFactory.getLogger(CryptoBox::class.java)
|
||||
|
||||
fun read(stream: InputStream, length: Int): CryptoBox {
|
||||
@JvmStatic fun read(stream: InputStream, length: Int): CryptoBox {
|
||||
val counter = AccessCounter()
|
||||
return Builder()
|
||||
.IV(Decode.bytes(stream, 16, counter))
|
||||
|
@ -53,7 +53,7 @@ class GenericPayload(version: Long, override val stream: Long, val data: ByteArr
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(version: Long, stream: Long, `is`: InputStream, length: Int): GenericPayload {
|
||||
@JvmStatic fun read(version: Long, stream: Long, `is`: InputStream, length: Int): GenericPayload {
|
||||
return GenericPayload(version, stream, Decode.bytes(`is`, length))
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class GetPubkey : ObjectPayload {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(`is`: InputStream, stream: Long, length: Int, version: Long): GetPubkey {
|
||||
@JvmStatic fun read(`is`: InputStream, stream: Long, length: Int, version: Long): GetPubkey {
|
||||
return GetPubkey(version, stream, Decode.bytes(`is`, length))
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class Msg : ObjectPayload, Encrypted, PlaintextHolder {
|
||||
companion object {
|
||||
val ACK_LENGTH = 32
|
||||
|
||||
fun read(`in`: InputStream, stream: Long, length: Int): Msg {
|
||||
@JvmStatic fun read(`in`: InputStream, stream: Long, length: Int): Msg {
|
||||
return Msg(stream, CryptoBox.read(`in`, length))
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ enum class ObjectType constructor(val number: Long) {
|
||||
BROADCAST(3);
|
||||
|
||||
companion object {
|
||||
fun fromNumber(number: Long): ObjectType? {
|
||||
@JvmStatic fun fromNumber(number: Long): ObjectType? {
|
||||
return values().firstOrNull { it.number == number }
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ open class V2Pubkey constructor(version: Long, override val stream: Long, overri
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(`in`: InputStream, stream: Long): V2Pubkey {
|
||||
@JvmStatic fun read(`in`: InputStream, stream: Long): V2Pubkey {
|
||||
return V2Pubkey(
|
||||
version = 2,
|
||||
stream = stream,
|
||||
|
@ -134,7 +134,7 @@ class V3Pubkey protected constructor(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(`is`: InputStream, stream: Long): V3Pubkey {
|
||||
@JvmStatic fun read(`is`: InputStream, stream: Long): V3Pubkey {
|
||||
return V3Pubkey(
|
||||
version = 3,
|
||||
stream = stream,
|
||||
|
@ -52,7 +52,7 @@ open class V4Broadcast : Broadcast {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(`in`: InputStream, stream: Long, length: Int): V4Broadcast {
|
||||
@JvmStatic fun read(`in`: InputStream, stream: Long, length: Int): V4Broadcast {
|
||||
return V4Broadcast(4, stream, CryptoBox.read(`in`, length), null)
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ class V4Pubkey : Pubkey, Encrypted {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(`in`: InputStream, stream: Long, length: Int, encrypted: Boolean): V4Pubkey {
|
||||
@JvmStatic fun read(`in`: InputStream, stream: Long, length: Int, encrypted: Boolean): V4Pubkey {
|
||||
if (encrypted)
|
||||
return V4Pubkey(stream,
|
||||
Decode.bytes(`in`, 32),
|
||||
|
@ -51,7 +51,7 @@ class V5Broadcast : V4Broadcast {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(`is`: InputStream, stream: Long, length: Int): V5Broadcast {
|
||||
@JvmStatic fun read(`is`: InputStream, stream: Long, length: Int): V5Broadcast {
|
||||
return V5Broadcast(stream, Decode.bytes(`is`, 32), CryptoBox.read(`is`, length - 32))
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ package ch.dissem.bitmessage.utils
|
||||
class Property private constructor(val name: String, val value: Any? = null, val properties: Array<Property> = emptyArray()) {
|
||||
|
||||
constructor(name: String, value: Any) : this(name = name, value = value, properties = emptyArray())
|
||||
constructor(name: String, vararg properties: Property) : this(name, null, Array(properties.size, { i -> properties[i] }))
|
||||
constructor(name: String, vararg properties: Property) : this(name, null, arrayOf(*properties))
|
||||
constructor(name: String, properties: List<Property>) : this(name, null, properties.toTypedArray())
|
||||
|
||||
/**
|
||||
* Returns the property if available or `null` otherwise.
|
||||
|
Reference in New Issue
Block a user