Compute provisioning URL in separate function
This commit is contained in:
parent
6e2d0ff2ae
commit
eaf4036fc8
3 changed files with 45 additions and 7 deletions
23
ts/test-both/util/getProvisioningUrl_test.ts
Normal file
23
ts/test-both/util/getProvisioningUrl_test.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import { size } from '../../util/iterables';
|
||||||
|
|
||||||
|
import { getProvisioningUrl } from '../../util/getProvisioningUrl';
|
||||||
|
|
||||||
|
describe('getProvisioningUrl', () => {
|
||||||
|
it('returns a URL with a UUID and public key', () => {
|
||||||
|
const uuid = 'a08bf1fd-1799-427f-a551-70af747e3956';
|
||||||
|
const publicKey = new Uint8Array([9, 8, 7, 6, 5, 4, 3]);
|
||||||
|
|
||||||
|
const result = getProvisioningUrl(uuid, publicKey);
|
||||||
|
const resultUrl = new URL(result);
|
||||||
|
|
||||||
|
assert(result.startsWith('tsdevice:/?'));
|
||||||
|
assert.strictEqual(resultUrl.protocol, 'tsdevice:');
|
||||||
|
assert.strictEqual(size(resultUrl.searchParams.entries()), 2);
|
||||||
|
assert.strictEqual(resultUrl.searchParams.get('uuid'), uuid);
|
||||||
|
assert.strictEqual(resultUrl.searchParams.get('pub_key'), 'CQgHBgUEAw==');
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2020 Signal Messenger, LLC
|
// Copyright 2020-2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
@ -29,6 +29,7 @@ import {
|
||||||
} from '../Curve';
|
} from '../Curve';
|
||||||
import { isMoreRecentThan, isOlderThan } from '../util/timestamp';
|
import { isMoreRecentThan, isOlderThan } from '../util/timestamp';
|
||||||
import { ourProfileKeyService } from '../services/ourProfileKey';
|
import { ourProfileKeyService } from '../services/ourProfileKey';
|
||||||
|
import { getProvisioningUrl } from '../util/getProvisioningUrl';
|
||||||
|
|
||||||
const ARCHIVE_AGE = 30 * 24 * 60 * 60 * 1000;
|
const ARCHIVE_AGE = 30 * 24 * 60 * 60 * 1000;
|
||||||
const PREKEY_ROTATION_AGE = 24 * 60 * 60 * 1000;
|
const PREKEY_ROTATION_AGE = 24 * 60 * 60 * 1000;
|
||||||
|
@ -222,12 +223,11 @@ export default class AccountManager extends EventTarget {
|
||||||
const proto = window.textsecure.protobuf.ProvisioningUuid.decode(
|
const proto = window.textsecure.protobuf.ProvisioningUuid.decode(
|
||||||
request.body
|
request.body
|
||||||
);
|
);
|
||||||
const url = [
|
const { uuid } = proto;
|
||||||
'tsdevice:/?uuid=',
|
if (!uuid) {
|
||||||
proto.uuid,
|
throw new Error('registerSecondDevice: expected a UUID');
|
||||||
'&pub_key=',
|
}
|
||||||
encodeURIComponent(btoa(utils.getString(pubKey))),
|
const url = getProvisioningUrl(uuid, pubKey);
|
||||||
].join('');
|
|
||||||
|
|
||||||
if (window.CI) {
|
if (window.CI) {
|
||||||
window.CI.setProvisioningURL(url);
|
window.CI.setProvisioningURL(url);
|
||||||
|
|
15
ts/util/getProvisioningUrl.ts
Normal file
15
ts/util/getProvisioningUrl.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import { arrayBufferToBase64 } from '../Crypto';
|
||||||
|
|
||||||
|
export function getProvisioningUrl(
|
||||||
|
uuid: string,
|
||||||
|
publicKey: ArrayBuffer
|
||||||
|
): string {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
uuid,
|
||||||
|
pub_key: arrayBufferToBase64(publicKey),
|
||||||
|
});
|
||||||
|
return `tsdevice:/?${params.toString()}`;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue