Skip to content

Commit 0f15940

Browse files
fix: remove Buffer from decrypt (pubnub#298)
* fix: remove Buffer from decrypt * PubNub SDK v7.2.1 release. * fix: fix signature in the test Co-authored-by: Client Engineering Bot <[email protected]>
1 parent be27b37 commit 0f15940

File tree

11 files changed

+75
-68
lines changed

11 files changed

+75
-68
lines changed

.pubnub.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
changelog:
3+
- date: 2022-11-10
4+
version: v7.2.1
5+
changes:
6+
- type: bug
7+
text: "Removes remains of Buffer from the crypto module."
38
- date: 2022-07-01
49
version: v7.2.0
510
changes:
@@ -874,7 +879,7 @@ sdks:
874879
- distribution-type: source
875880
distribution-repository: GitHub release
876881
package-name: pubnub.js
877-
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.2.0.zip
882+
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.2.1.zip
878883
requires:
879884
- name: 'agentkeepalive'
880885
min-version: '3.5.2'
@@ -1545,7 +1550,7 @@ sdks:
15451550
- distribution-type: library
15461551
distribution-repository: GitHub release
15471552
package-name: pubnub.js
1548-
location: https://github.com/pubnub/javascript/releases/download/v7.2.0/pubnub.7.2.0.js
1553+
location: https://github.com/pubnub/javascript/releases/download/v7.2.1/pubnub.7.2.1.js
15491554
requires:
15501555
- name: 'agentkeepalive'
15511556
min-version: '3.5.2'

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v7.2.1
2+
November 10 2022
3+
4+
#### Fixed
5+
- Removes remains of Buffer from the crypto module.
6+
17
## v7.2.0
28
July 01 2022
39

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2222
npm install pubnub
2323
```
2424
* or download one of our builds from our CDN:
25-
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.0.js
26-
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.0.min.js
25+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.1.js
26+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.2.1.min.js
2727
2828
2. Configure your keys:
2929

dist/web/pubnub.js

+49-51
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@
768768
return this;
769769
};
770770
default_1.prototype.getVersion = function () {
771-
return '7.2.0';
771+
return '7.2.1';
772772
};
773773
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
774774
this._PNSDKSuffix[name] = suffix;
@@ -780,6 +780,53 @@
780780
return default_1;
781781
}());
782782

783+
var BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
784+
/**
785+
* Decode a Base64 encoded string.
786+
*
787+
* @param paddedInput Base64 string with padding
788+
* @returns ArrayBuffer with decoded data
789+
*/
790+
function decode$1(paddedInput) {
791+
// Remove up to last two equal signs.
792+
var input = paddedInput.replace(/==?$/, '');
793+
var outputLength = Math.floor((input.length / 4) * 3);
794+
// Prepare output buffer.
795+
var data = new ArrayBuffer(outputLength);
796+
var view = new Uint8Array(data);
797+
var cursor = 0;
798+
/**
799+
* Returns the next integer representation of a sixtet of bytes from the input
800+
* @returns sixtet of bytes
801+
*/
802+
function nextSixtet() {
803+
var char = input.charAt(cursor++);
804+
var index = BASE64_CHARMAP.indexOf(char);
805+
if (index === -1) {
806+
throw new Error("Illegal character at ".concat(cursor, ": ").concat(input.charAt(cursor - 1)));
807+
}
808+
return index;
809+
}
810+
for (var i = 0; i < outputLength; i += 3) {
811+
// Obtain four sixtets
812+
var sx1 = nextSixtet();
813+
var sx2 = nextSixtet();
814+
var sx3 = nextSixtet();
815+
var sx4 = nextSixtet();
816+
// Encode them as three octets
817+
var oc1 = ((sx1 & 63) << 2) | (sx2 >> 4);
818+
var oc2 = ((sx2 & 15) << 4) | (sx3 >> 2);
819+
var oc3 = ((sx3 & 3) << 6) | (sx4 >> 0);
820+
view[i] = oc1;
821+
// Skip padding bytes.
822+
if (sx3 != 64)
823+
view[i + 1] = oc2;
824+
if (sx4 != 64)
825+
view[i + 2] = oc3;
826+
}
827+
return data;
828+
}
829+
783830
/*eslint-disable */
784831
/*
785832
CryptoJS v3.1.2
@@ -1467,12 +1514,10 @@
14671514
})();
14681515
var hmacSha256 = CryptoJS;
14691516

1470-
/* */
14711517
function bufferToWordArray(b) {
14721518
var wa = [];
14731519
var i;
14741520
for (i = 0; i < b.length; i += 1) {
1475-
// eslint-disable-next-line no-bitwise
14761521
wa[(i / 4) | 0] |= b[i] << (24 - 8 * i);
14771522
}
14781523
return hmacSha256.lib.WordArray.create(wa, b.length);
@@ -1585,7 +1630,7 @@
15851630
var mode = this._getMode(options);
15861631
var cipherKey = this._getPaddedKey(customCipherKey || this._config.cipherKey, options);
15871632
if (this._config.useRandomIVs) {
1588-
var ciphertext = Buffer.from(data, 'base64');
1633+
var ciphertext = new Uint8ClampedArray(decode$1(data));
15891634
var iv = bufferToWordArray(ciphertext.slice(0, 16));
15901635
var payload = bufferToWordArray(ciphertext.slice(16));
15911636
try {
@@ -7794,53 +7839,6 @@
77947839
return default_1;
77957840
}());
77967841

7797-
var BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
7798-
/**
7799-
* Decode a Base64 encoded string.
7800-
*
7801-
* @param paddedInput Base64 string with padding
7802-
* @returns ArrayBuffer with decoded data
7803-
*/
7804-
function decode$1(paddedInput) {
7805-
// Remove up to last two equal signs.
7806-
var input = paddedInput.replace(/==?$/, '');
7807-
var outputLength = Math.floor((input.length / 4) * 3);
7808-
// Prepare output buffer.
7809-
var data = new ArrayBuffer(outputLength);
7810-
var view = new Uint8Array(data);
7811-
var cursor = 0;
7812-
/**
7813-
* Returns the next integer representation of a sixtet of bytes from the input
7814-
* @returns sixtet of bytes
7815-
*/
7816-
function nextSixtet() {
7817-
var char = input.charAt(cursor++);
7818-
var index = BASE64_CHARMAP.indexOf(char);
7819-
if (index === -1) {
7820-
throw new Error("Illegal character at ".concat(cursor, ": ").concat(input.charAt(cursor - 1)));
7821-
}
7822-
return index;
7823-
}
7824-
for (var i = 0; i < outputLength; i += 3) {
7825-
// Obtain four sixtets
7826-
var sx1 = nextSixtet();
7827-
var sx2 = nextSixtet();
7828-
var sx3 = nextSixtet();
7829-
var sx4 = nextSixtet();
7830-
// Encode them as three octets
7831-
var oc1 = ((sx1 & 63) << 2) | (sx2 >> 4);
7832-
var oc2 = ((sx2 & 15) << 4) | (sx3 >> 2);
7833-
var oc3 = ((sx3 & 3) << 6) | (sx4 >> 0);
7834-
view[i] = oc1;
7835-
// Skip padding bytes.
7836-
if (sx3 != 64)
7837-
view[i + 1] = oc2;
7838-
if (sx4 != 64)
7839-
view[i + 2] = oc3;
7840-
}
7841-
return data;
7842-
}
7843-
78447842
function stringifyBufferKeys(obj) {
78457843
var isObject = function (value) { return value && typeof value === 'object' && value.constructor === Object; };
78467844
var isString = function (value) { return typeof value === 'string' || value instanceof String; };

dist/web/pubnub.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ var default_1 = /** @class */ (function () {
169169
return this;
170170
};
171171
default_1.prototype.getVersion = function () {
172-
return '7.2.0';
172+
return '7.2.1';
173173
};
174174
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
175175
this._PNSDKSuffix[name] = suffix;

lib/core/components/cryptography/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
"use strict";
2-
/* */
32
var __importDefault = (this && this.__importDefault) || function (mod) {
43
return (mod && mod.__esModule) ? mod : { "default": mod };
54
};
65
Object.defineProperty(exports, "__esModule", { value: true });
6+
var base64_codec_1 = require("../base64_codec");
77
var hmac_sha256_1 = __importDefault(require("./hmac-sha256"));
88
function bufferToWordArray(b) {
99
var wa = [];
1010
var i;
1111
for (i = 0; i < b.length; i += 1) {
12-
// eslint-disable-next-line no-bitwise
1312
wa[(i / 4) | 0] |= b[i] << (24 - 8 * i);
1413
}
1514
return hmac_sha256_1.default.lib.WordArray.create(wa, b.length);
@@ -122,7 +121,7 @@ var default_1 = /** @class */ (function () {
122121
var mode = this._getMode(options);
123122
var cipherKey = this._getPaddedKey(customCipherKey || this._config.cipherKey, options);
124123
if (this._config.useRandomIVs) {
125-
var ciphertext = Buffer.from(data, 'base64');
124+
var ciphertext = new Uint8ClampedArray((0, base64_codec_1.decode)(data));
126125
var iv = bufferToWordArray(ciphertext.slice(0, 16));
127126
var payload = bufferToWordArray(ciphertext.slice(16));
128127
try {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pubnub",
3-
"version": "7.2.0",
3+
"version": "7.2.1",
44
"author": "PubNub <[email protected]>",
55
"description": "Publish & Subscribe Real-time Messaging with PubNub",
66
"scripts": {

src/core/components/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export default class {
339339
}
340340

341341
getVersion() {
342-
return '7.2.0';
342+
return '7.2.1';
343343
}
344344

345345
_addPnsdkSuffix(name, suffix) {

src/core/components/cryptography/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
/* */
2-
3-
import Config from '../config';
1+
import { decode } from '../base64_codec';
42
import CryptoJS from './hmac-sha256';
53

64
function bufferToWordArray(b) {
75
const wa = [];
86
let i;
97
for (i = 0; i < b.length; i += 1) {
10-
// eslint-disable-next-line no-bitwise
118
wa[(i / 4) | 0] |= b[i] << (24 - 8 * i);
129
}
1310

@@ -148,7 +145,7 @@ export default class {
148145
const mode = this._getMode(options);
149146
const cipherKey = this._getPaddedKey(customCipherKey || this._config.cipherKey, options);
150147
if (this._config.useRandomIVs) {
151-
const ciphertext = Buffer.from(data, 'base64');
148+
const ciphertext = new Uint8ClampedArray(decode(data));
152149

153150
const iv = bufferToWordArray(ciphertext.slice(0, 16));
154151
const payload = bufferToWordArray(ciphertext.slice(16));

test/integration/endpoints/grant_token.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ describe('grant token endpoint', () => {
3030
autoNetworkDetection: false,
3131
});
3232

33+
pubnub._config.getVersion = () => 'testVersion';
34+
3335
if (originalVersionFunction === null) {
3436
originalVersionFunction = pubnub._config.getVersion;
3537
pubnub._config.getVersion = () => 'testVersion';
@@ -164,7 +166,7 @@ describe('grant token endpoint', () => {
164166
uuid: 'myUUID',
165167
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
166168
timestamp: 1571360790,
167-
signature: 'v2.IN5r_r8FO6LMAIOYQnk6Y13Tqfa9BsPC8QWDmqaR16w',
169+
signature: 'v2.A1ldFjcfAiD0rw7-kFKKwY5j0Mpq1R5u8JDeej7P3jo',
168170
})
169171
.reply(200, {
170172
message: 'Success',

0 commit comments

Comments
 (0)