move token and submit challenge call to onion request

pull/1383/head
Audric Ackermann 5 years ago
parent 22eebcd66d
commit 4c91d977ca
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -363,7 +363,7 @@ const serverRequest = async (endpoint, options = {}) => {
} = options; } = options;
const url = new URL(endpoint); const url = new URL(endpoint);
if (params) { if (!_.isEmpty(params)) {
url.search = new URLSearchParams(params); url.search = new URLSearchParams(params);
} }
const fetchOptions = {}; const fetchOptions = {};
@ -838,13 +838,13 @@ class LokiAppDotNetServerAPI {
async requestToken() { async requestToken() {
let res; let res;
try { try {
const url = new URL(`${this.baseServerUrl}/loki/v1/get_challenge`);
const params = { const params = {
pubKey: this.ourKey, pubKey: this.ourKey,
}; };
url.search = new URLSearchParams(params); res = await this.serverRequest('loki/v1/get_challenge', {
method: 'GET',
res = await this.proxyFetch(url); params,
});
} catch (e) { } catch (e) {
// should we retry here? // should we retry here?
// no, this is the low level function // no, this is the low level function
@ -873,37 +873,29 @@ class LokiAppDotNetServerAPI {
} }
return null; return null;
} }
if (!res.ok) { if (res.statusCode !== 200) {
log.error('requestToken request failed'); log.error('requestToken request failed');
return null; return null;
} }
const body = await res.json(); const body = res.response;
const token = await libloki.crypto.decryptToken(body); const token = await libloki.crypto.decryptToken(body);
return token; return token;
} }
// activate token // activate token
async submitToken(token) { async submitToken(token) {
const fetchOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
pubKey: this.ourKey,
token,
}),
};
try { try {
const res = await this.proxyFetch( const res = await this.serverRequest('loki/v1/submit_challenge', {
new URL(`${this.baseServerUrl}/loki/v1/submit_challenge`), method: 'POST',
fetchOptions, objBody: {
{ textResponse: true } pubKey: this.ourKey,
); token,
return res.ok; },
noJson: true,
});
return res.statusCode === 200;
} catch (e) { } catch (e) {
log.error('submitToken proxyFetch failure', e.code, e.message); log.error('submitToken serverRequest failure', e.code, e.message);
return false; return false;
} }
} }

@ -32,7 +32,7 @@ const validOpenGroupServer = async serverUrl => {
{ method: 'GET' }, { method: 'GET' },
{ noJson: true } { noJson: true }
); );
if (res.result.status === 200) { if (res.result && res.result.status === 200) {
log.info( log.info(
`loki_public_chat::validOpenGroupServer - onion routing enabled on ${url.toString()}` `loki_public_chat::validOpenGroupServer - onion routing enabled on ${url.toString()}`
); );

@ -450,7 +450,7 @@ window.lokiFeatureFlags = {
privateGroupChats: true, privateGroupChats: true,
useSnodeProxy: !process.env.USE_STUBBED_NETWORK, useSnodeProxy: !process.env.USE_STUBBED_NETWORK,
useOnionRequests: true, useOnionRequests: true,
useOnionRequestsV2: false, useOnionRequestsV2: true,
useFileOnionRequests: true, useFileOnionRequests: true,
enableSenderKeys: true, enableSenderKeys: true,
onionRequestHops: 3, onionRequestHops: 3,
@ -487,7 +487,6 @@ if (config.environment.includes('test-integration')) {
window.lokiFeatureFlags = { window.lokiFeatureFlags = {
multiDeviceUnpairing: true, multiDeviceUnpairing: true,
privateGroupChats: true, privateGroupChats: true,
useSnodeProxy: !process.env.USE_STUBBED_NETWORK,
useOnionRequests: false, useOnionRequests: false,
useFileOnionRequests: false, useFileOnionRequests: false,
debugMessageLogs: true, debugMessageLogs: true,

@ -17,7 +17,7 @@ async function lokiPlainFetch(
const { log } = window; const { log } = window;
if (url.match(/https:\/\//)) { if (url.match(/https:\/\//)) {
// import that this does not get set in sendToProxy fetchOptions // import that this does not get set in lokiFetch fetchOptions
fetchOptions.agent = snodeHttpsAgent; fetchOptions.agent = snodeHttpsAgent;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
} else { } else {

Loading…
Cancel
Save