mirror of
https://github.com/signalapp/libsignal.git
synced 2026-04-26 01:35:22 +02:00
Remove SVR3 bridge from all platforms
This commit is contained in:
@@ -21,9 +21,7 @@ import {
|
||||
Environment,
|
||||
Net,
|
||||
newNativeHandle,
|
||||
ServiceAuth,
|
||||
} from '../net';
|
||||
import { randomBytes } from 'crypto';
|
||||
import { ChatResponse } from '../../Native';
|
||||
import { CompletablePromise } from './util';
|
||||
import { fail } from 'assert';
|
||||
@@ -568,170 +566,3 @@ describe('cdsi lookup', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('SVR3', () => {
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
type State = {
|
||||
auth: ServiceAuth;
|
||||
net: Net;
|
||||
};
|
||||
let state: State | null;
|
||||
|
||||
function make_auth(): Readonly<ServiceAuth> {
|
||||
const USERNAME = randomBytes(16).toString('hex');
|
||||
const otp = Native.CreateOTPFromBase64(
|
||||
USERNAME,
|
||||
// Empty string is a valid base64 encoding
|
||||
process.env.LIBSIGNAL_TESTING_ENCLAVE_SECRET || ''
|
||||
);
|
||||
return { username: USERNAME, password: otp };
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
auth: make_auth(),
|
||||
net: new Net({
|
||||
env: Environment.Production,
|
||||
userAgent: userAgent,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
state = null;
|
||||
});
|
||||
|
||||
describe('Backup', () => {
|
||||
it('maxTries must be positive', () => {
|
||||
const secret = randomBytes(32);
|
||||
return expect(state!.net.svr3.backup(secret, 'password', 0, state!.auth))
|
||||
.to.eventually.be.rejected;
|
||||
});
|
||||
|
||||
it('Secret must be 32 bytes', () => {
|
||||
const secret = randomBytes(42);
|
||||
return expect(state!.net.svr3.backup(secret, 'password', 1, state!.auth))
|
||||
.to.eventually.be.rejected;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Restore', () => {
|
||||
it('Empty share set', () => {
|
||||
const shareSet = Buffer.alloc(0);
|
||||
return expect(
|
||||
state!.net.svr3.restore('password', shareSet, state!.auth)
|
||||
).to.eventually.be.rejectedWith(LibSignalErrorBase);
|
||||
});
|
||||
|
||||
it('Share set bad format', () => {
|
||||
const shareSet = Buffer.from([42]);
|
||||
return expect(
|
||||
state!.net.svr3.restore('password', shareSet, state!.auth)
|
||||
).to.eventually.be.rejectedWith(LibSignalErrorBase);
|
||||
});
|
||||
});
|
||||
|
||||
// Integration tests require access to the staging environment and make real
|
||||
// network calls and as such require the secret (and lacking the secret will
|
||||
// not be run).
|
||||
describe('Integration tests', function (this: Mocha.Suite) {
|
||||
before(() => {
|
||||
if (!process.env.LIBSIGNAL_TESTING_ENCLAVE_SECRET) {
|
||||
this.ctx.skip();
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await state!.net.svr3.remove(state!.auth);
|
||||
state = null;
|
||||
});
|
||||
|
||||
it('Backup and restore work in staging', async () => {
|
||||
const secret = randomBytes(32);
|
||||
const tries = 10;
|
||||
const shareSet = await state!.net.svr3.backup(
|
||||
secret,
|
||||
'password',
|
||||
tries,
|
||||
state!.auth
|
||||
);
|
||||
const restoredSecret = await state!.net.svr3.restore(
|
||||
'password',
|
||||
shareSet,
|
||||
state!.auth
|
||||
);
|
||||
expect(restoredSecret.value).to.eql(secret);
|
||||
expect(restoredSecret.triesRemaining).to.eql(tries - 1);
|
||||
}).timeout(10000);
|
||||
|
||||
it('Restore should fail after remove', async () => {
|
||||
const secret = randomBytes(32);
|
||||
const tries = 10;
|
||||
const shareSet = await state!.net.svr3.backup(
|
||||
secret,
|
||||
'password',
|
||||
tries,
|
||||
state!.auth
|
||||
);
|
||||
await state!.net.svr3.remove(state!.auth);
|
||||
return expect(state!.net.svr3.restore('password', shareSet, state!.auth))
|
||||
.to.eventually.be.rejectedWith(LibSignalErrorBase)
|
||||
.and.have.property('code', ErrorCode.SvrDataMissing);
|
||||
}).timeout(10000);
|
||||
|
||||
it('Remove non-existent data', async () => {
|
||||
return expect(state!.net.svr3.remove(state!.auth)).to.eventually.be
|
||||
.fulfilled;
|
||||
}).timeout(10000);
|
||||
|
||||
it('Restore with wrong password', async () => {
|
||||
const secret = randomBytes(32);
|
||||
const tries = 10;
|
||||
const shareSet = await state!.net.svr3.backup(
|
||||
secret,
|
||||
'password',
|
||||
tries,
|
||||
state!.auth
|
||||
);
|
||||
return expect(
|
||||
state!.net.svr3.restore('wrong password', shareSet, state!.auth)
|
||||
)
|
||||
.to.eventually.be.rejectedWith(LibSignalErrorBase)
|
||||
.and.include({
|
||||
code: ErrorCode.SvrRestoreFailed,
|
||||
triesRemaining: tries - 1,
|
||||
});
|
||||
}).timeout(10000);
|
||||
|
||||
it('Restore with corrupted share set', async () => {
|
||||
const secret = randomBytes(32);
|
||||
const shareSet = await state!.net.svr3.backup(
|
||||
secret,
|
||||
'password',
|
||||
10,
|
||||
state!.auth
|
||||
);
|
||||
// The first byte is the serialization format version, changing that
|
||||
// _will_ fail (checked in the other test). Changing the actual share set
|
||||
// value makes a more interesting test case.
|
||||
shareSet[1] ^= 0xff;
|
||||
return expect(
|
||||
state!.net.svr3.restore('password', shareSet, state!.auth)
|
||||
).to.eventually.be.rejectedWith(LibSignalErrorBase);
|
||||
}).timeout(10000);
|
||||
|
||||
it('Exceed maxTries', async () => {
|
||||
const secret = randomBytes(32);
|
||||
const shareSet = await state!.net.svr3.backup(
|
||||
secret,
|
||||
'password',
|
||||
1,
|
||||
state!.auth
|
||||
);
|
||||
await state!.net.svr3.restore('password', shareSet, state!.auth);
|
||||
return expect(state!.net.svr3.restore('password', shareSet, state!.auth))
|
||||
.to.eventually.be.rejectedWith(LibSignalErrorBase)
|
||||
.and.have.property('code', ErrorCode.SvrDataMissing);
|
||||
}).timeout(10000);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user