Merge remote-tracking branch 'upstream/clearnet' into message-sending-refactor

This commit is contained in:
Audric Ackermann 2020-06-10 10:20:25 +10:00
commit f17ffd295a
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
13 changed files with 122 additions and 63 deletions

View file

@ -0,0 +1,42 @@
import { SignalService } from '../../protobuf';
import { CipherTextObject } from '../../../libtextsecure/libsignal-protocol';
export interface SecretSessionCipherConstructor {
new (storage: any): SecretSessionCipherInterface;
}
export interface SecretSessionCipherInterface {
encrypt(
destinationPubkey: string,
senderCertificate: SignalService.SenderCertificate,
innerEncryptedMessage: CipherTextObject
): Promise<ArrayBuffer>;
decrypt(
cipherText: ArrayBuffer,
me: { number: string; deviceId: number }
): Promise<{
isMe?: boolean;
sender: string;
content: ArrayBuffer;
type: SignalService.Envelope.Type;
}>;
}
export declare class SecretSessionCipher
implements SecretSessionCipherInterface {
constructor(storage: any);
public encrypt(
destinationPubkey: string,
senderCertificate: SignalService.SenderCertificate,
innerEncryptedMessage: CipherTextObject
): Promise<ArrayBuffer>;
public decrypt(
cipherText: ArrayBuffer,
me: { number: string; deviceId: number }
): Promise<{
isMe?: boolean;
sender: string;
content: ArrayBuffer;
type: SignalService.Envelope.Type;
}>;
}

9
js/modules/signal.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
import { SecretSessionCipherConstructor } from './metadata/SecretSessionCipher';
interface Metadata {
SecretSessionCipher: SecretSessionCipherConstructor;
}
export interface SignalInterface {
Metadata: Metadata;
}

View file

