Skip to content

Commit

Permalink
PubNub SDK v5.1.1 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Jan 20, 2021
1 parent cbb2802 commit 7e4c137
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 67 deletions.
17 changes: 15 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
name: kotlin
version: 5.1.0
version: 5.1.1
schema: 1
scm: github.com/pubnub/kotlin
files:
- build/libs/pubnub-kotlin-5.1.0-all.jar
- build/libs/pubnub-kotlin-5.1.1-all.jar
changelog:
-
version: v5.1.1
date: 2021-01-20
changes:
-
type: bug
text: "File upload encryption fix."
-
type: bug
text: "Asynchronous file upload encryption fix."
-
type: bug
text: "Telemetry fix - removal of `putIfAbsent`."
-
version: v5.1.0
date: 2020-12-16
Expand Down
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jdk: oraclejdk8
language: java
dist: trusty
os: linux
Expand Down Expand Up @@ -26,22 +27,16 @@ jobs:
include:
- stage: "test"
name: "Build & test"
jdk: oraclejdk8
dist: trusty
script:
- ./gradlew assemble
- ./gradlew check
- stage: "code coverage"
name: "Code coverage"
jdk: oraclejdk8
dist: trusty
script:
- ./gradlew assemble
- ./gradlew check
after_success:
- java -cp ~/codacy-coverage-reporter-2.0.0-assembly.jar com.codacy.CodacyCoverageReporter -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
- stage: "validate"
name: "Validate clean build & test"
jdk: oraclejdk8
dist: trusty
script: ./gradlew clean build
15 changes: 6 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
## [v5.1.0](https://github.com/pubnub/kotlin/releases/tag/v5.1.0)
December 16 2020
## [v5.1.1](https://github.com/pubnub/kotlin/releases/tag/v5.1.1)
January 20 2021

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

- Files support includes sending, downloading, listing, deleting together with notifications about file events.
- New methods can set and remove memberships/channelMembers in one call.
- 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.
- FetchMessages has a default limit of 100 for single-channel call.
- Make PNMessageActionResultevent accessible (no longer internal).
- Method `addMemberships` has been deprecated and shouldn't be used in the future.
- File upload encryption fix.
- Asynchronous file upload encryption fix.
- Telemetry fix - removal of `putIfAbsent`.


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### PubNub Kotlin-based SDKs for Android

[![Build Status](https://travis-ci.org/pubnub/kotlin.svg?branch=master)](https://travis-ci.org/pubnub/kotlin)
[![Build Status](https://travis-ci.com/pubnub/kotlin.svg?branch=master)](https://travis-ci.com/pubnub/kotlin)
[![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)
[![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)
[![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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.nio.charset.StandardCharsets
import java.util.Scanner
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference

class FilesIntegrationTest : BaseIntegrationTest() {
@Test
Expand All @@ -32,6 +33,48 @@ class FilesIntegrationTest : BaseIntegrationTest() {
uploadListDownloadDelete(false)
}

@Test
fun uploadAsyncAndDelete() {
val channel: String = randomChannel()
val content = "This is content"
val message = "This is message"
val meta = "This is meta"
val fileName = "fileName$channel.txt"
val fileSent = CountDownLatch(1)
pubnub.subscribe(channels = listOf(channel))
val sendResultReference: AtomicReference<PNFileUploadResult> = AtomicReference()
ByteArrayInputStream(content.toByteArray(StandardCharsets.UTF_8)).use {
pubnub.sendFile(
channel = channel,
fileName = fileName,
inputStream = it,
message = message,
meta = meta
).async { r, s ->
if (!s.error) {
sendResultReference.set(r)
}
fileSent.countDown()
}
}

if (!fileSent.await(3, TimeUnit.SECONDS)) {
Assert.fail()
return
}
val sendResult = sendResultReference.get()

if (sendResult == null) {
Assert.fail()
return
}

pubnub.deleteFile(channel = channel,
fileName = fileName,
fileId = sendResult.file.id)
.sync()
}

private fun uploadListDownloadDelete(withCipher: Boolean) {
if (withCipher) {
pubnub.configuration.cipherKey = "enigma"
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/pubnub/api/vendor/Crypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Random;
Expand Down Expand Up @@ -84,6 +83,10 @@ public static PubNubException newCryptoError(int code, Exception exception) {
}

public String encrypt(String input) throws PubNubException {
return encrypt(input, Base64.NO_WRAP);
}

public String encrypt(String input, Integer flags) throws PubNubException {
try {
initCiphers();
AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes);
Expand All @@ -95,37 +98,34 @@ public String encrypt(String input) throws PubNubException {
byte[] encryptedWithIV = new byte[ivBytes.length + encrypted.length];
System.arraycopy(ivBytes, 0, encryptedWithIV, 0, ivBytes.length);
System.arraycopy(encrypted, 0, encryptedWithIV, ivBytes.length, encrypted.length);
return new String(Base64.encode(encryptedWithIV, 0), ENCODING_UTF_8);
return new String(Base64.encode(encryptedWithIV, flags), ENCODING_UTF_8);
}
else {
return new String(Base64.encode(cipher.doFinal(input.getBytes(ENCODING_UTF_8)), 0), ENCODING_UTF_8);
return new String(Base64.encode(cipher.doFinal(input.getBytes(ENCODING_UTF_8)), flags), ENCODING_UTF_8);
}
} catch (Exception e) {
throw newCryptoError(0, e);
}

}

/**
* Decrypt
*
* @param cipher_text
* @return String
* @throws PubNubException
*/
public String decrypt(String cipher_text) throws PubNubException {
return decrypt(cipher_text, Base64.NO_WRAP);
}

public String decrypt(String cipher_text, Integer flags) throws PubNubException {
try {
byte[] dataBytes;
initCiphers();
if (dynamicIV){
dataBytes = Base64.decode(cipher_text, 0);
dataBytes = Base64.decode(cipher_text, flags);
System.arraycopy(dataBytes, 0, ivBytes, 0, 16);
byte[] receivedCipherBytes = new byte[dataBytes.length - 16];
System.arraycopy(dataBytes, 16, receivedCipherBytes, 0, dataBytes.length-16);
dataBytes = receivedCipherBytes;
}
else {
dataBytes = Base64.decode(cipher_text, 0);
dataBytes = Base64.decode(cipher_text, flags);
}
AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes);
SecretKeySpec newKey = new SecretKeySpec(keyBytes, "AES");
Expand Down
25 changes: 8 additions & 17 deletions src/main/kotlin/com/pubnub/api/PubNub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel
import com.pubnub.api.models.consumer.objects.member.PNUUIDWithCustom
import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel
import com.pubnub.api.models.consumer.objects.membership.PNChannelWithCustom
import com.pubnub.api.vendor.Base64
import com.pubnub.api.vendor.Crypto
import com.pubnub.api.vendor.FileEncryptionUtil.decrypt
import com.pubnub.api.vendor.FileEncryptionUtil.encrypt
Expand All @@ -78,7 +79,7 @@ class PubNub(val configuration: PNConfiguration) {

private companion object Constants {
private const val TIMESTAMP_DIVIDER = 1000
private const val SDK_VERSION = "5.1.0"
private const val SDK_VERSION = "5.1.1"
private const val MAX_SEQUENCE = 65535
}

Expand Down Expand Up @@ -1765,13 +1766,13 @@ class PubNub(val configuration: PNConfiguration) {
* Perform Cryptographic decryption of an input string using a cipher key.
*
* @param inputString String to be decrypted.
* @param cipherKey cipher key to be used for decryption.
* @param cipherKey cipher key to be used for decryption. Default is [PNConfiguration.cipherKey]
*
* @return String containing the decryption of `inputString` using `cipherKey`.
* @throws PubNubException throws exception in case of failed decryption.
*/
fun decrypt(inputString: String, cipherKey: String): String =
Crypto(cipherKey).decrypt(inputString)
fun decrypt(inputString: String, cipherKey: String = configuration.cipherKey): String =
Crypto(cipherKey).decrypt(inputString, Base64.DEFAULT)

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

/**
* Perform Cryptographic encryption of an input string and the cipher key provided by [PNConfiguration.cipherKey].
*
* @param inputString String to be encrypted.
*
* @return String containing the encryption of `inputString` using `cipherKey`.
* @throws PubNubException Throws exception in case of failed encryption.
*/
fun encrypt(inputString: String): String = encrypt(inputString, configuration.cipherKey)

/**
* Perform Cryptographic encryption of an input string and a cipher key.
*
* @param inputString String to be encrypted.
* @param cipherKey Cipher key to be used for encryption.
* @param cipherKey Cipher key to be used for encryption. Default is [PNConfiguration.cipherKey]
*
* @return String containing the encryption of `inputString` using `cipherKey`.
* @throws PubNubException Throws exception in case of failed encryption.
*/
fun encrypt(inputString: String, cipherKey: String): String =
Crypto(cipherKey).encrypt(inputString)
fun encrypt(inputString: String, cipherKey: String = configuration.cipherKey): String =
Crypto(cipherKey).encrypt(inputString, Base64.DEFAULT)

/**
* Perform Cryptographic encryption of an input stream using provided cipher key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal class UploadFile(
return
}
callback(
null,
Unit,
createStatusResponse(
PNStatusCategory.PNAcknowledgmentCategory, response,
null
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/pubnub/api/endpoints/pubsub/Publish.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,5 @@ class Publish internal constructor(
private fun encryptMessage(message: String): String =
Crypto(pubnub.configuration.cipherKey)
.encrypt(message)
.replace("\n", "")
// endregion
}
4 changes: 3 additions & 1 deletion src/main/kotlin/com/pubnub/api/managers/TelemetryManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class TelemetryManager {
type.queryParam?.let { queryParam: String ->
if (latency > 0) {
val storeDate = currentDate / (TIMESTAMP_DIVIDER.toDouble())
latencies.putIfAbsent(queryParam, mutableListOf())
if (latencies[queryParam] == null) {
latencies[queryParam] = ArrayList()
}

latencies[queryParam]?.let {
val latencyEntry = Latency(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.pubnub.api.models.server

import com.google.gson.JsonElement
import com.google.gson.annotations.SerializedName
import com.pubnub.api.workers.SubscribeMessageWorker.Companion.TYPE_FILES
import com.pubnub.api.workers.SubscribeMessageWorker.Companion.TYPE_MESSAGE

class SubscribeMessage(
@SerializedName("a")
Expand Down Expand Up @@ -39,5 +41,5 @@ class SubscribeMessage(

) {

fun supportsEncryption() = type == null || type == 0
fun supportsEncryption() = type in arrayOf(null, TYPE_MESSAGE, TYPE_FILES)
}
Loading

0 comments on commit 7e4c137

Please sign in to comment.