@@ -14,31 +14,17 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import { IRoomKeyRequestBody , IRoomKeyRequestRecipient } from "../index.ts" ;
18
- import { RoomKeyRequestState } from "../OutgoingRoomKeyRequestManager.ts" ;
19
- import { IOlmDevice } from "../algorithms/megolm.ts" ;
20
- import { TrackingStatus } from "../DeviceList.ts" ;
21
- import { IRoomEncryption } from "../RoomList.ts" ;
22
- import { IDevice } from "../deviceinfo.ts" ;
23
- import { ICrossSigningInfo } from "../CrossSigning.ts" ;
24
17
import { Logger } from "../../logger.ts" ;
25
- import { InboundGroupSessionData } from "../OlmDevice.ts" ;
26
18
import { MatrixEvent } from "../../models/event.ts" ;
27
- import { DehydrationManager } from "../dehydration.ts" ;
28
19
import { CrossSigningKeyInfo } from "../../crypto-api/index.ts" ;
29
20
import { AESEncryptedSecretStoragePayload } from "../../@types/AESEncryptedSecretStoragePayload.ts" ;
21
+ import { ISignatures } from "../../@types/signed.ts" ;
30
22
31
23
/**
32
24
* Internal module. Definitions for storage for the crypto module
33
25
*/
34
26
35
27
export interface SecretStorePrivateKeys {
36
- "dehydration" : {
37
- keyInfo : DehydrationManager [ "keyInfo" ] ;
38
- key : AESEncryptedSecretStoragePayload ;
39
- deviceDisplayName : string ;
40
- time : number ;
41
- } | null ;
42
28
"m.megolm_backup.v1" : AESEncryptedSecretStoragePayload ;
43
29
}
44
30
@@ -81,37 +67,14 @@ export interface CryptoStore {
81
67
*/
82
68
setMigrationState ( migrationState : MigrationState ) : Promise < void > ;
83
69
84
- getOrAddOutgoingRoomKeyRequest ( request : OutgoingRoomKeyRequest ) : Promise < OutgoingRoomKeyRequest > ;
85
- getOutgoingRoomKeyRequest ( requestBody : IRoomKeyRequestBody ) : Promise < OutgoingRoomKeyRequest | null > ;
86
- getOutgoingRoomKeyRequestByState ( wantedStates : number [ ] ) : Promise < OutgoingRoomKeyRequest | null > ;
87
- getAllOutgoingRoomKeyRequestsByState ( wantedState : number ) : Promise < OutgoingRoomKeyRequest [ ] > ;
88
- getOutgoingRoomKeyRequestsByTarget (
89
- userId : string ,
90
- deviceId : string ,
91
- wantedStates : number [ ] ,
92
- ) : Promise < OutgoingRoomKeyRequest [ ] > ;
93
- updateOutgoingRoomKeyRequest (
94
- requestId : string ,
95
- expectedState : number ,
96
- updates : Partial < OutgoingRoomKeyRequest > ,
97
- ) : Promise < OutgoingRoomKeyRequest | null > ;
98
- deleteOutgoingRoomKeyRequest ( requestId : string , expectedState : number ) : Promise < OutgoingRoomKeyRequest | null > ;
99
-
100
70
// Olm Account
101
71
getAccount ( txn : unknown , func : ( accountPickle : string | null ) => void ) : void ;
102
- storeAccount ( txn : unknown , accountPickle : string ) : void ;
103
72
getCrossSigningKeys ( txn : unknown , func : ( keys : Record < string , CrossSigningKeyInfo > | null ) => void ) : void ;
104
73
getSecretStorePrivateKey < K extends keyof SecretStorePrivateKeys > (
105
74
txn : unknown ,
106
75
func : ( key : SecretStorePrivateKeys [ K ] | null ) => void ,
107
76
type : K ,
108
77
) : void ;
109
- storeCrossSigningKeys ( txn : unknown , keys : Record < string , CrossSigningKeyInfo > ) : void ;
110
- storeSecretStorePrivateKey < K extends keyof SecretStorePrivateKeys > (
111
- txn : unknown ,
112
- type : K ,
113
- key : SecretStorePrivateKeys [ K ] ,
114
- ) : void ;
115
78
116
79
// Olm Sessions
117
80
countEndToEndSessions ( txn : unknown , func : ( count : number ) => void ) : void ;
@@ -126,11 +89,6 @@ export interface CryptoStore {
126
89
txn : unknown ,
127
90
func : ( sessions : { [ sessionId : string ] : ISessionInfo } ) => void ,
128
91
) : void ;
129
- getAllEndToEndSessions ( txn : unknown , func : ( session : ISessionInfo | null ) => void ) : void ;
130
- storeEndToEndSession ( deviceKey : string , sessionId : string , sessionInfo : ISessionInfo , txn : unknown ) : void ;
131
- storeEndToEndSessionProblem ( deviceKey : string , type : string , fixed : boolean ) : Promise < void > ;
132
- getEndToEndSessionProblem ( deviceKey : string , timestamp : number ) : Promise < IProblem | null > ;
133
- filterOutNotifiedErrorDevices ( devices : IOlmDevice [ ] ) : Promise < IOlmDevice [ ] > ;
134
92
135
93
/**
136
94
* Get a batch of end-to-end sessions from the database.
@@ -156,25 +114,6 @@ export interface CryptoStore {
156
114
txn : unknown ,
157
115
func : ( groupSession : InboundGroupSessionData | null , groupSessionWithheld : IWithheld | null ) => void ,
158
116
) : void ;
159
- getAllEndToEndInboundGroupSessions ( txn : unknown , func : ( session : ISession | null ) => void ) : void ;
160
- addEndToEndInboundGroupSession (
161
- senderCurve25519Key : string ,
162
- sessionId : string ,
163
- sessionData : InboundGroupSessionData ,
164
- txn : unknown ,
165
- ) : void ;
166
- storeEndToEndInboundGroupSession (
167
- senderCurve25519Key : string ,
168
- sessionId : string ,
169
- sessionData : InboundGroupSessionData ,
170
- txn : unknown ,
171
- ) : void ;
172
- storeEndToEndInboundGroupSessionWithheld (
173
- senderCurve25519Key : string ,
174
- sessionId : string ,
175
- sessionData : IWithheld ,
176
- txn : unknown ,
177
- ) : void ;
178
117
179
118
/**
180
119
* Count the number of Megolm sessions in the database.
@@ -201,21 +140,8 @@ export interface CryptoStore {
201
140
deleteEndToEndInboundGroupSessionsBatch ( sessions : { senderKey : string ; sessionId : string } [ ] ) : Promise < void > ;
202
141
203
142
// Device Data
204
- getEndToEndDeviceData ( txn : unknown , func : ( deviceData : IDeviceData | null ) => void ) : void ;
205
- storeEndToEndDeviceData ( deviceData : IDeviceData , txn : unknown ) : void ;
206
- storeEndToEndRoom ( roomId : string , roomInfo : IRoomEncryption , txn : unknown ) : void ;
207
143
getEndToEndRooms ( txn : unknown , func : ( rooms : Record < string , IRoomEncryption > ) => void ) : void ;
208
- getSessionsNeedingBackup ( limit : number ) : Promise < ISession [ ] > ;
209
- countSessionsNeedingBackup ( txn ?: unknown ) : Promise < number > ;
210
- unmarkSessionsNeedingBackup ( sessions : ISession [ ] , txn ?: unknown ) : Promise < void > ;
211
144
markSessionsNeedingBackup ( sessions : ISession [ ] , txn ?: unknown ) : Promise < void > ;
212
- addSharedHistoryInboundGroupSession ( roomId : string , senderKey : string , sessionId : string , txn ?: unknown ) : void ;
213
- getSharedHistoryInboundGroupSessions (
214
- roomId : string ,
215
- txn ?: unknown ,
216
- ) : Promise < [ senderKey : string , sessionId : string ] [ ] > ;
217
- addParkedSharedHistory ( roomId : string , data : ParkedSharedHistory , txn ?: unknown ) : void ;
218
- takeParkedSharedHistory ( roomId : string , txn ?: unknown ) : Promise < ParkedSharedHistory [ ] > ;
219
145
220
146
// Session key backups
221
147
doTxn < T > ( mode : Mode , stores : Iterable < string > , func : ( txn : unknown ) => T , log ?: Logger ) : Promise < T > ;
@@ -346,3 +272,119 @@ export enum MigrationState {
346
272
* {@link CryptoStore#getEndToEndInboundGroupSessionsBatch}.
347
273
*/
348
274
export const SESSION_BATCH_SIZE = 50 ;
275
+
276
+ export interface InboundGroupSessionData {
277
+ room_id : string ; // eslint-disable-line camelcase
278
+ /** pickled Olm.InboundGroupSession */
279
+ session : string ;
280
+ keysClaimed ?: Record < string , string > ;
281
+ /** Devices involved in forwarding this session to us (normally empty). */
282
+ forwardingCurve25519KeyChain : string [ ] ;
283
+ /** whether this session is untrusted. */
284
+ untrusted ?: boolean ;
285
+ /** whether this session exists during the room being set to shared history. */
286
+ sharedHistory ?: boolean ;
287
+ }
288
+
289
+ export interface ICrossSigningInfo {
290
+ keys : Record < string , CrossSigningKeyInfo > ;
291
+ firstUse : boolean ;
292
+ crossSigningVerifiedBefore : boolean ;
293
+ }
294
+
295
+ /* eslint-disable camelcase */
296
+ export interface IRoomEncryption {
297
+ algorithm : string ;
298
+ rotation_period_ms ?: number ;
299
+ rotation_period_msgs ?: number ;
300
+ }
301
+ /* eslint-enable camelcase */
302
+
303
+ export enum TrackingStatus {
304
+ NotTracked ,
305
+ PendingDownload ,
306
+ DownloadInProgress ,
307
+ UpToDate ,
308
+ }
309
+
310
+ /**
311
+ * possible states for a room key request
312
+ *
313
+ * The state machine looks like:
314
+ * ```
315
+ *
316
+ * | (cancellation sent)
317
+ * | .-------------------------------------------------.
318
+ * | | |
319
+ * V V (cancellation requested) |
320
+ * UNSENT -----------------------------+ |
321
+ * | | |
322
+ * | | |
323
+ * | (send successful) | CANCELLATION_PENDING_AND_WILL_RESEND
324
+ * V | Λ
325
+ * SENT | |
326
+ * |-------------------------------- | --------------'
327
+ * | | (cancellation requested with intent
328
+ * | | to resend the original request)
329
+ * | |
330
+ * | (cancellation requested) |
331
+ * V |
332
+ * CANCELLATION_PENDING |
333
+ * | |
334
+ * | (cancellation sent) |
335
+ * V |
336
+ * (deleted) <---------------------------+
337
+ * ```
338
+ */
339
+ export enum RoomKeyRequestState {
340
+ /** request not yet sent */
341
+ Unsent ,
342
+ /** request sent, awaiting reply */
343
+ Sent ,
344
+ /** reply received, cancellation not yet sent */
345
+ CancellationPending ,
346
+ /**
347
+ * Cancellation not yet sent and will transition to UNSENT instead of
348
+ * being deleted once the cancellation has been sent.
349
+ */
350
+ CancellationPendingAndWillResend ,
351
+ }
352
+
353
+ /* eslint-disable camelcase */
354
+ interface IRoomKey {
355
+ room_id : string ;
356
+ algorithm : string ;
357
+ }
358
+
359
+ /**
360
+ * The parameters of a room key request. The details of the request may
361
+ * vary with the crypto algorithm, but the management and storage layers for
362
+ * outgoing requests expect it to have 'room_id' and 'session_id' properties.
363
+ */
364
+ export interface IRoomKeyRequestBody extends IRoomKey {
365
+ session_id : string ;
366
+ sender_key : string ;
367
+ }
368
+
369
+ /* eslint-enable camelcase */
370
+
371
+ export interface IRoomKeyRequestRecipient {
372
+ userId : string ;
373
+ deviceId : string ;
374
+ }
375
+
376
+ interface IDevice {
377
+ keys : Record < string , string > ;
378
+ algorithms : string [ ] ;
379
+ verified : DeviceVerification ;
380
+ known : boolean ;
381
+ unsigned ?: Record < string , any > ;
382
+ signatures ?: ISignatures ;
383
+ }
384
+
385
+ /** State of the verification of the device. */
386
+ export enum DeviceVerification {
387
+ Blocked = - 1 ,
388
+ Unverified = 0 ,
389
+ Verified = 1 ,
390
+ }
0 commit comments