Created
March 8, 2024 17:38
-
-
Save marcinwasowicz/cb21635f71f95586465b539ca6204cad to your computer and use it in GitHub Desktop.
Update C++ prekey format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/keyserver/docker-compose.yml b/keyserver/docker-compose.yml | |
index b9a0528e8f..adf04a8dd3 100644 | |
--- a/keyserver/docker-compose.yml | |
+++ b/keyserver/docker-compose.yml | |
@@ -13,7 +13,7 @@ services: | |
image: commapp/node-keyserver:1.0 | |
restart: always | |
ports: | |
- - '3000:3000' | |
+ - '3001:3000' | |
env_file: | |
- .env | |
environment: | |
diff --git a/lib/utils/services-utils.js b/lib/utils/services-utils.js | |
index 684f444314..c22609665e 100644 | |
--- a/lib/utils/services-utils.js | |
+++ b/lib/utils/services-utils.js | |
@@ -7,7 +7,7 @@ import type { AuthMetadata } from '../shared/identity-client-context.js'; | |
// If this is true then we're using the identity service for auth. After we | |
// auth, the identity service gives us a CSAT, which we can use to auth with | |
// other Comm services. | |
-const usingCommServicesAccessToken = false; | |
+const usingCommServicesAccessToken = true; | |
// If this is true, then the app is able to support multiple keyservers. This | |
// requires the use of Tunnelbroker and the backup service to persist and sync | |
diff --git a/native/cpp/CommonCpp/CryptoTools/Session.cpp b/native/cpp/CommonCpp/CryptoTools/Session.cpp | |
index 99dc434b4b..ac38b8ecbb 100644 | |
--- a/native/cpp/CommonCpp/CryptoTools/Session.cpp | |
+++ b/native/cpp/CommonCpp/CryptoTools/Session.cpp | |
@@ -1,6 +1,9 @@ | |
#include "Session.h" | |
#include "PlatformSpecificTools.h" | |
+#include <folly/String.h> | |
+#include <folly/dynamic.h> | |
+#include <folly/json.h> | |
#include <stdexcept> | |
namespace comm { | |
@@ -27,6 +30,18 @@ std::unique_ptr<Session> Session::createSessionAsInitializer( | |
randomBuffer, | |
::olm_create_outbound_session_random_length(session->getOlmSession())); | |
+ std::string preKeysString = std::string{preKeys.begin(), preKeys.end()}; | |
+ std::string shortFormatPrekeyString; | |
+ try { | |
+ folly::dynamic parsedPrekey = folly::parseJson(preKeysString); | |
+ shortFormatPrekeyString = | |
+ parsedPrekey["curve25519"].items().begin()->second.asString(); | |
+ } catch (const folly::json::parse_error &e) { | |
+ shortFormatPrekeyString = preKeysString; | |
+ } | |
+ OlmBuffer shortFormatPrekey = | |
+ OlmBuffer{shortFormatPrekeyString.begin(), shortFormatPrekeyString.end()}; | |
+ | |
if (-1 == | |
::olm_create_outbound_session( | |
session->getOlmSession(), | |
@@ -35,7 +50,7 @@ std::unique_ptr<Session> Session::createSessionAsInitializer( | |
KEYSIZE, | |
idKeys.data() + SIGNING_KEYS_PREFIX_OFFSET, | |
KEYSIZE, | |
- preKeys.data() + PRE_KEY_PREFIX_OFFSET, | |
+ shortFormatPrekey.data(), | |
KEYSIZE, | |
preKeySignature.data(), | |
SIGNATURESIZE, | |
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp | |
index 493a1b0e4d..f3c203c9fb 100644 | |
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp | |
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp | |
@@ -715,6 +715,16 @@ jsi::Value CommCoreModule::validateAndUploadPrekeys( | |
} | |
std::string prekeyUploadError; | |
+ std::string contentPrekeyValueToUpload = | |
+ folly::parseJson(contentPrekeyToUpload)["curve25519"] | |
+ .items() | |
+ .begin() | |
+ ->second.asString(); | |
+ std::string notifsPrekeyValueToUpload = | |
+ folly::parseJson(notifsPrekeyToUpload)["curve25519"] | |
+ .items() | |
+ .begin() | |
+ ->second.asString(); | |
try { | |
std::string contentPrekeySignature = | |
@@ -734,9 +744,9 @@ jsi::Value CommCoreModule::validateAndUploadPrekeys( | |
authUserIDRust, | |
authDeviceIDRust, | |
authAccessTokenRust, | |
- rust::string(contentPrekeyToUpload), | |
+ rust::string(contentPrekeyValueToUpload), | |
rust::string(contentPrekeySignature), | |
- rust::string(notifsPrekeyToUpload), | |
+ rust::string(notifsPrekeyValueToUpload), | |
rust::string(notifsPrekeySignature), | |
currentID); | |
prekeyFuture.get(); | |
@@ -812,17 +822,29 @@ jsi::Value CommCoreModule::validateAndGetPrekeys(jsi::Runtime &rt) { | |
error = e.what(); | |
} | |
+ std::string contentPrekeyValue = | |
+ folly::parseJson(contentPrekey.value())["curve25519"] | |
+ .items() | |
+ .begin() | |
+ ->second.asString(); | |
+ | |
+ std::string notifPrekeyValue = | |
+ folly::parseJson(notifPrekey.value())["curve25519"] | |
+ .items() | |
+ .begin() | |
+ ->second.asString(); | |
+ | |
this->jsInvoker_->invokeAsync([=, &innerRt]() { | |
if (error.size()) { | |
promise->reject(error); | |
return; | |
} | |
auto contentPrekeyJSI = | |
- jsi::String::createFromUtf8(innerRt, contentPrekey.value()); | |
+ jsi::String::createFromUtf8(innerRt, contentPrekeyValue); | |
auto contentPrekeySignatureJSI = | |
jsi::String::createFromUtf8(innerRt, contentPrekeySignature); | |
auto notifPrekeyJSI = | |
- jsi::String::createFromUtf8(innerRt, notifPrekey.value()); | |
+ jsi::String::createFromUtf8(innerRt, notifPrekeyValue); | |
auto notifPrekeySignatureJSI = | |
jsi::String::createFromUtf8(innerRt, notifPrekeySignature); | |
diff --git a/native/profile/add-keyserver.react.js b/native/profile/add-keyserver.react.js | |
index 441615e1f8..60bc5e7912 100644 | |
--- a/native/profile/add-keyserver.react.js | |
+++ b/native/profile/add-keyserver.react.js | |
@@ -49,8 +49,8 @@ function AddKeyserver(props: Props): React.Node { | |
return; | |
} | |
- const isKeyserverURLValid = await isKeyserverURLValidCallback(); | |
- if (!isKeyserverURLValid) { | |
+ const keyserverVersionData = await isKeyserverURLValidCallback(); | |
+ if (!keyserverVersionData) { | |
setShowErrorMessage(true); | |
return; | |
} | |
@@ -60,7 +60,7 @@ function AddKeyserver(props: Props): React.Node { | |
dispatch({ | |
type: addKeyserverActionType, | |
payload: { | |
- keyserverAdminUserID: currentUserID, | |
+ keyserverAdminUserID: keyserverVersionData.ownerID, | |
newKeyserverInfo, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment