From 3202413501c678857e9e305cb2232e3f7294d1c5 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Fri, 19 Jul 2024 16:17:46 +0100 Subject: [PATCH] fix: join community with keycard (#15635) * fix: keycard signature add 27 * fix: hash message before signing on keycard --- src/app/modules/main/communities/controller.nim | 4 +++- src/app/modules/main/communities/module.nim | 4 +++- src/backend/general.nim | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 203360beac..598331fc82 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -15,6 +15,7 @@ import app_service/service/keycard/service as keycard_service import app_service/common/types import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module import app_service/service/network/network_item +import ../../../../backend/general as status_general const UNIQUE_COMMUNITIES_MODULE_AUTH_IDENTIFIER* = "CommunitiesModule-Authentication" const UNIQUE_COMMUNITIES_MODULE_SIGNING_IDENTIFIER* = "CommunitiesModule-Signing" @@ -466,9 +467,10 @@ proc runSignFlow(self: Controller, pin, path, dataToSign: string) = self.keycardService.startSignFlow(path, dataToSign, pin) proc runSigningOnKeycard*(self: Controller, keyUid: string, path: string, dataToSign: string, pin: string) = - var finalDataToSign = dataToSign + var finalDataToSign = status_general.hashMessageForSigning(dataToSign) if finalDataToSign.startsWith("0x"): finalDataToSign = finalDataToSign[2..^1] + if pin.len == 0: let data = SharedKeycarModuleSigningArgs(uniqueIdentifier: UNIQUE_COMMUNITIES_MODULE_SIGNING_IDENTIFIER, keyUid: keyUid, diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index f01ee5475e..0a5bf04d12 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -732,10 +732,12 @@ method onDataSigned*(self: Module, keyUid: string, path: string, r: string, s: s # being here is not an error return + let vFixed = toLower(uint8(parseUint(v) + 27).toHex()) + for address, details in self.joiningCommunityDetails.addressesToShare.pairs: if details.keyUid != keyUid or details.path != path: continue - self.joiningCommunityDetails.addressesToShare[address].signature = "0x" & r & s & v + self.joiningCommunityDetails.addressesToShare[address].signature = "0x" & r & s & vFixed break self.signSharedAddressesForKeypair(keyUid, pin) diff --git a/src/backend/general.nim b/src/backend/general.nim index 824fe2a3f3..113e2b8afa 100644 --- a/src/backend/general.nim +++ b/src/backend/general.nim @@ -84,4 +84,13 @@ proc backupData*(): RpcResponse[JsonNode] = result = callPrivateRPC("backupData".prefix, payload) proc parseSharedUrl*(url: string): RpcResponse[JsonNode] = - result = callPrivateRPC("parseSharedURL".prefix, %*[url]) \ No newline at end of file + result = callPrivateRPC("parseSharedURL".prefix, %*[url]) + +proc hashMessageForSigning*(message: string): string = + try: + let response = status_go.hashMessage(message) + let jsonResponse = parseJson(response) + return jsonResponse{"result"}.getStr() + except Exception as e: + error "hashMessage: failed to parse json response", error = e.msg + return ""