Skip to content

Commit 520c375

Browse files
Merge pull request #1808 from session-foundation/release/1.30.3
Prepare for Release 1.30.3
2 parents 805110d + 433836f commit 520c375

28 files changed

Lines changed: 529 additions & 584 deletions

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ configurations.configureEach {
2626
exclude(module = "commons-logging")
2727
}
2828

29-
val canonicalVersionCode = 435
30-
val canonicalVersionName = "1.30.2"
29+
val canonicalVersionCode = 436
30+
val canonicalVersionName = "1.30.3"
3131

3232
val postFixSize = 10
3333
val abiPostFix = mapOf(

app/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.session.libsession.utilities.AESGCM
55
import org.session.libsession.utilities.AESGCM.EncryptionResult
66
import org.session.libsignal.utilities.JsonUtil
77
import org.session.libsignal.utilities.toHexString
8+
import java.io.ByteArrayOutputStream
89
import java.nio.Buffer
910
import java.nio.ByteBuffer
1011
import java.nio.ByteOrder
@@ -14,16 +15,15 @@ object OnionRequestEncryption {
1415
internal fun encode(ciphertext: ByteArray, json: Map<*, *>): ByteArray {
1516
// The encoding of V2 onion requests looks like: | 4 bytes: size N of ciphertext | N bytes: ciphertext | json as utf8 |
1617
val jsonAsData = JsonUtil.toJson(json).toByteArray()
17-
val ciphertextSize = ciphertext.size
18-
val buffer = ByteBuffer.allocate(Int.SIZE_BYTES)
19-
buffer.order(ByteOrder.LITTLE_ENDIAN)
20-
buffer.putInt(ciphertextSize)
21-
val ciphertextSizeAsData = ByteArray(buffer.capacity())
22-
// Casting here avoids an issue where this gets compiled down to incorrect byte code. See
23-
// https://github.com/eclipse/jetty.project/issues/3244 for more info
24-
(buffer as Buffer).position(0)
25-
buffer.get(ciphertextSizeAsData)
26-
return ciphertextSizeAsData + ciphertext + jsonAsData
18+
val output = ByteArray(4 + ciphertext.size + jsonAsData.size)
19+
20+
ByteBuffer.wrap(output).apply {
21+
order(ByteOrder.LITTLE_ENDIAN).putInt(ciphertext.size)
22+
put(ciphertext)
23+
put(jsonAsData)
24+
}
25+
26+
return output
2727
}
2828

2929
/**

app/src/main/java/org/session/libsession/utilities/AESGCM.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.session.libsignal.utilities.ByteArraySlice.Companion.view
99
import org.session.libsignal.utilities.ByteUtil
1010
import org.session.libsignal.utilities.Hex
1111
import org.session.libsignal.utilities.Util
12+
import java.nio.ByteBuffer
1213
import javax.crypto.Cipher
1314
import javax.crypto.Mac
1415
import javax.crypto.spec.GCMParameterSpec
@@ -57,10 +58,19 @@ internal object AESGCM {
5758
*/
5859
fun encrypt(plaintext: ByteArraySlice, symmetricKey: ByteArray): ByteArray {
5960
val iv = Util.getSecretBytes(ivSize)
60-
synchronized(CIPHER_LOCK) {
61+
62+
return synchronized(CIPHER_LOCK) {
6163
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
6264
cipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(symmetricKey, "AES"), GCMParameterSpec(gcmTagSize, iv))
63-
return ByteUtil.combine(iv, cipher.doFinal(plaintext.data, plaintext.offset, plaintext.len))
65+
66+
val output = ByteArray(ivSize + cipher.getOutputSize(plaintext.len))
67+
68+
ByteBuffer.wrap(output).also { buffer ->
69+
buffer.put(iv)
70+
cipher.doFinal(ByteBuffer.wrap(plaintext.data, plaintext.offset, plaintext.len), buffer)
71+
}
72+
73+
output
6474
}
6575
}
6676

0 commit comments

Comments
 (0)