@ -7,15 +7,16 @@ export type CipherTextObject = {
body: BinaryString;
registrationId?: number;
};
export interface SignalProtocolAddressConstructor {
new (hexEncodedPublicKey: string, deviceId: number): SignalProtocolAddress;
fromString(encodedAddress: string): SignalProtocolAddress;
}
export declare class SignalProtocolAddress {
constructor(hexEncodedPublicKey: string, deviceId: number);
// tslint:disable-next-line: function-name
public static fromString(encodedAddress: string): SignalProtocolAddress;
public getName(): string;
public getDeviceId(): number;
public toString(): string;
public equals(other: SignalProtocolAddress): boolean;
export interface SignalProtocolAddress {
getName(): string;
getDeviceId(): number;
toString(): string;
equals(other: SignalProtocolAddress): boolean;
}
export type KeyPair = {
@ -99,29 +100,30 @@ export interface KeyHelperInterface {
}>;
}
export declare class SessionCipher {
constructor(storage: any, remoteAddress: SignalProtocolAddress);
export type SessionCipherConstructor = new (
storage: any,
remoteAddress: SignalProtocolAddress
) => SessionCipher;
export interface SessionCipher {
/**
* @returns The envelope type, registration id and binary encoded encrypted body.
*/
public encrypt(buffer: ArrayBuffer | Uint8Array): Promise<CipherTextObject>;
public decryptPreKeyWhisperMessage(
encrypt(buffer: ArrayBuffer | Uint8Array): Promise<CipherTextObject>;
decryptPreKeyWhisperMessage(
buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer>;
public decryptWhisperMessage(
buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer>;
public getRecord(encodedNumber: string): Promise<any | undefined>;
public getRemoteRegistrationId(): Promise<number>;
public hasOpenSession(): Promise<boolean>;
public closeOpenSessionForDevice(): Promise<void>;
public deleteAllSessionsForDevice(): Promise<void>;
decryptWhisperMessage(buffer: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
getRecord(encodedNumber: string): Promise<any | undefined>;
getRemoteRegistrationId(): Promise<number>;
hasOpenSession(): Promise<boolean>;
closeOpenSessionForDevice(): Promise<void>;
deleteAllSessionsForDevice(): Promise<void>;
}
export interface LibsignalProtocol {
SignalProtocolAddress: typeof SignalProtocolAddress;
SignalProtocolAddress: SignalProtocolAddressConstructor;
Curve: CurveInterface;
crypto: CryptoInterface;
KeyHelper: KeyHelperInterface;
SessionCipher: typeof SessionCipher;
SessionCipher: SessionCipherConstructor;
}

View file

@ -1,8 +1,8 @@
import { EncryptionType } from '../types/EncryptionType';
import { SignalService } from '../../protobuf';
import { libloki, libsignal, Signal, textsecure } from '../../window';
import { CipherTextObject } from '../../window/types/libsignal-protocol';
import { UserUtil } from '../../util';
import { CipherTextObject } from '../../../libtextsecure/libsignal-protocol';
export function padPlainTextBuffer(messageBuffer: Uint8Array): Uint8Array {
const plaintext = new Uint8Array(

View file

@ -67,7 +67,9 @@ export class SessionProtocol {
const pendingSend = SessionProtocol.pendingSendSessionsTimestamp.has(
pubkey.key
);
const hasSent = await SessionProtocol._hasSentSessionRequest(pubkey.key);
const hasSent = await SessionProtocol.hasAlreadySentSessionRequest(
pubkey.key
);
return pendingSend || hasSent;
}
@ -303,7 +305,7 @@ export class SessionProtocol {
);
}
private static async _hasSentSessionRequest(
private static async hasAlreadySentSessionRequest(
device: string
): Promise<boolean> {
await SessionProtocol.fetchFromDBIfNeeded();

View file

@ -1,4 +1,4 @@
import { CipherTextObject } from '../../../../window/types/libsignal-protocol';
import { CipherTextObject } from '../../../../../libtextsecure/libsignal-protocol';
import { SignalService } from '../../../../protobuf';
export class FallBackSessionCipherStub {

View file

@ -1,7 +1,8 @@
import { SignalService } from '../../../../protobuf';
import { CipherTextObject } from '../../../../window/types/libsignal-protocol';
import { CipherTextObject } from '../../../../../libtextsecure/libsignal-protocol';
import { SecretSessionCipherInterface } from '../../../../../js/modules/metadata/SecretSessionCipher';
export class SecretSessionCipherStub {
export class SecretSessionCipherStub implements SecretSessionCipherInterface {
public async encrypt(
_destinationPubkey: string,
_senderCertificate: SignalService.SenderCertificate,

View file

@ -1,7 +1,10 @@
import { CipherTextObject } from '../../../../window/types/libsignal-protocol';
import {
CipherTextObject,
SessionCipher,
} from '../../../../../libtextsecure/libsignal-protocol';
import { SignalService } from '../../../../protobuf';
export class SessionCipherStub {
export class SessionCipherStub implements SessionCipher {
public storage: any;
public address: any;
constructor(storage: any, address: any) {
@ -18,7 +21,35 @@ export class SessionCipherStub {
};
}
public async hasOpenSession(): Promise<Boolean> {
public async decryptPreKeyWhisperMessage(
buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer> {
throw new Error('Method not implemented.');
}
public async decryptWhisperMessage(
buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer> {
throw new Error('Method not implemented.');
}
public async getRecord(encodedNumber: string): Promise<any> {
throw new Error('Method not implemented.');
}
public async getRemoteRegistrationId(): Promise<number> {
throw new Error('Method not implemented.');
}
public async hasOpenSession(): Promise<boolean> {
return false;
}
public async closeOpenSessionForDevice(): Promise<void> {
throw new Error('Method not implemented.');
}
public async deleteAllSessionsForDevice(): Promise<void> {
throw new Error('Method not implemented.');
}
}

View file

@ -9,6 +9,7 @@
"max-func-body-length": false,
"no-unused-expression": false,
"no-unused-variable": false,
"await-promise": [true, "PromiseLike"],
"no-floating-promises": [true, "PromiseLike"]

View file

@ -1,5 +1,5 @@
import { getItemById } from '../../js/modules/data';
import { KeyPair } from '../window/types/libsignal-protocol';
import { KeyPair } from '../../libtextsecure/libsignal-protocol';
export async function getCurrentDevicePubKey(): Promise<string | undefined> {
const item = await getItemById('number_id');

View file

@ -1,8 +1,8 @@
import { LibsignalProtocol } from './types/libsignal-protocol';
import { SignalInterface } from './types/signal';
import { LocalizerType } from '../types/Util';
import LokiMessageAPI from '../../js/modules/loki_message_api';
import LokiPublicChatFactoryAPI from '../../js/modules/loki_public_chat_api';
import { LibsignalProtocol } from '../../libtextsecure/libsignal-protocol';
import { SignalInterface } from '../../js/modules/signal';
interface WindowInterface extends Window {
seedNodeList: any;

View file

@ -1,20 +0,0 @@
import { SignalService } from '../../protobuf';
import { CipherTextObject } from './libsignal-protocol';
export declare class SecretSessionCipher {
constructor(storage: any);
public encrypt(
destinationPubkey: string,
senderCertificate: SignalService.SenderCertificate,
innerEncryptedMessage: CipherTextObject
): Promise<ArrayBuffer>;
public decrypt(
cipherText: ArrayBuffer,
me: { number: string; deviceId: number }
): Promise<{
isMe?: boolean;
sender: string;
content: ArrayBuffer;
type: SignalService.Envelope.Type;
}>;
}

View file

@ -1,9 +0,0 @@
import { SecretSessionCipher } from './SecretSessionCipher';
interface Metadata {
SecretSessionCipher: typeof SecretSessionCipher;
}
export interface SignalInterface {
Metadata: Metadata;
}