@wireapp/core 42.11.0 → 42.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/lib/Account.d.ts +6 -2
  2. package/lib/Account.d.ts.map +1 -1
  3. package/lib/Account.js +32 -12
  4. package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
  5. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.d.ts +125 -0
  6. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.d.ts.map +1 -0
  7. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.js +157 -0
  8. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.types.d.ts +17 -0
  9. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.types.d.ts.map +1 -0
  10. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.types.js +20 -0
  11. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/index.d.ts +2 -0
  12. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/index.d.ts.map +1 -0
  13. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/index.js +35 -0
  14. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/schema.d.ts +306 -0
  15. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/schema.d.ts.map +1 -0
  16. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/schema.js +117 -0
  17. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/index.d.ts +2 -0
  18. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/index.d.ts.map +1 -0
  19. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/index.js +35 -0
  20. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.d.ts +43 -0
  21. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.d.ts.map +1 -0
  22. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.js +25 -0
  23. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.d.ts +17 -0
  24. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.d.ts.map +1 -0
  25. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.js +85 -0
  26. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts +24 -0
  27. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts.map +1 -0
  28. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.js +263 -0
  29. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.d.ts +12 -0
  30. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.d.ts.map +1 -0
  31. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.js +46 -0
  32. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Account.d.ts +12 -0
  33. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Account.d.ts.map +1 -0
  34. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Account.js +32 -0
  35. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.d.ts +15 -0
  36. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.d.ts.map +1 -0
  37. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.js +49 -0
  38. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Certificate.d.ts +14 -0
  39. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Certificate.d.ts.map +1 -0
  40. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Certificate.js +33 -0
  41. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/DpopChallenge.d.ts +12 -0
  42. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/DpopChallenge.d.ts.map +1 -0
  43. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/DpopChallenge.js +63 -0
  44. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/DpopChallenge.types.d.ts +20 -0
  45. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/DpopChallenge.types.d.ts.map +1 -0
  46. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/DpopChallenge.types.js +20 -0
  47. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/index.d.ts +2 -0
  48. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/index.d.ts.map +1 -0
  49. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/index.js +35 -0
  50. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/OidcChallenge.d.ts +28 -0
  51. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/OidcChallenge.d.ts.map +1 -0
  52. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/OidcChallenge.js +34 -0
  53. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Order.d.ts +28 -0
  54. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Order.d.ts.map +1 -0
  55. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Order.js +56 -0
  56. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.d.ts +28 -0
  57. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.d.ts.map +1 -0
  58. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.js +120 -0
  59. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.schema.d.ts +136 -0
  60. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.schema.d.ts.map +1 -0
  61. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.schema.js +49 -0
  62. package/lib/messagingProtocols/mls/E2EIdentityService/index.d.ts +4 -0
  63. package/lib/messagingProtocols/mls/E2EIdentityService/index.d.ts.map +1 -0
  64. package/lib/messagingProtocols/mls/E2EIdentityService/index.js +37 -0
  65. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +21 -6
  66. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
  67. package/lib/messagingProtocols/mls/MLSService/MLSService.js +81 -11
  68. package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +27 -10
  69. package/lib/messagingProtocols/mls/MLSService/MLSService.types.d.ts +4 -0
  70. package/lib/messagingProtocols/mls/MLSService/MLSService.types.d.ts.map +1 -1
  71. package/lib/messagingProtocols/mls/types.d.ts +1 -0
  72. package/lib/messagingProtocols/mls/types.d.ts.map +1 -1
  73. package/lib/util/LocalStorageStore/index.d.ts +7 -0
  74. package/lib/util/LocalStorageStore/index.d.ts.map +1 -0
  75. package/lib/util/LocalStorageStore/index.js +38 -0
  76. package/lib/util/TaskScheduler/TaskScheduler.store.d.ts +1 -1
  77. package/lib/util/TaskScheduler/TaskScheduler.store.d.ts.map +1 -1
  78. package/lib/util/TaskScheduler/TaskScheduler.store.js +3 -13
  79. package/lib/util/index.d.ts +1 -0
  80. package/lib/util/index.d.ts.map +1 -1
  81. package/lib/util/index.js +1 -0
  82. package/package.json +5 -4
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2023 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.E2EIServiceInternal = void 0;
25
+ const bazinga64_1 = require("bazinga64");
26
+ const logdown_1 = __importDefault(require("logdown"));
27
+ const AcmeServer_1 = require("./Connection/AcmeServer");
28
+ const E2EIService_types_1 = require("./E2EIService.types");
29
+ const Helper_1 = require("./Helper");
30
+ const Account_1 = require("./Steps/Account");
31
+ const Authorization_1 = require("./Steps/Authorization");
32
+ const Certificate_1 = require("./Steps/Certificate");
33
+ const DpopChallenge_1 = require("./Steps/DpopChallenge");
34
+ const OidcChallenge_1 = require("./Steps/OidcChallenge");
35
+ const Order_1 = require("./Steps/Order");
36
+ const E2EIStorage_1 = require("./Storage/E2EIStorage");
37
+ class E2EIServiceInternal {
38
+ constructor(coreCryptClient, apiClient, e2eiServiceExternal, keyPackagesAmount = 100) {
39
+ this.logger = (0, logdown_1.default)('@wireapp/core/E2EIdentityServiceInternal');
40
+ this.isInitialized = false;
41
+ this.coreCryptoClient = coreCryptClient;
42
+ this.apiClient = apiClient;
43
+ this.e2eServiceExternal = e2eiServiceExternal;
44
+ this.keyPackagesAmount = keyPackagesAmount;
45
+ this.logger.log('Instance of E2EIServiceInternal created');
46
+ }
47
+ // ############ Public Functions ############
48
+ static async getInstance(params) {
49
+ if (!E2EIServiceInternal.instance) {
50
+ if (!params) {
51
+ throw new Error('E2EIServiceInternal is not initialized. Please call getInstance with params.');
52
+ }
53
+ const { skipInit = false, coreCryptClient, apiClient, e2eiServiceExternal, keyPackagesAmount } = params;
54
+ E2EIServiceInternal.instance = new E2EIServiceInternal(coreCryptClient, apiClient, e2eiServiceExternal, keyPackagesAmount);
55
+ if (!skipInit) {
56
+ const { discoveryUrl, user, clientId } = params;
57
+ if (!discoveryUrl || !user || !clientId) {
58
+ throw new Error('discoveryUrl, user and clientId are required to initialize E2EIServiceInternal');
59
+ }
60
+ E2EIStorage_1.E2EIStorage.store.initialData({ discoveryUrl, user, clientId });
61
+ await E2EIServiceInternal.instance.init({ clientId, discoveryUrl, user });
62
+ }
63
+ }
64
+ return E2EIServiceInternal.instance;
65
+ }
66
+ async startCertificateProcess() {
67
+ // Step 0: Check if we have a handle in local storage
68
+ // If we don't have a handle, we need to start a new OAuth flow
69
+ try {
70
+ return this.startNewOAuthFlow();
71
+ }
72
+ catch (error) {
73
+ return this.exitWithError('Error while trying to start OAuth flow with error:', error);
74
+ }
75
+ }
76
+ async continueCertificateProcess(oAuthIdToken) {
77
+ // If we don't have a handle, we need to start a new OAuth flow
78
+ if (this.e2eServiceExternal.isEnrollmentInProgress()) {
79
+ try {
80
+ return this.continueOAuthFlow(oAuthIdToken);
81
+ }
82
+ catch (error) {
83
+ return this.exitWithError('Error while trying to continue OAuth flow with error:', error);
84
+ }
85
+ }
86
+ this.logger.error('Error while trying to continue OAuth flow. No handle found in local storage');
87
+ return undefined;
88
+ }
89
+ // ############ Internal Functions ############
90
+ exitWithError(message, error) {
91
+ this.logger.error(message, error);
92
+ return undefined;
93
+ }
94
+ async init(params) {
95
+ try {
96
+ const { user, clientId, discoveryUrl } = params;
97
+ if (!user || !clientId) {
98
+ this.logger.error('user and clientId are required to initialize E2eIdentityService');
99
+ throw new Error();
100
+ }
101
+ this.acmeService = new AcmeServer_1.AcmeService(discoveryUrl);
102
+ this.identity = await this.coreCryptoClient.e2eiNewActivationEnrollment((0, Helper_1.getE2EIClientId)(clientId, user.id, user.domain).asString, user.displayName, user.handle, 2, E2EIService_types_1.Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519);
103
+ this.isInitialized = true;
104
+ }
105
+ catch (error) {
106
+ this.logger.error('Error while trying to initialize E2eIdentityService', error);
107
+ throw error;
108
+ }
109
+ }
110
+ async getDirectory(identity, connection) {
111
+ try {
112
+ const directory = await connection.getDirectory();
113
+ if (directory) {
114
+ const parsedDirectory = identity.directoryResponse(directory);
115
+ return parsedDirectory;
116
+ }
117
+ }
118
+ catch (error) {
119
+ this.logger.error('Error while trying to receive a directory', error);
120
+ throw error;
121
+ }
122
+ return undefined;
123
+ }
124
+ async getInitialNonce(directory, connection) {
125
+ try {
126
+ const nonce = await connection.getInitialNonce(directory.newNonce);
127
+ if (nonce) {
128
+ return nonce;
129
+ }
130
+ throw new Error('No initial-nonce received');
131
+ }
132
+ catch (error) {
133
+ this.logger.error('Error while trying to receive a nonce', error);
134
+ throw error;
135
+ }
136
+ }
137
+ async startNewOAuthFlow() {
138
+ if (this.e2eServiceExternal.isEnrollmentInProgress()) {
139
+ return this.exitWithError('Error while trying to start OAuth flow. There is already a flow in progress');
140
+ }
141
+ if (!this.isInitialized || !this.identity || !this.acmeService) {
142
+ return this.exitWithError('Error while trying to start OAuth flow. E2eIdentityService is not fully initialized');
143
+ }
144
+ // Get the directory
145
+ const directory = await this.getDirectory(this.identity, this.acmeService);
146
+ if (!directory) {
147
+ return this.exitWithError('Error while trying to start OAuth flow. No directory received');
148
+ }
149
+ // Step 1: Get a new nonce from ACME server
150
+ const nonce = await this.getInitialNonce(directory, this.acmeService);
151
+ if (!nonce) {
152
+ return this.exitWithError('Error while trying to start OAuth flow. No nonce received');
153
+ }
154
+ // Step 2: Create a new account
155
+ const newAccountNonce = await (0, Account_1.createNewAccount)({
156
+ connection: this.acmeService,
157
+ directory,
158
+ identity: this.identity,
159
+ nonce,
160
+ });
161
+ // Step 3: Create a new order
162
+ const orderData = await (0, Order_1.createNewOrder)({
163
+ directory,
164
+ connection: this.acmeService,
165
+ identity: this.identity,
166
+ nonce: newAccountNonce,
167
+ });
168
+ // Step 4: Get authorization challenges
169
+ const authData = await (0, Authorization_1.getAuthorization)({
170
+ connection: this.acmeService,
171
+ identity: this.identity,
172
+ authzUrl: orderData.authzUrl,
173
+ nonce: orderData.nonce,
174
+ });
175
+ // Manual copy of the data because of a problem with copying the wasm object
176
+ // Step 6: Start E2E OAuth flow
177
+ const { authorization: { wireOidcChallenge }, } = authData;
178
+ if (wireOidcChallenge) {
179
+ // stash the identity for later use
180
+ const handle = await this.coreCryptoClient.e2eiEnrollmentStash(this.identity);
181
+ // stash the handle in local storage
182
+ E2EIStorage_1.E2EIStorage.store.handle(bazinga64_1.Encoder.toBase64(handle).asString);
183
+ E2EIStorage_1.E2EIStorage.store.authData(authData);
184
+ E2EIStorage_1.E2EIStorage.store.orderData({ orderUrl: orderData.orderUrl });
185
+ // we need to pass back the aquired wireOidcChallenge to the UI
186
+ return wireOidcChallenge;
187
+ }
188
+ return undefined;
189
+ }
190
+ async continueOAuthFlow(oAuthIdToken) {
191
+ // If we have a handle, the user has already started the process to authenticate with the OIDC provider. We can continue the flow.
192
+ try {
193
+ if (!this.acmeService) {
194
+ return this.exitWithError('Error while trying to continue OAuth flow. AcmeService is not initialized');
195
+ }
196
+ const handle = E2EIStorage_1.E2EIStorage.get.handle();
197
+ const authData = E2EIStorage_1.E2EIStorage.get.authData();
198
+ if (!authData.authorization.wireOidcChallenge) {
199
+ return this.exitWithError('Error while trying to continue OAuth flow. No wireOidcChallenge received');
200
+ }
201
+ this.identity = await this.coreCryptoClient.e2eiEnrollmentStashPop(bazinga64_1.Decoder.fromBase64(handle).asBytes);
202
+ this.logger.log('retrieved identity from stash');
203
+ // Step 7: Do OIDC client challenge
204
+ const oidcData = await (0, OidcChallenge_1.doWireOidcChallenge)({
205
+ oAuthIdToken,
206
+ authData,
207
+ connection: this.acmeService,
208
+ identity: this.identity,
209
+ nonce: authData.nonce,
210
+ });
211
+ this.logger.log('received oidcData', oidcData);
212
+ if (!oidcData.data.validated) {
213
+ return this.exitWithError('Error while trying to continue OAuth flow. OIDC challenge not validated');
214
+ }
215
+ const { user: wireUser, clientId } = E2EIStorage_1.E2EIStorage.get.initialData();
216
+ //Step 8: Do DPOP Challenge
217
+ const dpopData = await (0, DpopChallenge_1.doWireDpopChallenge)({
218
+ authData,
219
+ clientId,
220
+ connection: this.acmeService,
221
+ identity: this.identity,
222
+ userDomain: wireUser.domain,
223
+ apiClient: this.apiClient,
224
+ expirySecs: 30,
225
+ nonce: oidcData.nonce,
226
+ });
227
+ this.logger.log('acme dpopData', JSON.stringify(dpopData));
228
+ if (!(0, Helper_1.isResponseStatusValid)(dpopData.data.status)) {
229
+ return this.exitWithError('Error while trying to continue OAuth flow. DPOP challenge not validated');
230
+ }
231
+ //Step 9: Finalize Order
232
+ const orderData = E2EIStorage_1.E2EIStorage.get.orderData();
233
+ const finalizeOrderData = await (0, Order_1.finalizeOrder)({
234
+ connection: this.acmeService,
235
+ identity: this.identity,
236
+ nonce: dpopData.nonce,
237
+ orderUrl: orderData.orderUrl,
238
+ });
239
+ if (!finalizeOrderData.certificateUrl) {
240
+ return this.exitWithError('Error while trying to continue OAuth flow. No certificateUrl received');
241
+ }
242
+ // Step 9: Get certificate
243
+ const { certificate } = await (0, Certificate_1.getCertificate)({
244
+ certificateUrl: finalizeOrderData.certificateUrl,
245
+ nonce: finalizeOrderData.nonce,
246
+ connection: this.acmeService,
247
+ identity: this.identity,
248
+ });
249
+ if (!certificate) {
250
+ return this.exitWithError('Error while trying to continue OAuth flow. No certificate received');
251
+ }
252
+ E2EIStorage_1.E2EIStorage.store.certificate(certificate);
253
+ // Step 10: Initialize MLS with the certificate
254
+ // TODO: This is not working yet (since we initialize mls beforehand) and will be replaced by a new core-crypto function later on
255
+ return await this.coreCryptoClient.e2eiRotateAll(this.identity, certificate, this.keyPackagesAmount);
256
+ }
257
+ catch (error) {
258
+ this.logger.error('Error while trying to continue OAuth flow', error);
259
+ throw error;
260
+ }
261
+ }
262
+ }
263
+ exports.E2EIServiceInternal = E2EIServiceInternal;
@@ -0,0 +1,12 @@
1
+ import { EncodedData } from 'bazinga64';
2
+ export declare const jsonToByteArray: (data: any) => Uint8Array;
3
+ export declare const uuidTobase64url: (uuid: string) => EncodedData;
4
+ type E2EIClientId = `${string}:${string}@${string}`;
5
+ type GetE2EIClientIdReturnType = {
6
+ asString: E2EIClientId;
7
+ asBytes: Uint8Array;
8
+ };
9
+ export declare const getE2EIClientId: (clientId: string, userId: string, userDomain: string) => GetE2EIClientIdReturnType;
10
+ export declare const isResponseStatusValid: (status: string | undefined) => boolean | "" | undefined;
11
+ export {};
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/mls/E2EIdentityService/Helper/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAY,WAAW,EAAU,MAAM,WAAW,CAAC;AAE1D,eAAO,MAAM,eAAe,SAAU,GAAG,KAAG,UAG3C,CAAC;AAEF,eAAO,MAAM,eAAe,SAAU,MAAM,KAAG,WAO9C,CAAC;AAEF,KAAK,YAAY,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AACpD,KAAK,yBAAyB,GAAG;IAC/B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AACF,eAAO,MAAM,eAAe,aAAc,MAAM,UAAU,MAAM,cAAc,MAAM,KAAG,yBAOtF,CAAC;AAEF,eAAO,MAAM,qBAAqB,WAAY,MAAM,GAAG,SAAS,6BAAiC,CAAC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2023 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.isResponseStatusValid = exports.getE2EIClientId = exports.uuidTobase64url = exports.jsonToByteArray = void 0;
22
+ const bazinga64_1 = require("bazinga64");
23
+ const jsonToByteArray = (data) => {
24
+ const encoder = new TextEncoder();
25
+ return encoder.encode(JSON.stringify(data, null, 0));
26
+ };
27
+ exports.jsonToByteArray = jsonToByteArray;
28
+ const uuidTobase64url = (uuid) => {
29
+ const noDashes = uuid.replace(/-/g, '');
30
+ if (noDashes.length !== 32) {
31
+ throw new Error('Invalid UUID');
32
+ }
33
+ return bazinga64_1.Encoder.toBase64Url(bazinga64_1.Converter.hexStringToArrayBufferView(noDashes));
34
+ };
35
+ exports.uuidTobase64url = uuidTobase64url;
36
+ const getE2EIClientId = (clientId, userId, userDomain) => {
37
+ const asString = `${(0, exports.uuidTobase64url)(userId).asString}:${clientId}@${userDomain}`;
38
+ const asBytes = new TextEncoder().encode(asString);
39
+ return {
40
+ asString,
41
+ asBytes,
42
+ };
43
+ };
44
+ exports.getE2EIClientId = getE2EIClientId;
45
+ const isResponseStatusValid = (status) => status && status === 'valid';
46
+ exports.isResponseStatusValid = isResponseStatusValid;
@@ -0,0 +1,12 @@
1
+ import { AcmeService } from '../Connection/AcmeServer';
2
+ import { AcmeDirectory, E2eiEnrollment, Nonce } from '../E2EIService.types';
3
+ type CreateNewAccountParams = {
4
+ nonce: Nonce;
5
+ identity: E2eiEnrollment;
6
+ connection: AcmeService;
7
+ directory: AcmeDirectory;
8
+ };
9
+ type CreateNewAccountReturnValue = Promise<Nonce>;
10
+ export declare const createNewAccount: ({ nonce, connection, directory, identity, }: CreateNewAccountParams) => CreateNewAccountReturnValue;
11
+ export {};
12
+ //# sourceMappingURL=Account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/mls/E2EIdentityService/Steps/Account.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,KAAK,EAAC,MAAM,sBAAsB,CAAC;AAG1E,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,WAAW,CAAC;IACxB,SAAS,EAAE,aAAa,CAAC;CAC1B,CAAC;AACF,KAAK,2BAA2B,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAElD,eAAO,MAAM,gBAAgB,gDAK1B,sBAAsB,gCAUxB,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2023 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.createNewAccount = void 0;
22
+ const Helper_1 = require("../Helper");
23
+ const createNewAccount = async ({ nonce, connection, directory, identity, }) => {
24
+ const reqBody = identity.newAccountRequest(nonce);
25
+ const response = await connection.createNewAccount(directory.newAccount, reqBody);
26
+ if ((response === null || response === void 0 ? void 0 : response.data) && !!response.data.status.length && !!response.nonce.length) {
27
+ identity.newAccountResponse((0, Helper_1.jsonToByteArray)(response.data));
28
+ return response.nonce;
29
+ }
30
+ throw new Error('No account-data received');
31
+ };
32
+ exports.createNewAccount = createNewAccount;
@@ -0,0 +1,15 @@
1
+ import { AcmeService } from '../Connection';
2
+ import { E2eiEnrollment, NewAcmeAuthz, Nonce } from '../E2EIService.types';
3
+ interface GetAuthorizationParams {
4
+ nonce: Nonce;
5
+ authzUrl: string;
6
+ identity: E2eiEnrollment;
7
+ connection: AcmeService;
8
+ }
9
+ export type GetAuthorizationReturnValue = {
10
+ authorization: NewAcmeAuthz;
11
+ nonce: Nonce;
12
+ };
13
+ export declare const getAuthorization: ({ authzUrl, nonce, identity, connection, }: GetAuthorizationParams) => Promise<GetAuthorizationReturnValue>;
14
+ export {};
15
+ //# sourceMappingURL=Authorization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Authorization.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAE,YAAY,EAAE,KAAK,EAAC,MAAM,sBAAsB,CAAC;AAGzE,UAAU,sBAAsB;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,WAAW,CAAC;CACzB;AACD,MAAM,MAAM,2BAA2B,GAAG;IAAC,aAAa,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAC,CAAC;AAEtF,eAAO,MAAM,gBAAgB,+CAK1B,sBAAsB,KAAG,QAAQ,2BAA2B,CA2B9D,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2023 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.getAuthorization = void 0;
22
+ const Helper_1 = require("../Helper");
23
+ const getAuthorization = async ({ authzUrl, nonce, identity, connection, }) => {
24
+ const reqBody = identity.newAuthzRequest(authzUrl, nonce);
25
+ const response = await connection.getAuthorization(authzUrl, reqBody);
26
+ if ((response === null || response === void 0 ? void 0 : response.data) && !!response.data.status.length && !!response.nonce.length) {
27
+ const wasmData = identity.newAuthzResponse((0, Helper_1.jsonToByteArray)(response.data));
28
+ // manual copy of the wasm data because of a problem while cloning it
29
+ const authorization = {
30
+ identifier: wasmData.identifier,
31
+ wireDpopChallenge: {
32
+ delegate: wasmData.wireDpopChallenge.delegate,
33
+ target: wasmData.wireDpopChallenge.target,
34
+ url: wasmData.wireDpopChallenge.url,
35
+ },
36
+ wireOidcChallenge: {
37
+ delegate: wasmData.wireOidcChallenge.delegate,
38
+ target: wasmData.wireOidcChallenge.target,
39
+ url: wasmData.wireOidcChallenge.url,
40
+ },
41
+ };
42
+ return {
43
+ authorization,
44
+ nonce: response.nonce,
45
+ };
46
+ }
47
+ throw new Error('No authorization-data received');
48
+ };
49
+ exports.getAuthorization = getAuthorization;
@@ -0,0 +1,14 @@
1
+ import { AcmeService } from '../Connection';
2
+ import { E2eiEnrollment, Nonce } from '../E2EIService.types';
3
+ interface GetCertificateParams {
4
+ identity: E2eiEnrollment;
5
+ connection: AcmeService;
6
+ nonce: Nonce;
7
+ certificateUrl: string;
8
+ }
9
+ export declare const getCertificate: ({ certificateUrl, connection, identity, nonce }: GetCertificateParams) => Promise<{
10
+ certificate: string;
11
+ nonce: string;
12
+ }>;
13
+ export {};
14
+ //# sourceMappingURL=Certificate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Certificate.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/mls/E2EIdentityService/Steps/Certificate.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAE,KAAK,EAAC,MAAM,sBAAsB,CAAC;AAE3D,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,WAAW,CAAC;IACxB,KAAK,EAAE,KAAK,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;CACxB;AACD,eAAO,MAAM,cAAc,oDAAyD,oBAAoB;;;EAavG,CAAC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2023 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.getCertificate = void 0;
22
+ const getCertificate = async ({ certificateUrl, connection, identity, nonce }) => {
23
+ const reqBody = identity.certificateRequest(nonce);
24
+ const certificateResponse = await connection.getCertificate(certificateUrl, reqBody);
25
+ if (certificateResponse === null || certificateResponse === void 0 ? void 0 : certificateResponse.data) {
26
+ return {
27
+ certificate: certificateResponse.data,
28
+ nonce: certificateResponse.nonce,
29
+ };
30
+ }
31
+ throw new Error('No certificate received');
32
+ };
33
+ exports.getCertificate = getCertificate;
@@ -0,0 +1,12 @@
1
+ import { DoWireDpopChallengeParams } from './DpopChallenge.types';
2
+ export declare const doWireDpopChallenge: ({ apiClient, clientId, authData, identity, nonce, connection, expirySecs, userDomain, }: DoWireDpopChallengeParams) => Promise<{
3
+ data: {
4
+ type: string;
5
+ url: string;
6
+ status: string;
7
+ token: string;
8
+ };
9
+ nonce: string;
10
+ location?: string | undefined;
11
+ }>;
12
+ //# sourceMappingURL=DpopChallenge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DpopChallenge.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/DpopChallenge.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,yBAAyB,EAAmD,MAAM,uBAAuB,CAAC;AA6BlH,eAAO,MAAM,mBAAmB,4FAS7B,yBAAyB;;;;;;;;;EA4B3B,CAAC"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2023 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.doWireDpopChallenge = void 0;
22
+ const getClientNonce = async ({ apiClient, clientId }) => {
23
+ try {
24
+ const nonce = await apiClient.api.client.getNonce(clientId);
25
+ if (nonce) {
26
+ return nonce;
27
+ }
28
+ throw new Error('No client-nonce received');
29
+ }
30
+ catch (e) {
31
+ throw new Error(`Error while trying to receive a nonce with cause: ${e}`);
32
+ }
33
+ };
34
+ const getClientAccessToken = async ({ apiClient, clientNonce, identity, clientId, expirySecs, }) => {
35
+ const dpopToken = identity.createDpopToken(expirySecs, clientNonce);
36
+ // Remove this when the server is ready to accept the token
37
+ await new Promise(resolve => setTimeout(resolve, 2000));
38
+ return await apiClient.api.client.getAccessToken(clientId, dpopToken);
39
+ };
40
+ const doWireDpopChallenge = async ({ apiClient, clientId, authData, identity, nonce, connection, expirySecs, userDomain, }) => {
41
+ const { wireDpopChallenge } = authData.authorization;
42
+ if (!wireDpopChallenge) {
43
+ throw new Error('No wireDpopChallenge defined');
44
+ }
45
+ const clientNonce = await getClientNonce({ clientId, apiClient });
46
+ // We need to wait for the server to be ready to accept the token, there are some issues with the timing
47
+ await new Promise(resolve => setTimeout(resolve, 1000));
48
+ const clientAccessTokenData = await getClientAccessToken({
49
+ apiClient,
50
+ clientId,
51
+ clientNonce,
52
+ identity,
53
+ expirySecs,
54
+ userDomain,
55
+ });
56
+ const reqBody = identity.newDpopChallengeRequest(clientAccessTokenData.token, nonce);
57
+ const dpopChallengeResponse = await connection.validateDpopChallenge(wireDpopChallenge.url, reqBody);
58
+ if (!dpopChallengeResponse) {
59
+ throw new Error('No response received while validating DPOP challenge');
60
+ }
61
+ return dpopChallengeResponse;
62
+ };
63
+ exports.doWireDpopChallenge = doWireDpopChallenge;
@@ -0,0 +1,20 @@
1
+ import { APIClient } from '@wireapp/api-client';
2
+ import { ClientId } from '../../../types';
3
+ import { AcmeService } from '../../Connection/AcmeServer';
4
+ import { E2eiEnrollment, Nonce, User } from '../../E2EIService.types';
5
+ import { GetAuthorizationReturnValue } from '../Authorization';
6
+ export interface DoWireDpopChallengeParams {
7
+ apiClient: APIClient;
8
+ clientId: ClientId;
9
+ userDomain: User['domain'];
10
+ authData: GetAuthorizationReturnValue;
11
+ identity: E2eiEnrollment;
12
+ connection: AcmeService;
13
+ nonce: Nonce;
14
+ expirySecs: number;
15
+ }
16
+ export type GetClientNonceParams = Pick<DoWireDpopChallengeParams, 'clientId' | 'apiClient'>;
17
+ export type GetClientAccessTokenParams = Pick<DoWireDpopChallengeParams, 'clientId' | 'apiClient' | 'identity' | 'expirySecs' | 'userDomain'> & {
18
+ clientNonce: Nonce;
19
+ };
20
+ //# sourceMappingURL=DpopChallenge.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DpopChallenge.types.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/DpopChallenge.types.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,cAAc,EAAE,KAAK,EAAE,IAAI,EAAC,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAC,2BAA2B,EAAC,MAAM,kBAAkB,CAAC;AAE7D,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3B,QAAQ,EAAE,2BAA2B,CAAC;IACtC,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,WAAW,CAAC;IACxB,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,EAAE,UAAU,GAAG,WAAW,CAAC,CAAC;AAE7F,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAC3C,yBAAyB,EACzB,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,CACpE,GAAG;IACF,WAAW,EAAE,KAAK,CAAC;CACpB,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2023 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from './DpopChallenge';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/mls/E2EIdentityService/Steps/DpopChallenge/index.ts"],"names":[],"mappings":"AAmBA,cAAc,iBAAiB,CAAC"}