nodefetch headers as on mobile + cleanup worker code

pull/1783/head
Audric Ackermann 4 years ago
parent aead3d6510
commit 8760a59875
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -9,7 +9,6 @@ js/components.js
js/libtextsecure.js js/libtextsecure.js
js/libloki.js js/libloki.js
js/util_worker.js js/util_worker.js
js/libsignal-protocol-worker.js
libtextsecure/components.js libtextsecure/components.js
libloki/test/test.js libloki/test/test.js
libtextsecure/test/test.js libtextsecure/test/test.js
@ -18,7 +17,6 @@ test/test.js
# Third-party files # Third-party files
js/Mp3LameEncoder.min.js js/Mp3LameEncoder.min.js
js/WebAudioRecorderMp3.js js/WebAudioRecorderMp3.js
js/libsignal-protocol-worker.js
libtextsecure/libsignal-protocol.js libtextsecure/libsignal-protocol.js
libtextsecure/test/blanket_mocha.js libtextsecure/test/blanket_mocha.js
test/blanket_mocha.js test/blanket_mocha.js

@ -30,7 +30,6 @@ components/**
js/curve/** js/curve/**
js/Mp3LameEncoder.min.js js/Mp3LameEncoder.min.js
js/WebAudioRecorderMp3.js js/WebAudioRecorderMp3.js
js/libsignal-protocol-worker.js
libtextsecure/libsignal-protocol.js libtextsecure/libsignal-protocol.js
libtextsecure/test/blanket_mocha.js libtextsecure/test/blanket_mocha.js
test/blanket_mocha.js test/blanket_mocha.js

@ -31,6 +31,13 @@ module.exports = grunt => {
liblokicomponents.push(bower.concat.libloki[i]); liblokicomponents.push(bower.concat.libloki[i]);
} }
const utilWorkerComponents = [
'node_modules/bytebuffer/dist/bytebuffer.js',
'node_modules/libsodium/dist/modules/libsodium.js',
'node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js',
'js/util_worker_tasks.js',
];
grunt.loadNpmTasks('grunt-sass'); grunt.loadNpmTasks('grunt-sass');
grunt.initConfig({ grunt.initConfig({
@ -41,12 +48,7 @@ module.exports = grunt => {
dest: 'js/components.js', dest: 'js/components.js',
}, },
util_worker: { util_worker: {
src: [ src: utilWorkerComponents,
'node_modules/bytebuffer/dist/bytebuffer.js',
'components/JSBI/dist/jsbi.mjs',
'node_modules/long/dist/long.js',
'js/util_worker_tasks.js',
],
dest: 'js/util_worker.js', dest: 'js/util_worker.js',
}, },
libtextsecurecomponents: { libtextsecurecomponents: {
@ -61,7 +63,6 @@ module.exports = grunt => {
src: ['node_modules/mocha/mocha.js', 'node_modules/chai/chai.js', 'test/_test.js'], src: ['node_modules/mocha/mocha.js', 'node_modules/chai/chai.js', 'test/_test.js'],
dest: 'test/test.js', dest: 'test/test.js',
}, },
// TODO: Move errors back down?
libtextsecure: { libtextsecure: {
options: { options: {
banner: ';(function() {\n', banner: ';(function() {\n',
@ -119,12 +120,7 @@ module.exports = grunt => {
tasks: ['concat:libtextsecure'], tasks: ['concat:libtextsecure'],
}, },
utilworker: { utilworker: {
files: [ files: utilWorkerComponents,
'node_modules/bytebuffer/dist/bytebuffer.js',
'components/JSBI/dist/jsbi.mjs',
'node_modules/long/dist/long.js',
'js/util_worker_tasks.js',
],
tasks: ['concat:util_worker'], tasks: ['concat:util_worker'],
}, },
libloki: { libloki: {

@ -13,7 +13,7 @@
http-equiv="Content-Security-Policy" http-equiv="Content-Security-Policy"
content="default-src 'none'; content="default-src 'none';
child-src 'self'; child-src 'self';
connect-src 'self' https: wss: blob:; connect-src 'self' https: wss: blob: data:;
font-src 'self'; font-src 'self';
form-action 'self'; form-action 'self';
frame-src 'none'; frame-src 'none';

@ -37,8 +37,7 @@
"components/protobuf/**/*.js" "components/protobuf/**/*.js"
], ],
"libloki": [ "libloki": [
"node_modules/long/dist/long.js", "node_modules/long/dist/long.js"
"components/JSBI/dist/jsbi.mjs"
] ]
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -19,7 +19,6 @@ module.exports = {
encryptFile, encryptFile,
encryptSymmetric, encryptSymmetric,
fromEncodedBinaryToArrayBuffer, fromEncodedBinaryToArrayBuffer,
getAccessKeyVerifier,
getRandomBytes, getRandomBytes,
getViewOfArrayBuffer, getViewOfArrayBuffer,
getZeroes, getZeroes,
@ -29,7 +28,6 @@ module.exports = {
splitBytes, splitBytes,
stringFromBytes, stringFromBytes,
trimBytes, trimBytes,
verifyAccessKey,
}; };
function arrayBufferToBase64(arrayBuffer) { function arrayBufferToBase64(arrayBuffer) {
@ -101,23 +99,6 @@ async function deriveAccessKey(profileKey) {
return _getFirstBytes(accessKey, 16); return _getFirstBytes(accessKey, 16);
} }
async function getAccessKeyVerifier(accessKey) {
const plaintext = getZeroes(32);
const hmac = await hmacSha256(accessKey, plaintext);
return hmac;
}
async function verifyAccessKey(accessKey, theirVerifier) {
const ourVerifier = await getAccessKeyVerifier(accessKey);
if (constantTimeEqual(ourVerifier, theirVerifier)) {
return true;
}
return false;
}
const IV_LENGTH = 16; const IV_LENGTH = 16;
const MAC_LENGTH = 16; const MAC_LENGTH = 16;
const NONCE_LENGTH = 16; const NONCE_LENGTH = 16;

@ -1,9 +1,10 @@
/* global dcodeIO */ /* global dcodeIO, libsignal */
/* eslint-disable strict */ /* eslint-disable strict */
const functions = { const functions = {
arrayBufferToStringBase64, arrayBufferToStringBase64,
fromBase64ToArrayBuffer, fromBase64ToArrayBuffer,
verifySignature,
}; };
onmessage = async e => { onmessage = async e => {
@ -41,3 +42,35 @@ function arrayBufferToStringBase64(arrayBuffer) {
function fromBase64ToArrayBuffer(value) { function fromBase64ToArrayBuffer(value) {
return dcodeIO.ByteBuffer.wrap(value, 'base64').toArrayBuffer(); return dcodeIO.ByteBuffer.wrap(value, 'base64').toArrayBuffer();
} }
async function verifySignature(senderPubKey, messageData, signature) {
try {
console.warn('sodium', sodium);
console.warn('senderPubKey', senderPubKey);
console.warn('messageData', messageData);
console.warn('signature', signature);
let res = sodium.cr(key);
let [state_out, header] = [res.state, res.header];
let c1 = sodium.crypto_secretstream_xchacha20poly1305_push(
state_out,
sodium.from_string('message 1'),
null,
sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE
);
let c2 = sodium.crypto_secretstream_xchacha20poly1305_push(
state_out,
sodium.from_string('message 2'),
null,
sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL
);
const result = sodium.crypto_sign_verify_detached(signature, messageData, senderPubKey);
console.warn('sodium result', result);
// libsignal.Curve.async.verifySignature(senderPubKey, messageData, signature);
} catch (e) {
console.warn('verifySignature:', e);
return false;
}
}

@ -3,19 +3,6 @@
'use strict'; 'use strict';
describe('Crypto', () => { describe('Crypto', () => {
describe('accessKey/profileKey', () => {
it('verification roundtrips', async () => {
const profileKey = await Signal.Crypto.getRandomBytes(32);
const accessKey = await Signal.Crypto.deriveAccessKey(profileKey);
const verifier = await Signal.Crypto.getAccessKeyVerifier(accessKey);
const correct = await Signal.Crypto.verifyAccessKey(accessKey, verifier);
assert.strictEqual(correct, true);
});
});
describe('symmetric encryption', () => { describe('symmetric encryption', () => {
it('roundtrips', async () => { it('roundtrips', async () => {
const message = 'this is my message'; const message = 'this is my message';

@ -259,7 +259,11 @@ async function testGuardNode(snode: Snode) {
const fetchOptions = { const fetchOptions = {
method: 'POST', method: 'POST',
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' }, headers: {
'Content-Type': 'application/json',
'User-Agent': 'WhatsApp',
'Accept-Language': 'en-us',
},
timeout: 10000, // 10s, we want a smaller timeout for testing timeout: 10000, // 10s, we want a smaller timeout for testing
agent: snodeHttpsAgent, agent: snodeHttpsAgent,
}; };

@ -178,7 +178,7 @@ export const sendViaOnion = async (
}, },
{ {
retries: 4, // each path can fail 3 times before being dropped, we have 3 paths at most retries: 4, // each path can fail 3 times before being dropped, we have 3 paths at most
factor: 2, factor: 1,
minTimeout: 100, minTimeout: 100,
maxTimeout: 4000, maxTimeout: 4000,
onFailedAttempt: e => { onFailedAttempt: e => {

@ -146,7 +146,10 @@ export async function getSnodesFromSeedUrl(urlObj: URL): Promise<Array<any>> {
method: 'POST', method: 'POST',
timeout: 10000, timeout: 10000,
body: JSON.stringify(body), body: JSON.stringify(body),
headers: {
'User-Agent': 'WhatsApp',
'Accept-Language': 'en-us',
},
agent: sslAgent, agent: sslAgent,
}; };
window?.log?.info('insecureNodeFetch => plaintext for getSnodesFromSeedUrl'); window?.log?.info('insecureNodeFetch => plaintext for getSnodesFromSeedUrl');

@ -41,6 +41,12 @@ async function lokiFetch(
// import that this does not get set in lokiFetch fetchOptions // import that this does not get set in lokiFetch fetchOptions
fetchOptions.agent = snodeHttpsAgent; fetchOptions.agent = snodeHttpsAgent;
} }
(fetchOptions as any).headers = {
'User-Agent': 'WhatsApp',
'Accept-Language': 'en-us',
};
window?.log?.warn(`insecureNodeFetch => lokiFetch of ${url}`); window?.log?.warn(`insecureNodeFetch => lokiFetch of ${url}`);
const response = await insecureNodeFetch(url, fetchOptions); const response = await insecureNodeFetch(url, fetchOptions);

@ -798,7 +798,10 @@ const sendOnionRequest = async ({
body: payload, body: payload,
// we are talking to a snode... // we are talking to a snode...
agent: snodeHttpsAgent, agent: snodeHttpsAgent,
headers: {}, headers: {
'User-Agent': 'WhatsApp',
'Accept-Language': 'en-us',
},
timeout: 10000, timeout: 10000,
}; };

2
ts/window.d.ts vendored

@ -85,7 +85,7 @@ declare global {
globalOnlineStatus: boolean; globalOnlineStatus: boolean;
confirmationDialog: any; confirmationDialog: any;
callWorker: ( callWorker: (
fnName: 'arrayBufferToStringBase64' | 'fromBase64ToArrayBuffer', fnName: 'arrayBufferToStringBase64' | 'fromBase64ToArrayBuffer' | 'verifySignature',
...args ...args
) => Promise<any>; ) => Promise<any>;
} }

Loading…
Cancel
Save