Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5767,7 +5767,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -5833,7 +5833,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -6114,7 +6114,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/nextcloud/NextcloudKit";
requirement = {
branch = main;
branch = 7.2.7;
kind = branch;
};
};
Expand Down
13 changes: 7 additions & 6 deletions iOSClient/GUI/Lucid Banner/AlertActionBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import LucidBanner

@MainActor
func showAlertActionBanner(lucidBanner: LucidBanner?,
windowScene: UIWindowScene?,
title: String? = nil,
subtitle: String? = nil,
onConfirm: (() -> Void)? = nil) {
guard let lucidBanner else {
guard let lucidBanner,
let windowScene,
let window = windowScene.windows.first(where: \.isKeyWindow) else {
return
}
let isPad = lucidBanner.windowScene.traitCollection.userInterfaceIdiom == .pad
let horizontalLayout: LucidBanner.HorizontalLayout =
isPad
? .centered(width: 450)
: .stretch(margins: 20)
let horizontalLayout = horizontalLayoutBanner(bounds: window.bounds,
safeAreaInsets: window.safeAreaInsets,
idiom: window.traitCollection.userInterfaceIdiom)

let payload = LucidBannerPayload(
title: title,
Expand Down
3 changes: 2 additions & 1 deletion iOSClient/GUI/Lucid Banner/ErrorBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func showErrorBanner(windowScene: UIWindowScene?,
footnote: String? = nil,
errorCode: Int? = nil,
afError: AFError? = nil) async {
guard let windowScene, let window = windowScene.windows.first else {
guard let windowScene,
let window = windowScene.windows.first(where: \.isKeyWindow) else {
return
}

Expand Down
7 changes: 6 additions & 1 deletion iOSClient/GUI/Lucid Banner/HudBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ func showHudBanner(windowScene: UIWindowScene?,
subtitle: String? = nil,
stage: LucidBanner.Stage? = nil,
onButtonTap: (() -> Void)? = nil) -> (banner: LucidBanner?, token: Int?) {
guard let windowScene else {
guard let windowScene,
let window = windowScene.windows.first(where: \.isKeyWindow) else {
return (nil, nil)
}
let localizedTitle = title.map { NSLocalizedString($0, comment: "") }
let localizedSubTitle = subtitle.map { NSLocalizedString($0, comment: "") }
let banner = LucidBannerRegistry.shared.banner(for: windowScene)
let horizontalLayout = horizontalLayoutBanner(bounds: window.bounds,
safeAreaInsets: window.safeAreaInsets,
idiom: window.traitCollection.userInterfaceIdiom)

let payload = LucidBannerPayload(
title: localizedTitle,
subtitle: localizedSubTitle,
stage: stage,
vPosition: .center,
horizontalLayout: horizontalLayout,
blocksTouches: true,
)

Expand Down
7 changes: 6 additions & 1 deletion iOSClient/GUI/Lucid Banner/HudIndeterminateBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ func showHudIndeterminateBanner(windowScene: UIWindowScene?,
subtitle: String? = nil,
stage: LucidBanner.Stage? = nil,
onButtonTap: (() -> Void)? = nil) -> (banner: LucidBanner?, token: Int?) {
guard let windowScene else {
guard let windowScene,
let window = windowScene.windows.first(where: \.isKeyWindow) else {
return (nil, nil)
}
let localizedTitle = title.map { NSLocalizedString($0, comment: "") }
let localizedSubTitle = subtitle.map { NSLocalizedString($0, comment: "") }
let banner = LucidBannerRegistry.shared.banner(for: windowScene)
let horizontalLayout = horizontalLayoutBanner(bounds: window.bounds,
safeAreaInsets: window.safeAreaInsets,
idiom: window.traitCollection.userInterfaceIdiom)

let payload = LucidBannerPayload(
title: localizedTitle,
subtitle: localizedSubTitle,
stage: stage,
vPosition: .center,
horizontalLayout: horizontalLayout,
blocksTouches: true,
)

Expand Down
3 changes: 2 additions & 1 deletion iOSClient/GUI/Lucid Banner/InfoBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func showInfoBanner(windowScene: UIWindowScene?,
text: String,
footnote: String? = nil,
errorCode: Int? = nil) async {
guard let windowScene, let window = windowScene.windows.first else {
guard let windowScene,
let window = windowScene.windows.first(where: \.isKeyWindow) else {
return
}

Expand Down
3 changes: 2 additions & 1 deletion iOSClient/GUI/Lucid Banner/ShowBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func showBanner(windowScene: UIWindowScene?,
swipeToDismiss: Bool = true,
policy: LucidBanner.ShowPolicy = .replace,
errorCode: Int? = nil) async -> (banner: LucidBanner?, token: Int?) {
guard let windowScene, let window = windowScene.windows.first else {
guard let windowScene,
let window = windowScene.windows.first(where: \.isKeyWindow) else {
return(nil, nil)
}

Expand Down
3 changes: 2 additions & 1 deletion iOSClient/GUI/Lucid Banner/UploadBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ func showUploadBanner(windowScene: UIWindowScene?,
payload: LucidBannerPayload,
allowMinimizeOnTap: Bool,
onButtonTap: (() -> Void)? = nil) -> (banner: LucidBanner?, token: Int?) {
guard let windowScene, let window = windowScene.windows.first else {
guard let windowScene,
let window = windowScene.windows.first(where: \.isKeyWindow) else {
return (nil, nil)
}
let horizontalLayout = horizontalLayoutBanner(bounds: window.bounds,
Expand Down
3 changes: 2 additions & 1 deletion iOSClient/GUI/Lucid Banner/WarningBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func showWarningBanner(windowScene: UIWindowScene?,
systemImage: String,
imageAnimation: LucidBanner.LucidBannerAnimationStyle,
errorCode: Int? = nil) async {
guard let windowScene, let window = windowScene.windows.first else {
guard let windowScene,
let window = windowScene.windows.first(where: \.isKeyWindow) else {
return
}

Expand Down
1 change: 1 addition & 0 deletions iOSClient/Login/NCLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
self.banner = LucidBannerRegistry.shared.banner(for: windowScene)

showAlertActionBanner(lucidBanner: banner,
windowScene: windowScene,
title: title,
subtitle: subtitle) {
self.openShareAccountsViewController(nil)
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Networking/E2EE/NCEndToEndMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class NCEndToEndMetadata: NSObject {
return await decodeMetadataV1(metadata, serverUrl: serverUrl, ocIdServerUrl: directory.ocId, session: session)
} else if (try? JSONDecoder().decode(E2eeV12.self, from: data)) != nil {
return await decodeMetadataV12(metadata, serverUrl: serverUrl, ocIdServerUrl: directory.ocId, session: session)
} else if (try? JSONDecoder().decode(E2eeV20.self, from: data)) != nil {
return await decodeMetadataV20(metadata, signature: signature, serverUrl: serverUrl, ocIdServerUrl: directory.ocId, session: session)
} else if (try? JSONDecoder().decode(E2eeV2.self, from: data)) != nil {
return await decodeMetadataV2(metadata, signature: signature, serverUrl: serverUrl, ocIdServerUrl: directory.ocId, session: session)
} else {
return NKError(errorCode: NCGlobal.shared.errorE2EEVersion, errorDescription: "Unable to decode the metadata file")
}
Expand Down
46 changes: 23 additions & 23 deletions iOSClient/Networking/E2EE/NCEndToEndMetadataV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Gzip

extension NCEndToEndMetadata {
struct E2eeV20: Codable {
struct E2eeV2: Codable {

struct Metadata: Codable {
let ciphertext: String
Expand Down Expand Up @@ -56,7 +56,7 @@
let version: String
}

struct E2eeV20Signature: Codable {
struct E2eeV2Signature: Codable {

struct Metadata: Codable {
let ciphertext: String
Expand Down Expand Up @@ -95,8 +95,8 @@

var metadataKey: String?
var keyChecksums: [String] = []
var usersCodable: [E2eeV20.Users] = []
var filesCodable: [String: E2eeV20.Metadata.ciphertext.Files] = [:]
var usersCodable: [E2eeV2.Users] = []
var filesCodable: [String: E2eeV2.Metadata.ciphertext.Files] = [:]
var folders: [String: String] = [:]
var counter: Int = 1

Expand Down Expand Up @@ -151,7 +151,7 @@
let users = await self.database.getE2EUsersAsync(account: session.account, directoryTopOcId: directoryTopOcId)
for user in users {
if isDirectoryTop {
usersCodable.append(E2eeV20.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
usersCodable.append(E2eeV2.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
}
if let hash = NCEndToEndEncryption.shared().createSHA256(user.metadataKey) {
keyChecksums.append(hash)
Expand All @@ -172,15 +172,15 @@
if e2eEncryption.mimeType == "httpd/unix-directory" {
folders[e2eEncryption.fileNameIdentifier] = e2eEncryption.fileName
} else {
let file = E2eeV20.Metadata.ciphertext.Files(authenticationTag: e2eEncryption.authenticationTag, filename: e2eEncryption.fileName, key: e2eEncryption.key, mimetype: e2eEncryption.mimeType, nonce: e2eEncryption.initializationVector)
let file = E2eeV2.Metadata.ciphertext.Files(authenticationTag: e2eEncryption.authenticationTag, filename: e2eEncryption.fileName, key: e2eEncryption.key, mimetype: e2eEncryption.mimeType, nonce: e2eEncryption.initializationVector)
filesCodable.updateValue(file, forKey: e2eEncryption.fileNameIdentifier)
}
}

do {
var authenticationTag: NSString?
var initializationVector: NSString?
let json = try JSONEncoder().encode(E2eeV20.Metadata.ciphertext(counter: counter, deleted: false, keyChecksums: keyChecksums, files: filesCodable, folders: folders))
let json = try JSONEncoder().encode(E2eeV2.Metadata.ciphertext(counter: counter, deleted: false, keyChecksums: keyChecksums, files: filesCodable, folders: folders))
let jsonZip = try json.gzipped()
let ciphertextMetadata = NCEndToEndEncryption.shared().encryptPayloadFile(jsonZip, key: metadataKey, initializationVector: &initializationVector, authenticationTag: &authenticationTag)
guard var ciphertextMetadata, let initializationVector = initializationVector as? String, let authenticationTag = authenticationTag as? String else {
Expand All @@ -191,8 +191,8 @@
// Add initializationVector [ANDROID]
ciphertextMetadata = ciphertextMetadata + "|" + initializationVector

let metadataCodable = E2eeV20.Metadata(ciphertext: ciphertextMetadata, nonce: initializationVector, authenticationTag: authenticationTag)
let e2eeCodable = E2eeV20(metadata: metadataCodable, users: usersCodable, filedrop: nil, version: capabilities.e2EEApiVersion)
let metadataCodable = E2eeV2.Metadata(ciphertext: ciphertextMetadata, nonce: initializationVector, authenticationTag: authenticationTag)
let e2eeCodable = E2eeV2(metadata: metadataCodable, users: usersCodable, filedrop: nil, version: capabilities.e2EEApiVersion)
let e2eeData = try JSONEncoder().encode(e2eeCodable)
e2eeData.printJson()

Expand All @@ -210,7 +210,7 @@
// MARK: Decode JSON Metadata V2
// --------------------------------------------------------------------------------------------

func decodeMetadataV20(_ json: String, signature: String?, serverUrl: String, ocIdServerUrl: String, session: NCSession.Session) async -> NKError {
func decodeMetadataV2(_ json: String, signature: String?, serverUrl: String, ocIdServerUrl: String, session: NCSession.Session) async -> NKError {
let global = NCGlobal.shared
guard let data = json.data(using: .utf8),
let directoryTop = await utilityFileSystem.getMetadataE2EETopAsync(serverUrl: serverUrl, session: session) else {
Expand Down Expand Up @@ -252,7 +252,7 @@
}

do {
let json = try JSONDecoder().decode(E2eeV20.self, from: data)
let json = try JSONDecoder().decode(E2eeV2.self, from: data)
let metadata = json.metadata
let users = json.users
let filesdrop = json.filedrop
Expand Down Expand Up @@ -326,7 +326,7 @@
}
let data = try decryptedFiledrop.gunzipped()
if let jsonText = String(data: data, encoding: .utf8) { print(jsonText) }
let file = try JSONDecoder().decode(E2eeV20.Metadata.ciphertext.Files.self, from: data)
let file = try JSONDecoder().decode(E2eeV2.Metadata.ciphertext.Files.self, from: data)
print(file)
await addE2eEncryption(fileNameIdentifier: fileNameIdentifier, fileName: file.filename, authenticationTag: file.authenticationTag, key: file.key, initializationVector: file.nonce, metadataKey: filedropKey, mimetype: file.mimetype)
}
Expand All @@ -344,7 +344,7 @@
let data = try decryptedMetadata.gunzipped()
// DEBUG
// if let jsonText = String(data: data, encoding: .utf8) { print(jsonText) }
let jsonCiphertextMetadata = try JSONDecoder().decode(E2eeV20.Metadata.ciphertext.self, from: data)
let jsonCiphertextMetadata = try JSONDecoder().decode(E2eeV2.Metadata.ciphertext.self, from: data)

// CHECKSUM CHECK
//
Expand Down Expand Up @@ -379,7 +379,7 @@
// DELETE CHECK
//
if let deleted = jsonCiphertextMetadata.deleted, deleted {
// TODO: We need to check deleted, id yes ???

Check warning on line 382 in iOSClient/Networking/E2EE/NCEndToEndMetadataV2.swift

View workflow job for this annotation

GitHub Actions / Lint

Todo Violation: TODOs should be resolved (We need to check deleted, id y...) (todo)
}

await self.database.addE2eMetadataAsync(account: session.account,
Expand Down Expand Up @@ -424,15 +424,15 @@

// MARK: -

func createSignature(metadata: E2eeV20.Metadata, users: [E2eeV20.Users]?, version: String, certificate: String, session: NCSession.Session) -> String? {
func createSignature(metadata: E2eeV2.Metadata, users: [E2eeV2.Users]?, version: String, certificate: String, session: NCSession.Session) -> String? {
guard let users else { return nil }
var usersSignatureCodable: [E2eeV20Signature.Users] = []
var usersSignatureCodable: [E2eeV2Signature.Users] = []

for user in users {
usersSignatureCodable.append(E2eeV20Signature.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
usersSignatureCodable.append(E2eeV2Signature.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
}

let signatureCodable = E2eeV20Signature(metadata: E2eeV20Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: usersSignatureCodable, version: version)
let signatureCodable = E2eeV2Signature(metadata: E2eeV2Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: usersSignatureCodable, version: version)

do {
let jsonEncoder = JSONEncoder()
Expand All @@ -451,19 +451,19 @@
return nil
}

func verifySignature(account: String, signature: String, userId: String, metadata: E2eeV20.Metadata, users: [E2eeV20.Users]?, version: String, certificate: String) -> Bool {
var signatureCodable: E2eeV20Signature?
func verifySignature(account: String, signature: String, userId: String, metadata: E2eeV2.Metadata, users: [E2eeV2.Users]?, version: String, certificate: String) -> Bool {
var signatureCodable: E2eeV2Signature?
var certificates: [String] = []

if let users {
var usersSignatureCodable: [E2eeV20Signature.Users] = []
var usersSignatureCodable: [E2eeV2Signature.Users] = []
for user in users {
usersSignatureCodable.append(E2eeV20Signature.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
usersSignatureCodable.append(E2eeV2Signature.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
}
signatureCodable = E2eeV20Signature(metadata: E2eeV20Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: usersSignatureCodable, version: version)
signatureCodable = E2eeV2Signature(metadata: E2eeV2Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: usersSignatureCodable, version: version)
certificates = users.map { $0.certificate }
} else {
signatureCodable = E2eeV20Signature(metadata: E2eeV20Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: nil, version: version)
signatureCodable = E2eeV2Signature(metadata: E2eeV2Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: nil, version: version)
certificates = [certificate]
}

Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Networking/NCConfigServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class NCConfigServer: NSObject, UIActionSheetDelegate, URLSessionDelegate
dataTask.resume()
}

func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping @Sendable (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
NCNetworking.shared.checkTrustedChallenge(session, didReceive: challenge, completionHandler: completionHandler)
}

Expand Down
Loading