Skip to content

Commit 7e4c137

Browse files
PubNub SDK v5.1.1 release.
1 parent cbb2802 commit 7e4c137

File tree

13 files changed

+120
-67
lines changed

13 files changed

+120
-67
lines changed

.pubnub.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
name: kotlin
2-
version: 5.1.0
2+
version: 5.1.1
33
schema: 1
44
scm: github.com/pubnub/kotlin
55
files:
6-
- build/libs/pubnub-kotlin-5.1.0-all.jar
6+
- build/libs/pubnub-kotlin-5.1.1-all.jar
77
changelog:
8+
-
9+
version: v5.1.1
10+
date: 2021-01-20
11+
changes:
12+
-
13+
type: bug
14+
text: "File upload encryption fix."
15+
-
16+
type: bug
17+
text: "Asynchronous file upload encryption fix."
18+
-
19+
type: bug
20+
text: "Telemetry fix - removal of `putIfAbsent`."
821
-
922
version: v5.1.0
1023
date: 2020-12-16

.travis.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
jdk: oraclejdk8
12
language: java
23
dist: trusty
34
os: linux
@@ -26,22 +27,16 @@ jobs:
2627
include:
2728
- stage: "test"
2829
name: "Build & test"
29-
jdk: oraclejdk8
30-
dist: trusty
3130
script:
3231
- ./gradlew assemble
3332
- ./gradlew check
3433
- stage: "code coverage"
3534
name: "Code coverage"
36-
jdk: oraclejdk8
37-
dist: trusty
3835
script:
3936
- ./gradlew assemble
4037
- ./gradlew check
4138
after_success:
4239
- java -cp ~/codacy-coverage-reporter-2.0.0-assembly.jar com.codacy.CodacyCoverageReporter -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
4340
- stage: "validate"
4441
name: "Validate clean build & test"
45-
jdk: oraclejdk8
46-
dist: trusty
4742
script: ./gradlew clean build

CHANGELOG.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
## [v5.1.0](https://github.com/pubnub/kotlin/releases/tag/v5.1.0)
2-
December 16 2020
1+
## [v5.1.1](https://github.com/pubnub/kotlin/releases/tag/v5.1.1)
2+
January 20 2021
33

