Skip to content

feat(core): Add option to set a domain on an account #4168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/core/src/main/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export interface Account {

export type StoreEngineProvider = (storeName: string) => Promise<CRUDEngine>;

type AccountConfig = {
federationDomain?: string;
};

export class Account extends EventEmitter {
private readonly apiClient: APIClient;
private readonly logger: logdown.Logger;
Expand All @@ -118,7 +122,16 @@ export class Account extends EventEmitter {
user: UserService;
};

constructor(apiClient: APIClient = new APIClient(), storeEngineProvider?: StoreEngineProvider) {
/**
* @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
* @param storeEngineProvider Used to store info in the database (will create a inMemory engine if undefined)
* @param config.federationDomain If using a federated backend this will set the default domain for qualified ids. Do not set if using a regular backend
*/
constructor(
apiClient: APIClient = new APIClient(),
storeEngineProvider?: StoreEngineProvider,
private readonly config?: AccountConfig,
) {
super();
this.apiClient = apiClient;
if (storeEngineProvider) {
Expand Down Expand Up @@ -187,7 +200,7 @@ export class Account extends EventEmitter {
public async initServices(storeEngine: CRUDEngine): Promise<void> {
const accountService = new AccountService(this.apiClient);
const assetService = new AssetService(this.apiClient);
const cryptographyService = new CryptographyService(this.apiClient, storeEngine);
const cryptographyService = new CryptographyService(this.apiClient, storeEngine, this.config);

const clientService = new ClientService(this.apiClient, storeEngine, cryptographyService);
const connectionService = new ConnectionService(this.apiClient);
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/main/cryptography/CryptographyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,28 @@ export interface MetaClient extends RegisteredClient {
};
}

type CryptographyServiceOptions = {
federationDomain?: string;
};

export class CryptographyService {
private readonly logger: logdown.Logger;

public cryptobox: Cryptobox;
private readonly database: CryptographyDatabaseRepository;

constructor(readonly apiClient: APIClient, private readonly storeEngine: CRUDEngine) {
constructor(
readonly apiClient: APIClient,
private readonly storeEngine: CRUDEngine,
private readonly options?: CryptographyServiceOptions,
) {
this.cryptobox = new Cryptobox(this.storeEngine);
this.database = new CryptographyDatabaseRepository(this.storeEngine);
this.logger = logdown('@wireapp/core/cryptography/CryptographyService', {
logger: console,
markdown: false,
});
this.options = options;
}

public static constructSessionId(userId: string, clientId: string, domain: string | null): string {
Expand Down Expand Up @@ -209,7 +218,8 @@ export class CryptographyService {
data: {sender, text: cipherText},
} = otrMessage;

const sessionId = CryptographyService.constructSessionId(from, sender, qualified_from?.domain || null);
const domain = this.options?.federationDomain ? qualified_from?.domain || this.options.federationDomain : null;
const sessionId = CryptographyService.constructSessionId(from, sender, domain);
const decryptedMessage = await this.decrypt(sessionId, cipherText);
const genericMessage = GenericMessage.decode(decryptedMessage);

Expand Down