Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3351696
D10964.id36671.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
18 KB
Referenced Files
None
Subscribers
None
D10964.id36671.diff
View Options
diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js
--- a/lib/actions/user-actions.js
+++ b/lib/actions/user-actions.js
@@ -9,6 +9,7 @@
} from '../keyserver-conn/keyserver-call-utils.js';
import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js';
import { preRequestUserStateSelector } from '../selectors/account-selectors.js';
+import { getOneTimeKeyValuesFromBlob } from '../shared/crypto-utils.js';
import { IdentityClientContext } from '../shared/identity-client-context.js';
import threadWatcher from '../shared/thread-watcher.js';
import type {
@@ -688,11 +689,26 @@
options?: ?CallSingleKeyserverEndpointOptions,
) => Promise<GetOlmSessionInitializationDataResponse>) =>
async options => {
- return await callSingleKeyserverEndpoint(
+ const olmInitData = await callSingleKeyserverEndpoint(
'get_olm_session_initialization_data',
{},
options,
);
+ return {
+ signedIdentityKeysBlob: olmInitData.signedIdentityKeysBlob,
+ contentInitializationInfo: {
+ ...olmInitData.contentInitializationInfo,
+ oneTimeKey: getOneTimeKeyValuesFromBlob(
+ olmInitData.contentInitializationInfo.oneTimeKey,
+ )[0],
+ },
+ notifInitializationInfo: {
+ ...olmInitData.notifInitializationInfo,
+ oneTimeKey: getOneTimeKeyValuesFromBlob(
+ olmInitData.notifInitializationInfo.oneTimeKey,
+ )[0],
+ },
+ };
};
const policyAcknowledgmentActionTypes = Object.freeze({
diff --git a/lib/shared/crypto-utils.js b/lib/shared/crypto-utils.js
--- a/lib/shared/crypto-utils.js
+++ b/lib/shared/crypto-utils.js
@@ -17,7 +17,7 @@
CallSingleKeyserverEndpointOptions,
CallSingleKeyserverEndpoint,
} from '../utils/call-single-keyserver-endpoint.js';
-import { values, entries } from '../utils/objects.js';
+import { values } from '../utils/objects.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
export type InitialNotifMessageOptions = {
@@ -104,14 +104,6 @@
return getPrekeyValue(prekey);
}
-function getOneTimeKeyArray(
- oneTimeKeys: OLMOneTimeKeys,
-): $ReadOnlyArray<string> {
- return entries(oneTimeKeys.curve25519).map(([key, value]: [string, string]) =>
- JSON.stringify({ curve25519: { [key]: value } }),
- );
-}
-
export {
getOneTimeKeyValues,
getPrekeyValue,
@@ -119,5 +111,4 @@
getPrekeyValueFromBlob,
initialEncryptedMessageContent,
useInitialNotificationsEncryptedMessage,
- getOneTimeKeyArray,
};
diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
--- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
+++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
@@ -64,8 +64,7 @@
const OlmBuffer &idKeys,
const OlmBuffer &preKeys,
const OlmBuffer &preKeySignature,
- const OlmBuffer &oneTimeKeys,
- size_t keyIndex = 0);
+ const OlmBuffer &oneTimeKey);
bool hasSessionFor(const std::string &targetDeviceId);
std::shared_ptr<Session> getSessionByDeviceId(const std::string &deviceId);
diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
--- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
+++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
@@ -266,8 +266,7 @@
const OlmBuffer &idKeys,
const OlmBuffer &preKeys,
const OlmBuffer &preKeySignature,
- const OlmBuffer &oneTimeKeys,
- size_t keyIndex) {
+ const OlmBuffer &oneTimeKey) {
if (this->hasSessionFor(targetDeviceId)) {
Logger::log(
"olm session overwritten for the device with id: " + targetDeviceId);
@@ -279,8 +278,7 @@
idKeys,
preKeys,
preKeySignature,
- oneTimeKeys,
- keyIndex);
+ oneTimeKey);
this->sessions.insert(make_pair(targetDeviceId, std::move(newSession)));
}
diff --git a/native/cpp/CommonCpp/CryptoTools/Session.h b/native/cpp/CommonCpp/CryptoTools/Session.h
--- a/native/cpp/CommonCpp/CryptoTools/Session.h
+++ b/native/cpp/CommonCpp/CryptoTools/Session.h
@@ -27,8 +27,7 @@
const OlmBuffer &idKeys,
const OlmBuffer &preKeys,
const OlmBuffer &preKeySignature,
- const OlmBuffer &oneTimeKeys,
- size_t keyIndex = 0);
+ const OlmBuffer &oneTimeKey);
static std::unique_ptr<Session> createSessionAsResponder(
OlmAccount *account,
std::uint8_t *ownerIdentityKeys,
diff --git a/native/cpp/CommonCpp/CryptoTools/Session.cpp b/native/cpp/CommonCpp/CryptoTools/Session.cpp
--- a/native/cpp/CommonCpp/CryptoTools/Session.cpp
+++ b/native/cpp/CommonCpp/CryptoTools/Session.cpp
@@ -16,8 +16,7 @@
const OlmBuffer &idKeys,
const OlmBuffer &preKeys,
const OlmBuffer &preKeySignature,
- const OlmBuffer &oneTimeKeys,
- size_t keyIndex) {
+ const OlmBuffer &oneTimeKey) {
std::unique_ptr<Session> session(new Session(account, ownerIdentityKeys));
session->olmSessionBuffer.resize(::olm_session_size());
@@ -40,8 +39,7 @@
KEYSIZE,
preKeySignature.data(),
SIGNATURESIZE,
- oneTimeKeys.data() + ONE_TIME_KEYS_PREFIX_OFFSET +
- (KEYSIZE + ONE_TIME_KEYS_MIDDLE_OFFSET) * keyIndex,
+ oneTimeKey.data(),
KEYSIZE,
randomBuffer.data(),
randomBuffer.size())) {
@@ -75,7 +73,7 @@
if (-1 == ::olm_remove_one_time_keys(account, session->getOlmSession())) {
throw std::runtime_error(
- "error createInbound (remove oneTimeKeys) => " +
+ "error createInbound (remove oneTimeKey) => " +
std::string{::olm_session_last_error(session->getOlmSession())});
}
return session;
diff --git a/native/cpp/CommonCpp/CryptoTools/Tools.h b/native/cpp/CommonCpp/CryptoTools/Tools.h
--- a/native/cpp/CommonCpp/CryptoTools/Tools.h
+++ b/native/cpp/CommonCpp/CryptoTools/Tools.h
@@ -11,8 +11,6 @@
#define ID_KEYS_PREFIX_OFFSET 15
#define SIGNING_KEYS_PREFIX_OFFSET 71
#define PRE_KEY_PREFIX_OFFSET 25
-#define ONE_TIME_KEYS_PREFIX_OFFSET 25
-#define ONE_TIME_KEYS_MIDDLE_OFFSET 12
#define ENCRYPTED_MESSAGE_TYPE 1
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
@@ -775,12 +775,12 @@
jsi::String identityKeys,
jsi::String prekey,
jsi::String prekeySignature,
- jsi::String oneTimeKeys,
+ jsi::String oneTimeKey,
jsi::String keyserverID) {
auto identityKeysCpp{identityKeys.utf8(rt)};
auto prekeyCpp{prekey.utf8(rt)};
auto prekeySignatureCpp{prekeySignature.utf8(rt)};
- auto oneTimeKeysCpp{oneTimeKeys.utf8(rt)};
+ auto oneTimeKeyCpp{oneTimeKey.utf8(rt)};
return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
taskType job = [=, &innerRt]() {
@@ -791,7 +791,7 @@
identityKeysCpp,
prekeyCpp,
prekeySignatureCpp,
- oneTimeKeysCpp,
+ oneTimeKeyCpp,
"Comm");
} catch (const std::exception &e) {
error = e.what();
@@ -840,12 +840,12 @@
jsi::String identityKeys,
jsi::String prekey,
jsi::String prekeySignature,
- jsi::String oneTimeKeys,
+ jsi::String oneTimeKey,
jsi::String deviceID) {
auto identityKeysCpp{identityKeys.utf8(rt)};
auto prekeyCpp{prekey.utf8(rt)};
auto prekeySignatureCpp{prekeySignature.utf8(rt)};
- auto oneTimeKeysCpp{oneTimeKeys.utf8(rt)};
+ auto oneTimeKeyCpp{oneTimeKey.utf8(rt)};
auto deviceIDCpp{deviceID.utf8(rt)};
return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
@@ -861,7 +861,7 @@
std::vector<uint8_t>(
prekeySignatureCpp.begin(), prekeySignatureCpp.end()),
std::vector<uint8_t>(
- oneTimeKeysCpp.begin(), oneTimeKeysCpp.end()));
+ oneTimeKeyCpp.begin(), oneTimeKeyCpp.end()));
const std::string initMessage = "{\"type\": \"init\"}";
initialEncryptedMessage =
diff --git a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp
--- a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp
+++ b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp
@@ -252,7 +252,7 @@
const std::string &identityKeys,
const std::string &prekey,
const std::string &prekeySignature,
- const std::string &oneTimeKeys,
+ const std::string &oneTimeKey,
const std::string &callingProcessName) {
crypto::EncryptedData initialEncryptedMessage;
auto caller = [&](const std::unique_ptr<crypto::CryptoModule> &cryptoModule) {
@@ -261,7 +261,7 @@
std::vector<uint8_t>(identityKeys.begin(), identityKeys.end()),
std::vector<uint8_t>(prekey.begin(), prekey.end()),
std::vector<uint8_t>(prekeySignature.begin(), prekeySignature.end()),
- std::vector<uint8_t>(oneTimeKeys.begin(), oneTimeKeys.end()));
+ std::vector<uint8_t>(oneTimeKey.begin(), oneTimeKey.end()));
initialEncryptedMessage = cryptoModule->encrypt(
NotificationsCryptoModule::keyserverHostedNotificationsID,
NotificationsCryptoModule::initialEncryptedMessageContent);
diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h
--- a/native/cpp/CommonCpp/_generated/commJSI.h
+++ b/native/cpp/CommonCpp/_generated/commJSI.h
@@ -42,9 +42,9 @@
virtual jsi::Value getNotificationsOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) = 0;
virtual jsi::Value generateAndGetPrekeys(jsi::Runtime &rt) = 0;
virtual jsi::Value validateAndUploadPrekeys(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken) = 0;
- virtual jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys, jsi::String keyserverID) = 0;
+ virtual jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKey, jsi::String keyserverID) = 0;
virtual jsi::Value isNotificationsSessionInitialized(jsi::Runtime &rt) = 0;
- virtual jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys, jsi::String deviceID) = 0;
+ virtual jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKey, jsi::String deviceID) = 0;
virtual jsi::Value initializeContentInboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String encryptedMessage, jsi::String deviceID) = 0;
virtual jsi::Value encrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) = 0;
virtual jsi::Value decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) = 0;
@@ -264,13 +264,13 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::validateAndUploadPrekeys, jsInvoker_, instance_, std::move(authUserID), std::move(authDeviceID), std::move(authAccessToken));
}
- jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys, jsi::String keyserverID) override {
+ jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKey, jsi::String keyserverID) override {
static_assert(
bridging::getParameterCount(&T::initializeNotificationsSession) == 6,
"Expected initializeNotificationsSession(...) to have 6 parameters");
return bridging::callFromJs<jsi::Value>(
- rt, &T::initializeNotificationsSession, jsInvoker_, instance_, std::move(identityKeys), std::move(prekey), std::move(prekeySignature), std::move(oneTimeKeys), std::move(keyserverID));
+ rt, &T::initializeNotificationsSession, jsInvoker_, instance_, std::move(identityKeys), std::move(prekey), std::move(prekeySignature), std::move(oneTimeKey), std::move(keyserverID));
}
jsi::Value isNotificationsSessionInitialized(jsi::Runtime &rt) override {
static_assert(
@@ -280,13 +280,13 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::isNotificationsSessionInitialized, jsInvoker_, instance_);
}
- jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys, jsi::String deviceID) override {
+ jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKey, jsi::String deviceID) override {
static_assert(
bridging::getParameterCount(&T::initializeContentOutboundSession) == 6,
"Expected initializeContentOutboundSession(...) to have 6 parameters");
return bridging::callFromJs<jsi::Value>(
- rt, &T::initializeContentOutboundSession, jsInvoker_, instance_, std::move(identityKeys), std::move(prekey), std::move(prekeySignature), std::move(oneTimeKeys), std::move(deviceID));
+ rt, &T::initializeContentOutboundSession, jsInvoker_, instance_, std::move(identityKeys), std::move(prekey), std::move(prekeySignature), std::move(oneTimeKey), std::move(deviceID));
}
jsi::Value initializeContentInboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String encryptedMessage, jsi::String deviceID) override {
static_assert(
diff --git a/native/handlers/peer-to-peer-message-handler.js b/native/handlers/peer-to-peer-message-handler.js
--- a/native/handlers/peer-to-peer-message-handler.js
+++ b/native/handlers/peer-to-peer-message-handler.js
@@ -1,6 +1,6 @@
// @flow
-import { getOneTimeKeyArray } from 'lib/shared/crypto-utils.js';
+import { getOneTimeKeyValues } from 'lib/shared/crypto-utils.js';
import {
type PeerToPeerMessage,
peerToPeerMessageTypes,
@@ -66,8 +66,8 @@
userID,
deviceID,
accessToken,
- getOneTimeKeyArray(primaryOneTimeKeys),
- getOneTimeKeyArray(notificationsOneTimeKeys),
+ getOneTimeKeyValues(primaryOneTimeKeys),
+ getOneTimeKeyValues(notificationsOneTimeKeys),
);
} catch (e) {
console.log(`Error uploading one-time keys: ${e.message}`);
diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js
--- a/native/identity-service/identity-service-context-provider.react.js
+++ b/native/identity-service/identity-service-context-provider.react.js
@@ -2,7 +2,7 @@
import * as React from 'react';
-import { getOneTimeKeyArray } from 'lib/shared/crypto-utils.js';
+import { getOneTimeKeyValues } from 'lib/shared/crypto-utils.js';
import { IdentityClientContext } from 'lib/shared/identity-client-context.js';
import {
type IdentityKeysBlob,
@@ -219,8 +219,8 @@
prekeys.contentPrekeySignature,
prekeys.notifPrekey,
prekeys.notifPrekeySignature,
- getOneTimeKeyArray(primaryOneTimeKeys),
- getOneTimeKeyArray(notificationsOneTimeKeys),
+ getOneTimeKeyValues(primaryOneTimeKeys),
+ getOneTimeKeyValues(notificationsOneTimeKeys),
);
const { userID, accessToken: token } = JSON.parse(registrationResult);
return { accessToken: token, userID, username };
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -95,7 +95,7 @@
identityKeys: string,
prekey: string,
prekeySignature: string,
- oneTimeKeys: string,
+ oneTimeKey: string,
keyserverID: string,
) => Promise<string>;
+isNotificationsSessionInitialized: () => Promise<boolean>;
@@ -103,7 +103,7 @@
identityKeys: string,
prekey: string,
prekeySignature: string,
- oneTimeKeys: string,
+ oneTimeKey: string,
deviceID: string,
) => Promise<string>;
+initializeContentInboundSession: (
diff --git a/web/account/account-hooks.js b/web/account/account-hooks.js
--- a/web/account/account-hooks.js
+++ b/web/account/account-hooks.js
@@ -8,7 +8,6 @@
import {
initialEncryptedMessageContent,
- getOneTimeKeyValuesFromBlob,
getPrekeyValueFromBlob,
} from 'lib/shared/crypto-utils.js';
import { OlmSessionCreatorContext } from 'lib/shared/olm-session-creator-context.js';
@@ -262,9 +261,6 @@
const notificationsPrekey = getPrekeyValueFromBlob(
notificationsInitializationInfo.prekey,
);
- const [notificationsOneTimeKey] = getOneTimeKeyValuesFromBlob(
- notificationsInitializationInfo.oneTimeKey,
- );
const session = new olm.Session();
session.create_outbound(
@@ -273,7 +269,7 @@
notificationsIdentityKeys.ed25519,
notificationsPrekey,
notificationsInitializationInfo.prekeySignature,
- notificationsOneTimeKey,
+ notificationsInitializationInfo.oneTimeKey,
);
const { body: initialNotificationsEncryptedMessage } = session.encrypt(
JSON.stringify(initialEncryptedMessageContent),
@@ -341,9 +337,6 @@
const contentPrekey = getPrekeyValueFromBlob(
contentInitializationInfo.prekey,
);
- const [contentOneTimeKey] = getOneTimeKeyValuesFromBlob(
- contentInitializationInfo.oneTimeKey,
- );
const session = new olm.Session();
session.create_outbound(
@@ -352,7 +345,7 @@
contentIdentityKeys.ed25519,
contentPrekey,
contentInitializationInfo.prekeySignature,
- contentOneTimeKey,
+ contentInitializationInfo.oneTimeKey,
);
const { body: initialContentEncryptedMessage } = session.encrypt(
JSON.stringify(initialEncryptedMessageContent),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 3:14 AM (18 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573657
Default Alt Text
D10964.id36671.diff (18 KB)
Attached To
Mode
D10964: [crypto] unify one-time keys usage
Attached
Detach File
Event Timeline
Log In to Comment