Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3367350
D11119.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11119.diff
View Options
diff --git a/lib/types/crypto-types.js b/lib/types/crypto-types.js
--- a/lib/types/crypto-types.js
+++ b/lib/types/crypto-types.js
@@ -130,4 +130,5 @@
contentIdentityKeys: OLMIdentityKeys,
initialEncryptedContent: string,
) => Promise<string>,
+ +getOneTimeKeys: (numberOfKeys: number) => Promise<OneTimeKeysResultValues>,
};
diff --git a/lib/utils/olm-utils.js b/lib/utils/olm-utils.js
--- a/lib/utils/olm-utils.js
+++ b/lib/utils/olm-utils.js
@@ -75,6 +75,18 @@
return { prekey, prekeySignature };
}
+function getAccountOneTimeKeys(
+ account: OlmAccount,
+ numberOfKeys: number,
+): $ReadOnlyArray<string> {
+ let oneTimeKeys = getOneTimeKeyValuesFromBlob(account.one_time_keys());
+ if (oneTimeKeys.length < numberOfKeys) {
+ account.generate_one_time_keys(numberOfKeys - oneTimeKeys.length);
+ oneTimeKeys = getOneTimeKeyValuesFromBlob(account.one_time_keys());
+ }
+ return oneTimeKeys;
+}
+
function retrieveAccountKeysSet(account: OlmAccount): AccountKeysSet {
const identityKeys = account.identity_keys();
@@ -85,12 +97,7 @@
throw new Error('invalid_prekey');
}
- let oneTimeKeys = getOneTimeKeyValuesFromBlob(account.one_time_keys());
-
- if (oneTimeKeys.length < ONE_TIME_KEYS_NUMBER) {
- account.generate_one_time_keys(ONE_TIME_KEYS_NUMBER);
- oneTimeKeys = getOneTimeKeyValuesFromBlob(account.one_time_keys());
- }
+ const oneTimeKeys = getAccountOneTimeKeys(account, ONE_TIME_KEYS_NUMBER);
return { identityKeys, oneTimeKeys, prekey, prekeySignature };
}
@@ -100,4 +107,5 @@
getAccountPrekeysSet,
shouldForgetPrekey,
shouldRotatePrekey,
+ getAccountOneTimeKeys,
};
diff --git a/native/crypto/olm-api.js b/native/crypto/olm-api.js
--- a/native/crypto/olm-api.js
+++ b/native/crypto/olm-api.js
@@ -1,6 +1,11 @@
// @flow
-import type { OlmAPI, OLMIdentityKeys } from 'lib/types/crypto-types';
+import { getOneTimeKeyValues } from 'lib/shared/crypto-utils.js';
+import type {
+ OneTimeKeysResultValues,
+ OlmAPI,
+ OLMIdentityKeys,
+} from 'lib/types/crypto-types';
import { commCoreModule } from '../native-modules.js';
@@ -24,6 +29,14 @@
contentIdentityKeys.ed25519,
);
},
+ async getOneTimeKeys(numberOfKeys: number): Promise<OneTimeKeysResultValues> {
+ const { contentOneTimeKeys, notificationsOneTimeKeys } =
+ await commCoreModule.getOneTimeKeys(numberOfKeys);
+ return {
+ contentOneTimeKeys: getOneTimeKeyValues(contentOneTimeKeys),
+ notificationsOneTimeKeys: getOneTimeKeyValues(notificationsOneTimeKeys),
+ };
+ },
};
export { olmAPI };
diff --git a/web/crypto/olm-api.js b/web/crypto/olm-api.js
--- a/web/crypto/olm-api.js
+++ b/web/crypto/olm-api.js
@@ -7,13 +7,17 @@
type OlmAPI,
olmEncryptedMessageTypes,
type OLMIdentityKeys,
+ type OneTimeKeysResultValues,
} from 'lib/types/crypto-types.js';
+import { getAccountOneTimeKeys } from 'lib/utils/olm-utils.js';
// methods below are just mocks to SQLite API
// implement proper methods tracked in ENG-6462
function getOlmAccount(): Account {
- return new olm.Account();
+ const account = new olm.Account();
+ account.create();
+ return account;
}
// eslint-disable-next-line no-unused-vars
function getOlmSession(deviceID: string): Session {
@@ -64,6 +68,25 @@
storeOlmSession(session);
return initialEncryptedMessage;
},
+ async getOneTimeKeys(numberOfKeys: number): Promise<OneTimeKeysResultValues> {
+ const contentAccount = getOlmAccount();
+ const notifAccount = getOlmAccount();
+ const contentOneTimeKeys = getAccountOneTimeKeys(
+ contentAccount,
+ numberOfKeys,
+ );
+ contentAccount.mark_keys_as_published();
+ storeOlmAccount(contentAccount);
+
+ const notificationsOneTimeKeys = getAccountOneTimeKeys(
+ notifAccount,
+ numberOfKeys,
+ );
+ notifAccount.mark_keys_as_published();
+ storeOlmAccount(notifAccount);
+
+ return { contentOneTimeKeys, notificationsOneTimeKeys };
+ },
};
export { olmAPI };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 2:36 PM (21 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2585136
Default Alt Text
D11119.diff (3 KB)
Attached To
Mode
D11119: [crypto] implement getting one-time keys in `OlmAPI`
Attached
Detach File
Event Timeline
Log In to Comment