4-
[Full Changelog](https://github.com/pubnub/kotlin/compare/v5.0.2...v5.1.0)
4+
[Full Changelog](https://github.com/pubnub/kotlin/compare/v5.1.0...v5.1.1)
55

6-
- Files support includes sending, downloading, listing, deleting together with notifications about file events.
7-
- New methods can set and remove memberships/channelMembers in one call.
8-
- New field `page` can be returned from the backend in case there's more data to fetch for the original query. This new field can be used directly in new `fetchMessages` and `getMessagesActions` method versions. The old versions in which paging information was in separate arguments has been deprecated.
9-
- FetchMessages has a default limit of 100 for single-channel call.
10-
- Make PNMessageActionResultevent accessible (no longer internal).
11-
- Method `addMemberships` has been deprecated and shouldn't be used in the future.
6+
- File upload encryption fix.
7+
- Asynchronous file upload encryption fix.
8+
- Telemetry fix - removal of `putIfAbsent`.
129

1310

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### PubNub Kotlin-based SDKs for Android
22

3-
[![Build Status](https://travis-ci.org/pubnub/kotlin.svg?branch=master)](https://travis-ci.org/pubnub/kotlin)
3+
[![Build Status](https://travis-ci.com/pubnub/kotlin.svg?branch=master)](https://travis-ci.com/pubnub/kotlin)
44
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/164fd518c314417e896b3de494ab75df)](https://www.codacy.com/app/PubNub/kotlin?utm_source=github.com&utm_medium=referral&utm_content=pubnub/kotlin&utm_campaign=Badge_Grade)
55
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/164fd518c314417e896b3de494ab75df)](https://www.codacy.com/app/PubNub/kotlin?utm_source=github.com&utm_medium=referral&utm_content=pubnub/kotlin&utm_campaign=Badge_Coverage)
66
[![Download](https://api.bintray.com/packages/bintray/jcenter/com.pubnub%3Apubnub-kotlin/images/download.svg)](https://bintray.com/bintray/jcenter/com.pubnub%3Apubnub-kotlin/_latestVersion)

src/integrationTest/kotlin/com/pubnub/api/integration/FilesIntegrationTest.kt

+43
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import java.nio.charset.StandardCharsets
2020
import java.util.Scanner
2121
import java.util.concurrent.CountDownLatch
2222
import java.util.concurrent.TimeUnit
23+
import java.util.concurrent.atomic.AtomicReference
2324

2425
class FilesIntegrationTest : BaseIntegrationTest() {
2526
@Test
@@ -32,6 +33,48 @@ class FilesIntegrationTest : BaseIntegrationTest() {
3233
uploadListDownloadDelete(false)
3334
}
3435

36+
@Test
37+
fun uploadAsyncAndDelete() {
38+
val channel: String = randomChannel()
39+
val content = "This is content"
40+
val message = "This is message"
41+
val meta = "This is meta"
42+
val fileName = "fileName$channel.txt"
43+
val fileSent = CountDownLatch(1)
44+
pubnub.subscribe(channels = listOf(channel))
45+
val sendResultReference: AtomicReference<PNFileUploadResult> = AtomicReference()
46+
ByteArrayInputStream(content.toByteArray(StandardCharsets.UTF_8)).use {
47+
pubnub.sendFile(
48+
channel = channel,
49+
fileName = fileName,
50+
inputStream = it,
51+
message = message,
52+
meta = meta
53+
).async { r, s ->
54+
if (!s.error) {
55+
sendResultReference.set(r)
56+
}
57+
fileSent.countDown()
58+
}
59+
}
60+
61+
if (!fileSent.await(3, TimeUnit.SECONDS)) {
62+
Assert.fail()
63+
return
64+
}
65+
val sendResult = sendResultReference.get()
66+
67+
if (sendResult == null) {
68+
Assert.fail()
69+
return
70+
}
71+
72+
pubnub.deleteFile(channel = channel,
73+
fileName = fileName,
74+
fileId = sendResult.file.id)
75+
.sync()
76+
}
77+
3578
private fun uploadListDownloadDelete(withCipher: Boolean) {
3679
if (withCipher) {
3780
pubnub.configuration.cipherKey = "enigma"

src/main/java/com/pubnub/api/vendor/Crypto.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import javax.crypto.spec.IvParameterSpec;
88
import javax.crypto.spec.SecretKeySpec;
99
import java.io.UnsupportedEncodingException;
10-
import java.nio.charset.StandardCharsets;
1110
import java.security.MessageDigest;
1211
import java.security.spec.AlgorithmParameterSpec;
1312
import java.util.Random;
@@ -84,6 +83,10 @@ public static PubNubException newCryptoError(int code, Exception exception) {
8483
}
8584

8685
public String encrypt(String input) throws PubNubException {
86+
return encrypt(input, Base64.NO_WRAP);
87+
}
88+
89+
public String encrypt(String input, Integer flags) throws PubNubException {
8790
try {
8891
initCiphers();
8992
AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes);
@@ -95,37 +98,34 @@ public String encrypt(String input) throws PubNubException {
9598
byte[] encryptedWithIV = new byte[ivBytes.length + encrypted.length];
9699
System.arraycopy(ivBytes, 0, encryptedWithIV, 0, ivBytes.length);
97100
System.arraycopy(encrypted, 0, encryptedWithIV, ivBytes.length, encrypted.length);
98-
return new String(Base64.encode(encryptedWithIV, 0), ENCODING_UTF_8);
101+
return new String(Base64.encode(encryptedWithIV, flags), ENCODING_UTF_8);
99102
}
100103
else {
101-
return new String(Base64.encode(cipher.doFinal(input.getBytes(ENCODING_UTF_8)), 0), ENCODING_UTF_8);
104+
return new String(Base64.encode(cipher.doFinal(input.getBytes(ENCODING_UTF_8)), flags), ENCODING_UTF_8);
102105
}
103106
} catch (Exception e) {
104107
throw newCryptoError(0, e);
105108
}
106109

107110
}
108111

109-
/**
110-
* Decrypt
111-
*
112-
* @param cipher_text
113-
* @return String
114-
* @throws PubNubException
115-
*/
116112
public String decrypt(String cipher_text) throws PubNubException {
113+
return decrypt(cipher_text, Base64.NO_WRAP);
114+
}
115+
116+
public String decrypt(String cipher_text, Integer flags) throws PubNubException {
117117
try {
118118
byte[] dataBytes;
119119
initCiphers();
120120
if (dynamicIV){
121-
dataBytes = Base64.decode(cipher_text, 0);
121+
dataBytes = Base64.decode(cipher_text, flags);
122122
System.arraycopy(dataBytes, 0, ivBytes, 0, 16);
123123
byte[] receivedCipherBytes = new byte[dataBytes.length - 16];
124124
System.arraycopy(dataBytes, 16, receivedCipherBytes, 0, dataBytes.length-16);
125125
dataBytes = receivedCipherBytes;
126126
}
127127
else {
128-
dataBytes = Base64.decode(cipher_text, 0);
128+
dataBytes = Base64.decode(cipher_text, flags);
129129
}
130130
AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes);
131131
SecretKeySpec newKey = new SecretKeySpec(keyBytes, "AES");

src/main/kotlin/com/pubnub/api/PubNub.kt

+8-17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel
6767
import com.pubnub.api.models.consumer.objects.member.PNUUIDWithCustom
6868
import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel
6969
import com.pubnub.api.models.consumer.objects.membership.PNChannelWithCustom
70+
import com.pubnub.api.vendor.Base64
7071
import com.pubnub.api.vendor.Crypto
7172
import com.pubnub.api.vendor.FileEncryptionUtil.decrypt
7273
import com.pubnub.api.vendor.FileEncryptionUtil.encrypt
@@ -78,7 +79,7 @@ class PubNub(val configuration: PNConfiguration) {
7879

7980
private companion object Constants {
8081
private const val TIMESTAMP_DIVIDER = 1000
81-
private const val SDK_VERSION = "5.1.0"
82+
private const val SDK_VERSION = "5.1.1"
8283
private const val MAX_SEQUENCE = 65535
8384
}
8485

@@ -1765,13 +1766,13 @@ class PubNub(val configuration: PNConfiguration) {
17651766
* Perform Cryptographic decryption of an input string using a cipher key.
17661767
*
17671768
* @param inputString String to be decrypted.
1768-
* @param cipherKey cipher key to be used for decryption.
1769+
* @param cipherKey cipher key to be used for decryption. Default is [PNConfiguration.cipherKey]
17691770
*
17701771
* @return String containing the decryption of `inputString` using `cipherKey`.
17711772
* @throws PubNubException throws exception in case of failed decryption.
17721773
*/
1773-
fun decrypt(inputString: String, cipherKey: String): String =
1774-
Crypto(cipherKey).decrypt(inputString)
1774+
fun decrypt(inputString: String, cipherKey: String = configuration.cipherKey): String =
1775+
Crypto(cipherKey).decrypt(inputString, Base64.DEFAULT)
17751776

17761777
/**
17771778
* Perform Cryptographic decryption of an input stream using provided cipher key.
@@ -1787,27 +1788,17 @@ class PubNub(val configuration: PNConfiguration) {
17871788
cipherKey: String = configuration.cipherKey
17881789
): InputStream = decrypt(inputStream, cipherKey)
17891790

1790-
/**
1791-
* Perform Cryptographic encryption of an input string and the cipher key provided by [PNConfiguration.cipherKey].
1792-
*
1793-
* @param inputString String to be encrypted.
1794-
*
1795-
* @return String containing the encryption of `inputString` using `cipherKey`.
1796-
* @throws PubNubException Throws exception in case of failed encryption.
1797-
*/
1798-
fun encrypt(inputString: String): String = encrypt(inputString, configuration.cipherKey)
1799-
18001791
/**
18011792
* Perform Cryptographic encryption of an input string and a cipher key.
18021793
*
18031794
* @param inputString String to be encrypted.
1804-
* @param cipherKey Cipher key to be used for encryption.
1795+
* @param cipherKey Cipher key to be used for encryption. Default is [PNConfiguration.cipherKey]
18051796
*
18061797
* @return String containing the encryption of `inputString` using `cipherKey`.
18071798
* @throws PubNubException Throws exception in case of failed encryption.
18081799
*/
1809-
fun encrypt(inputString: String, cipherKey: String): String =
1810-
Crypto(cipherKey).encrypt(inputString)
1800+
fun encrypt(inputString: String, cipherKey: String = configuration.cipherKey): String =
1801+
Crypto(cipherKey).encrypt(inputString, Base64.DEFAULT)
18111802

18121803
/**
18131804
* Perform Cryptographic encryption of an input stream using provided cipher key.

src/main/kotlin/com/pubnub/api/endpoints/files/UploadFile.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ internal class UploadFile(
104104
return
105105
}
106106
callback(
107-
null,
107+
Unit,
108108
createStatusResponse(
109109
PNStatusCategory.PNAcknowledgmentCategory, response,
110110
null

src/main/kotlin/com/pubnub/api/endpoints/pubsub/Publish.kt

-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,5 @@ class Publish internal constructor(
123123
private fun encryptMessage(message: String): String =
124124
Crypto(pubnub.configuration.cipherKey)
125125
.encrypt(message)
126-
.replace("\n", "")
127126
// endregion
128127
}

src/main/kotlin/com/pubnub/api/managers/TelemetryManager.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class TelemetryManager {
6565
type.queryParam?.let { queryParam: String ->
6666
if (latency > 0) {
6767
val storeDate = currentDate / (TIMESTAMP_DIVIDER.toDouble())
68-
latencies.putIfAbsent(queryParam, mutableListOf())
68+
if (latencies[queryParam] == null) {
69+
latencies[queryParam] = ArrayList()
70+
}
6971

7072
latencies[queryParam]?.let {
7173
val latencyEntry = Latency(

src/main/kotlin/com/pubnub/api/models/server/SubscribeMessage.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.pubnub.api.models.server
22

33
import com.google.gson.JsonElement
44
import com.google.gson.annotations.SerializedName
5+
import com.pubnub.api.workers.SubscribeMessageWorker.Companion.TYPE_FILES
6+
import com.pubnub.api.workers.SubscribeMessageWorker.Companion.TYPE_MESSAGE
57

68
class SubscribeMessage(
79
@SerializedName("a")
@@ -39,5 +41,5 @@ class SubscribeMessage(
3941

4042
) {
4143

42-
fun supportsEncryption() = type == null || type == 0
44+
fun supportsEncryption() = type in arrayOf(null, TYPE_MESSAGE, TYPE_FILES)
4345
}

0 commit comments

Comments
 (0)