|
|
|
@ -32,7 +32,7 @@ import {
|
|
|
|
|
import { Snode } from '../../data/data';
|
|
|
|
|
import { updateIsOnline } from '../../state/ducks/onion';
|
|
|
|
|
import { ed25519Str } from '../onions/onionPath';
|
|
|
|
|
import { UserUtils, StringUtils } from '../utils';
|
|
|
|
|
import { StringUtils, UserUtils } from '../utils';
|
|
|
|
|
|
|
|
|
|
// ONS name can have [a-zA-Z0-9_-] except that - is not allowed as start or end
|
|
|
|
|
// do not define a regex but rather create it on the fly to avoid https://stackoverflow.com/questions/3891641/regex-test-only-works-every-other-time
|
|
|
|
@ -607,7 +607,8 @@ export async function retrieveNextMessages(
|
|
|
|
|
* @param snode Snode to send request to
|
|
|
|
|
* @returns timestamp of the response from snode
|
|
|
|
|
*/
|
|
|
|
|
const getNetworkTime = async (snode: Snode): Promise<string | number> => {
|
|
|
|
|
// tslint:disable-next-line: variable-name
|
|
|
|
|
export const TEST_getNetworkTime = async (snode: Snode): Promise<string | number> => {
|
|
|
|
|
const response: any = await snodeRpc('info', {}, snode);
|
|
|
|
|
const body = JSON.parse(response.body);
|
|
|
|
|
const timestamp = body?.timestamp;
|
|
|
|
@ -625,25 +626,26 @@ export const forceNetworkDeletion = async (): Promise<Array<string> | null> => {
|
|
|
|
|
const userED25519KeyPair = await UserUtils.getUserED25519KeyPair();
|
|
|
|
|
|
|
|
|
|
if (!userED25519KeyPair) {
|
|
|
|
|
window.log.warn('Cannot forceNetworkDeletion, did not find user ed25519 key.');
|
|
|
|
|
window?.log?.warn('Cannot forceNetworkDeletion, did not find user ed25519 key.');
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
const edKeyPriv = userED25519KeyPair.privKey;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const maliciousSnodes = await pRetry(async () => {
|
|
|
|
|
const maliciousSnodes = await pRetry(
|
|
|
|
|
async () => {
|
|
|
|
|
const userSwarm = await getSwarmFor(userX25519PublicKey);
|
|
|
|
|
const snodeToMakeRequestTo: Snode | undefined = _.sample(userSwarm);
|
|
|
|
|
const edKeyPrivBytes = fromHexToArray(edKeyPriv);
|
|
|
|
|
|
|
|
|
|
if (!snodeToMakeRequestTo) {
|
|
|
|
|
window.log.warn('Cannot forceNetworkDeletion, without a valid swarm node.');
|
|
|
|
|
window?.log?.warn('Cannot forceNetworkDeletion, without a valid swarm node.');
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pRetry(
|
|
|
|
|
async () => {
|
|
|
|
|
const timestamp = await getNetworkTime(snodeToMakeRequestTo);
|
|
|
|
|
const timestamp = await exports.TEST_getNetworkTime(snodeToMakeRequestTo);
|
|
|
|
|
|
|
|
|
|
const verificationData = StringUtils.encode(`delete_all${timestamp}`, 'utf8');
|
|
|
|
|
const message = new Uint8Array(verificationData);
|
|
|
|
@ -702,13 +704,13 @@ export const forceNetworkDeletion = async (): Promise<Array<string> | null> => {
|
|
|
|
|
const reason = snodeJson.reason;
|
|
|
|
|
const statusCode = snodeJson.code;
|
|
|
|
|
if (reason && statusCode) {
|
|
|
|
|
window.log.warn(
|
|
|
|
|
window?.log?.warn(
|
|
|
|
|
`Could not delete data from ${ed25519Str(
|
|
|
|
|
snodeToMakeRequestTo.pubkey_ed25519
|
|
|
|
|
)} due to error: ${reason}: ${statusCode}`
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
window.log.warn(
|
|
|
|
|
window?.log?.warn(
|
|
|
|
|
`Could not delete data from ${ed25519Str(
|
|
|
|
|
snodeToMakeRequestTo.pubkey_ed25519
|
|
|
|
|
)}`
|
|
|
|
@ -745,19 +747,32 @@ export const forceNetworkDeletion = async (): Promise<Array<string> | null> => {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
retries: 3,
|
|
|
|
|
minTimeout: 500,
|
|
|
|
|
minTimeout: exports.TEST_getMinTimeout(),
|
|
|
|
|
onFailedAttempt: e => {
|
|
|
|
|
window?.log?.warn(
|
|
|
|
|
`delete_all request attempt #${e.attemptNumber} failed. ${e.retriesLeft} retries left...`
|
|
|
|
|
`delete_all INNER request attempt #${e.attemptNumber} failed. ${e.retriesLeft} retries left...`
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
retries: 3,
|
|
|
|
|
minTimeout: exports.TEST_getMinTimeout(),
|
|
|
|
|
onFailedAttempt: e => {
|
|
|
|
|
window?.log?.warn(
|
|
|
|
|
`delete_all OUTER request attempt #${e.attemptNumber} failed. ${e.retriesLeft} retries left...`
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
return maliciousSnodes;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
window.log.warn('failed to delete everything on network:', e);
|
|
|
|
|
window?.log?.warn('failed to delete everything on network:', e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// tslint:disable-next-line: variable-name
|
|
|
|
|
export const TEST_getMinTimeout = () => 500;
|
|
|
|
|