-
Notifications
You must be signed in to change notification settings - Fork 24
feat: support EAR with incremental sync - WPB-17302 #4310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/ear-support-without-new-sync
Are you sure you want to change the base?
Changes from 26 commits
b8eaa53
efabd78
113f121
e0d40b3
986d2d4
7a4e6f5
0e0c7c5
7889005
e8f2f24
3405047
f289f9e
1f896ee
2701c91
2529cf3
df66095
38b668f
7689b41
d1ae697
ae38662
7b487c5
c43dc40
0242f6d
af717ce
d5a0821
93052a3
1326a1b
b04d292
18f1687
f526676
bbf10c7
a6dc55f
7293043
fbb565b
2ea7235
6a2e408
34f71b9
c192c71
927a65c
dc10036
87b3a0a
e82398e
65fd560
e0296f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| <model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="24411" systemVersion="24G419" minimumToolsVersion="Xcode 7.0" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="7.0"> | ||
| <entity name="StoredUpdateEvent" representedClassName="StoredUpdateEvent" syncable="YES"> | ||
| <attribute name="debugInformation" optional="YES" attributeType="String" syncable="YES"/> | ||
| <attribute name="eventHash" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/> | ||
| <attribute name="isCallEvent" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/> | ||
| <attribute name="isEncrypted" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/> | ||
| <attribute name="isTransient" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/> | ||
| <attribute name="payload" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES"/> | ||
| <attribute name="sortIndex" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" indexed="YES" syncable="YES"/> | ||
| <attribute name="source" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/> | ||
| <attribute name="uuidString" optional="YES" attributeType="String" syncable="YES"/> | ||
| </entity> | ||
| <entity name="StoredUpdateEventEnvelope" representedClassName="WireDataModel.StoredUpdateEventEnvelope" syncable="YES"> | ||
| <attribute name="data" attributeType="Binary" syncable="YES"/> | ||
| <attribute name="isBackgroundAccessible" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/> | ||
| <attribute name="isEncrypted" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/> | ||
| <attribute name="sortIndex" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" indexed="YES" syncable="YES"/> | ||
| </entity> | ||
| </model> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // | ||
| // Wire | ||
| // Copyright (C) 2026 Wire Swiss GmbH | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see http://www.gnu.org/licenses/. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| enum EAREncryptionHelper { | ||
| static func encrypt( | ||
| data: Data, | ||
| publicKey: SecKey | ||
| ) -> Data? { | ||
|
|
||
| SecKeyCreateEncryptedData( | ||
| publicKey, | ||
| .eciesEncryptionCofactorX963SHA256AESGCM, | ||
| data as CFData, | ||
| nil | ||
| ) as? Data | ||
| } | ||
|
|
||
| static func decrypt( | ||
| data: Data, | ||
| privateKey: SecKey | ||
| ) -> Data? { | ||
|
|
||
| SecKeyCreateDecryptedData( | ||
| privateKey, | ||
| .eciesEncryptionCofactorX963SHA256AESGCM, | ||
| data as CFData, | ||
| nil | ||
| ) as? Data | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // | ||
| // Wire | ||
| // Copyright (C) 2026 Wire Swiss GmbH | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see http://www.gnu.org/licenses/. | ||
| // | ||
|
|
||
| import Foundation | ||
| import GenericMessageProtocol | ||
|
|
||
| struct ProtobufMessageDecoder { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: it looks like this was restored to its original implementation, but changes were made recently to throw errors. I think we should preserve these changes. |
||
|
|
||
| private init() {} | ||
|
|
||
| static func getProtobufMessage( | ||
| from base64Message: String, | ||
| externalData: String? = nil | ||
| ) -> GenericMessage? { | ||
| var genericMessage = GenericMessage(from: base64Message, validate: true) | ||
|
|
||
| // If the encrypted payload is bigger than a certain size, an External Message is sent instead of a regular | ||
| // message. | ||
| // See `External` section from https://github.com/wireapp/generic-message-proto | ||
| // See `External messages` section from | ||
| // https://wearezeta.atlassian.net/wiki/spaces/ENGINEERIN/pages/20545866/Messages | ||
| if let externalData, | ||
| case let .some(.external(external)) = genericMessage?.content { | ||
|
|
||
| // Content message is external, we decrypt the external payload | ||
| // and turns it back into a generic non-external content message. | ||
| if let decryptedGenericMessage = decryptExternalMessage( | ||
| externalData: externalData, | ||
| external: external | ||
| ) { | ||
| genericMessage = decryptedGenericMessage | ||
| } else { | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| return genericMessage | ||
| } | ||
|
|
||
| private static func decryptExternalMessage( | ||
| externalData: String, | ||
| external: External | ||
| ) -> GenericMessage? { | ||
| let externalData = Data(base64Encoded: externalData) | ||
| let externalSha256 = externalData?.zmSHA256Digest() | ||
|
|
||
| guard externalSha256 == external.sha256 else { | ||
| return nil | ||
| } | ||
|
|
||
| let decryptedData = externalData?.zmDecryptPrefixedPlainTextIV( | ||
David-Henner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| key: external.otrKey | ||
| ) | ||
|
|
||
| guard | ||
| let base64String = decryptedData?.base64String(), | ||
| let message = GenericMessage(from: base64String, validate: true) | ||
| else { return nil } | ||
|
|
||
| return message | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,13 @@ | |
| throw Failure.mainAppRequired(message: "no self client id") | ||
| } | ||
|
|
||
| let earService = await EARService( | ||
| accountID: accountID, | ||
| coreDataStack: coreDataStack, | ||
| sharedUserDefaults: dependency.sharedUserDefaults, | ||
| authenticationContext: AuthenticationContext(storage: LAContextStorage()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: isn't the LAContextStorage() requiring a biometric prompt?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's |
||
| ) | ||
|
|
||
| // Continue with client. | ||
| let clientScope = clientScope( | ||
| clientID: clientID, | ||
|
|
@@ -163,7 +170,8 @@ | |
| apiVersion: metadata.apiVersion, | ||
| localDomain: metadata.domain, | ||
| isFederationEnabled: metadata.isFederationEnabled, | ||
| coreDataStack: coreDataStack | ||
| coreDataStack: coreDataStack, | ||
| earService: earService | ||
| ) | ||
|
|
||
| try await clientScope.processPayload( | ||
|
|
@@ -266,7 +274,7 @@ | |
| throw Failure.mainAppRequired(message: "database migration required") | ||
| } | ||
|
|
||
| do { | ||
|
Check warning on line 277 in WireDomain/Sources/WireDomain/Notifications/Components/NSEUserScope.swift
|
||
| try await coreDataStack.load() | ||
| } catch { | ||
| throw Failure.failedToLoadPersistenceStack(error) | ||
|
|
@@ -304,7 +312,8 @@ | |
| apiVersion: WireNetwork.APIVersion, | ||
| localDomain: String, | ||
| isFederationEnabled: Bool, | ||
| coreDataStack: CoreDataStack | ||
| coreDataStack: CoreDataStack, | ||
| earService: EARServiceInterface | ||
| ) -> NSEClientScope { | ||
| NSEClientScope( | ||
| parent: self, | ||
|
|
@@ -314,7 +323,8 @@ | |
| apiVersion: apiVersion, | ||
| localDomain: localDomain, | ||
| isFederationEnabled: isFederationEnabled, | ||
| coreDataStack: coreDataStack | ||
| coreDataStack: coreDataStack, | ||
| earService: earService | ||
| ) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.