Skip to content

Commit

Permalink
PubNub SDK v1.4.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Jul 23, 2020
1 parent 2e1d2d9 commit 16e91e6
Show file tree
Hide file tree
Showing 24 changed files with 1,108 additions and 45 deletions.
22 changes: 21 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
---
changelog:
-
changes:
-
text: "Add file apis to support file feature."
type: feature
-
text: "Add support for random initialization vector for messages and file."
type: improvement
date: Jul 23, 20
version: v1.4.0
-
changes:
-
Expand Down Expand Up @@ -161,6 +171,7 @@ features:
- PUBLISH-FIRE
- PUBLISH-REPLICATION-FLAG
- PUBLISH-MESSAGE-TTL
- PUBLISH-FILE-MESSAGE
push:
- PUSH-ADD-DEVICE-TO-CHANNELS
- PUSH-REMOVE-DEVICE-FROM-CHANNELS
Expand Down Expand Up @@ -206,12 +217,21 @@ features:
- OBJECTS-MANAGE-CHANNEL-MEMBERS-V2
- OBJECTS-FILTERING
- OBJECTS-SORTING
files:
- FILES-SEND-FILE
- FILES-LIST-FILES
- FILES-GET-FILE-URL
- FILES-DELETE-FILE
- FILES-DOWNLOAD-FILE
message-actions:
- MESSAGE-ACTIONS-GET
- MESSAGE-ACTIONS-ADD
- MESSAGE-ACTIONS-REMOVE
time:
- TIME-TIME
others:
- RANDOM-INITIALIZATION-VECTOR

name: dart
schema: 1
scm: github.com/pubnub/dart
Expand All @@ -222,4 +242,4 @@ supported-platforms:
platforms:
- "Dart SDK >=2.6.0 <3.0.0"
version: "PubNub Dart SDK"
version: "1.3.0"
version: "1.4.0"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [v1.4.0](https://github.com/pubnub/dart/releases/tag/v1.4.0)
July 23 2020

[Full Changelog](https://github.com/pubnub/dart/compare/v1.3.0...v1.4.0)

- 🌟️ Add file apis to support file feature.
- ⭐️️ Add support for random initialization vector for messages and file.

## [v1.3.0](https://github.com/pubnub/dart/releases/tag/v1.3.0)
June 25 2020

Expand Down
7 changes: 7 additions & 0 deletions lib/pubnub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export './src/dx/channel/channel.dart' show Channel;
export './src/dx/channel/channel_group.dart' show ChannelGroup;
export './src/dx/push/push.dart' show Device;
export './src/dx/_endpoints/publish.dart' show PublishResult;
export './src/dx/_endpoints/file.dart'
show
PublishFileMessageResult,
ListFilesResult,
DeleteFileResult,
DownloadFileResult;
export './src/dx/_endpoints/presence.dart'
show HeartbeatResult, LeaveResult, HereNowResult, StateInfo;
export './src/dx/_endpoints/channel_group.dart'
Expand Down Expand Up @@ -41,6 +47,7 @@ export './src/dx/subscribe/envelope.dart'
show Envelope, PresenceAction, PresenceEvent;
export './src/dx/channel/channel_history.dart'
show PaginatedChannelHistory, ChannelHistory;
export './src/dx/file/file.dart';
export './src/dx/channel/message.dart' show Message;

export './src/dx/_endpoints/objects/objects_types.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Core {
ParserModule parser;
CryptoModule crypto;

static String version = '1.3.0';
static String version = '1.4.0';

Core(
{Keyset defaultKeyset,
Expand Down
5 changes: 4 additions & 1 deletion lib/src/core/crypto/crypto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ class CryptoException extends PubNubException {

abstract class CryptoModule {
String encrypt(CipherKey key, String input);
String decrypt(CipherKey key, String input);
dynamic decrypt(CipherKey key, String input);

List<int> encryptFileData(CipherKey key, List<int> input);
List<int> decryptFileData(CipherKey key, List<int> input);
}
2 changes: 2 additions & 0 deletions lib/src/core/net/net.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export 'request_type.dart' show RequestType, RequestTypeExtension;

abstract class NetworkModule {
Future<RequestHandler> handle(Request request);

Future<RequestHandler> handleCustomRequest(Request request);
}
15 changes: 9 additions & 6 deletions lib/src/core/net/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typedef SignFunction = String Function(
String body);

class Request {
static Map<String, String> defualtQueryParameters = {
static Map<String, String> defaultQueryParameters = {
'pnsdk': 'PubNub-Dart/${Core.version}'
};
static final Map<String, String> defaultHeaders = {
Expand All @@ -21,17 +21,19 @@ class Request {

Map<String, String> queryParameters;
Map<String, String> headers;
String body;
dynamic body;
Uri url;

Request(this.type, this.pathSegments,
{Map<String, String> queryParameters,
Map<String, String> headers,
String body,
SignFunction signWith}) {
dynamic body,
SignFunction signWith,
this.url}) {
pathSegments = pathSegments;
this.queryParameters = {
...(queryParameters ?? {}),
...defualtQueryParameters
...defaultQueryParameters
};
this.headers = {...(headers ?? {}), ...defaultHeaders};
this.body = body;
Expand All @@ -49,8 +51,9 @@ class Request {
}

abstract class RequestHandler {
Future<String> text();
Future<dynamic> text();
Future<Map<String, List<String>>> headers();
Future<dynamic> response();

bool isCancelled;
void cancel([dynamic reason]);
Expand Down
70 changes: 57 additions & 13 deletions lib/src/crypto/crypto.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import 'package:encrypt/encrypt.dart' as crypto;
import 'package:crypto/crypto.dart' show sha256;
import 'dart:convert' show json, base64, utf8;
import 'dart:typed_data' show Uint8List;

import '../core/core.dart';
import 'encryption_mode.dart';

class CryptoConfiguration {
final EncryptionMode encryptionMode;
final bool encryptKey;
final bool useRandomInitializationVector;

const CryptoConfiguration({
this.encryptionMode = EncryptionMode.CBC,
this.encryptKey = true,
});
const CryptoConfiguration(
{this.encryptionMode = EncryptionMode.CBC,
this.encryptKey = true,
this.useRandomInitializationVector = false});
}

class PubNubCryptoModule implements CryptoModule {
Expand All @@ -29,36 +32,77 @@ class PubNubCryptoModule implements CryptoModule {
}

@override
String decrypt(CipherKey key, String input,
dynamic decrypt(CipherKey key, String input,
{CryptoConfiguration configuration}) {
var config = configuration ?? defaultConfiguration;

var encrypter = crypto.Encrypter(
crypto.AES(_getKey(key, config), mode: config.encryptionMode.value()));

var iv = crypto.IV.fromUtf8('0123456789012345');

try {
return encrypter.decrypt64(input, iv: iv);
if (config.useRandomInitializationVector) {
var data = base64.decode(input);
return utf8.decode(encrypter.decryptBytes(
crypto.Encrypted(Uint8List.fromList(data.sublist(16))),
iv: crypto.IV.fromBase64(base64.encode(data.sublist(0, 16)))));
} else {
var iv = crypto.IV.fromUtf8('0123456789012345');
return encrypter.decrypt64(input, iv: iv);
}
} catch (e) {
throw CryptoException('Error while decrypting message \n${e.message}');
}
}

@override
String encrypt(CipherKey key, String input,
String encrypt(CipherKey key, dynamic input,
{CryptoConfiguration configuration}) {
var config = configuration ?? defaultConfiguration;

var encrypter = crypto.Encrypter(
crypto.AES(_getKey(key, config), mode: config.encryptionMode.value()));
try {
if (config.useRandomInitializationVector) {
var iv = crypto.IV.fromSecureRandom(16);

var encrypted = encrypter.encrypt(input, iv: iv).bytes;
return base64.encode([...iv.bytes, ...encrypted]);
} else {
var iv = crypto.IV.fromUtf8('0123456789012345');
return encrypter.encrypt(input, iv: iv).base64;
}
} catch (e) {
throw CryptoException('Error while encrypting message \n${e.message}');
}
}

@override
List<int> decryptFileData(CipherKey key, List<int> input,
{CryptoConfiguration configuration}) {
var config = configuration ?? defaultConfiguration;
var encrypter = crypto.Encrypter(
crypto.AES(_getKey(key, config), mode: config.encryptionMode.value()));
try {
return encrypter.decryptBytes(
crypto.Encrypted(Uint8List.fromList(input.sublist(16))),
iv: crypto.IV.fromBase64(base64.encode(input.sublist(0, 16))));
} catch (e) {
throw CryptoException('Error while decrypting file data \n${e.message}');
}
}

var iv = crypto.IV.fromUtf8('0123456789012345');
@override
List<int> encryptFileData(CipherKey key, List<int> input,
{CryptoConfiguration configuration}) {
var iv = crypto.IV.fromSecureRandom(16);
var config = configuration ?? defaultConfiguration;
var encrypter = crypto.Encrypter(
crypto.AES(_getKey(key, config), mode: config.encryptionMode.value()));

try {
return encrypter.encrypt(input, iv: iv).base64;
var encrypted = encrypter.encryptBytes(input, iv: iv).bytes;
return [...iv.bytes, ...encrypted];
} catch (e) {
throw CryptoException('Error while encrypting message \n${e.message}');
throw CryptoException('Error while encrypting file data \n${e.message}');
}
}
}
6 changes: 6 additions & 0 deletions lib/src/default.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'dx/message_action/message_action.dart';
import 'dx/pam/pam.dart';
import 'dx/push/push.dart';
import 'dx/presence/presence.dart';
import 'dx/file/file.dart';
import 'dx/file/fileManager.dart';
import 'dx/objects/objects_types.dart';
import 'dx/objects/objects.dart';

Expand Down Expand Up @@ -56,6 +58,9 @@ class PubNub extends Core
/// UUID's membership and Channel's members
ObjectsDx objects;

/// [FileDx] contains that allow managing files
FileDx files;

/// Current version of this library.
static String version = Core.version;

Expand All @@ -72,6 +77,7 @@ class PubNub extends Core
batch = BatchDx(this);
channelGroups = ChannelGroupDx(this);
objects = ObjectsDx(this);
files = FileDx(this, PubNubFileManager());
}

/// Returns a representation of a channel.
Expand Down
Loading

0 comments on commit 16e91e6

Please sign in to comment.