Skip to content

[stable-6.6.0] NMC/1937 - E2EE #332

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

Open
wants to merge 2 commits into
base: stable-6.6.0
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */; };
AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; };
AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; };
AFCE353927E5DE0500FEA6C2 /* NCShare+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */; };
B568C2C92DA7CE560072FCB4 /* E2EETests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B568C2C82DA7CE560072FCB4 /* E2EETests.swift */; };
C04E2F232A17BB4D001BAD85 /* FilesIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E2F222A17BB4D001BAD85 /* FilesIntegrationTests.swift */; };
D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; };
D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; };
Expand Down Expand Up @@ -1330,6 +1333,8 @@
AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = "<group>"; };
AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+Helper.swift"; sourceTree = "<group>"; };
B568C2C82DA7CE560072FCB4 /* E2EETests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = E2EETests.swift; sourceTree = "<group>"; };
C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2118,6 +2123,8 @@
isa = PBXGroup;
children = (
AA52EB452D42AC5A0089C348 /* Placeholder.swift */,
B568C2C82DA7CE560072FCB4 /* E2EETests.swift */,
AF8ED1FB2757821000B8DBC4 /* NextcloudUnitTests.swift */,
);
path = NextcloudUnitTests;
sourceTree = "<group>";
Expand Down
90 changes: 90 additions & 0 deletions Tests/NextcloudUnitTests/E2EETests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// E2EETests.swift
// NextcloudTests
//
// Created by A200020526 on 26/05/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

@testable import Nextcloud
import XCTest
import TOPasscodeViewController

final class E2EETests: XCTestCase {

var manageE2EE: NCManageE2EE!

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
manageE2EE = NCManageE2EE()
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
manageE2EE = nil
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

// MARK: - Initialization

func testInitialization() {
XCTAssertTrue(manageE2EE.endToEndInitialize.delegate === manageE2EE)
XCTAssertFalse(manageE2EE.isEndToEndEnabled)
XCTAssertEqual(manageE2EE.statusOfService, NSLocalizedString("_status_in_progress_", comment: ""))
}

// MARK: - Delegate

func testEndToEndInitializeSuccess() {
manageE2EE.endToEndInitializeSuccess()
XCTAssertTrue(manageE2EE.isEndToEndEnabled)
}

// MARK: - Passcode

func testRequestPasscodeType() {
// TODO: Implement this test case
}

func testCorrectPasscode_startE2E() {
manageE2EE.passcodeType = "startE2E"
manageE2EE.correctPasscode()
// TODO: Add assertions for the expected behavior after entering the correct passcode for starting E2E
}

func testCorrectPasscode_readPassphrase() {
manageE2EE.passcodeType = "readPassphrase"
// TODO: Simulate entering the correct passcode and verify the expected behavior
}

func testCorrectPasscode_removeLocallyEncryption() {
manageE2EE.passcodeType = "removeLocallyEncryption"
// TODO: Simulate entering the correct passcode and verify the expected behavior
}

func testDidPerformBiometricValidationRequest() {
let passcodeViewController = TOPasscodeViewController(passcodeType: .sixDigits, allowCancel: true)
manageE2EE.didPerformBiometricValidationRequest(in: passcodeViewController)
// TODO: Add assertions for the expected behavior after performing biometric validation
}

func testDidTapCancel() {
let passcodeViewController = TOPasscodeViewController(passcodeType: .sixDigits, allowCancel: true)
manageE2EE.didTapCancel(in: passcodeViewController)
// TODO: Add assertions for the expected behavior after tapping cancel
}
}
6 changes: 3 additions & 3 deletions iOSClient/Settings/E2EE/NCEndToEndInitialize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class NCEndToEndInitialize: NSObject {
let privateKey = String(data: keyData, encoding: .utf8) {
NCKeychain().setEndToEndPrivateKey(account: account, privateKey: privateKey)
} else {
let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "Serious internal error to decrypt Private Key")
NCContentPresenter().messageNotification("E2E decrypt privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: NSLocalizedString("_e2e_error_incorrect_passphrase_", comment: ""))
NCContentPresenter().messageNotification(NSLocalizedString("_e2e_error_passphrase_title", comment: ""), error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)

return
}
Expand Down Expand Up @@ -159,7 +159,7 @@ class NCEndToEndInitialize: NSObject {
}
})

let cancel = UIAlertAction(title: "Cancel", style: .cancel) { _ -> Void in
let cancel = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ -> Void in
}

alertController.addAction(ok)
Expand Down
156 changes: 109 additions & 47 deletions iOSClient/Settings/E2EE/NCManageE2EEView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
import SwiftUI
import NextcloudKit

@objc class NCManageE2EEInterface: NSObject {

@objc func makeShipDetailsUI(account: String) -> UIViewController {

let controller = UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController
let details = NCManageE2EEView(model: NCManageE2EE(controller: controller))
let vc = UIHostingController(rootView: details)
vc.title = NSLocalizedString("_e2e_settings_", comment: "")
return vc
}
}

struct NCManageE2EEView: View {
@ObservedObject var model: NCManageE2EE
@Environment(\.presentationMode) var presentationMode
Expand All @@ -32,104 +44,95 @@ struct NCManageE2EEView: View {
VStack {
if model.isEndToEndEnabled {
List {
Section(header: Text(""), footer: Text(model.statusOfService + "\n\n" + "End-to-End Encryption " + model.capabilities.capabilityE2EEApiVersion)) {
Section(header: Text(""), footer: Text("End-to-End Encryption " + NCGlobal.shared.capabilityE2EEApiVersion)) {
Label {
Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
} icon: {
Image(systemName: "checkmark.circle.fill")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 25, height: 25)
.foregroundColor(.green)
}
}
HStack {

Section(header: Text(""), footer: Text(NSLocalizedString("_read_passphrase_description_", comment: ""))) {
Label {
Text(NSLocalizedString("_e2e_settings_read_passphrase_", comment: ""))
} icon: {
Image(systemName: "eye")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 25, height: 25)
.foregroundColor(Color(NCBrandColor.shared.iconImageColor))
.foregroundColor(Color(NCBrandColor.shared.iconColor))
.frame(width: 20, height: 30)
}
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
if NCKeychain().passcode != nil {
model.requestPasscodeType("readPassphrase")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
.onTapGesture {
if NCKeychain().passcode != nil {
model.requestPasscodeType("readPassphrase")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
}
}
}
HStack {

let removeStrDesc1 = NSLocalizedString("_remove_passphrase_desc_1_", comment: "")
let removeStrDesc2 = NSLocalizedString("_remove_passphrase_desc_2_", comment: "")
let removeStrDesc = String(format: "%@\n\n%@", removeStrDesc1, removeStrDesc2)
Section(header: Text(""), footer: Text(removeStrDesc)) {
Label {
Text(NSLocalizedString("_e2e_settings_remove_", comment: ""))
} icon: {
Image(systemName: "xmark")
Image(systemName: "trash")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 25, height: 15)
.foregroundColor(Color(NCBrandColor.shared.iconImageColor))
.foregroundColor(Color(NCBrandColor.shared.iconColor))
.frame(width: 20, height: 30)
}
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
if NCKeychain().passcode != nil {
model.requestPasscodeType("removeLocallyEncryption")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
.onTapGesture {
if NCKeychain().passcode != nil {
model.requestPasscodeType("removeLocallyEncryption")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
}
}
}
#if DEBUG
deleteCerificateSection
#endif
}

} else {

List {
Section(header: Text(""), footer: Text(model.statusOfService + "\n\n" + "End-to-End Encryption " + model.capabilities.capabilityE2EEApiVersion)) {
let startE2EDesc1 = NSLocalizedString("_start_e2e_encryption_1_", comment: "");
let startE2EDesc2 = NSLocalizedString("_start_e2e_encryption_2_", comment: "");
let startE2EDesc3 = NSLocalizedString("_start_e2e_encryption_3_", comment: "");
let startE2EDesc = String(format: "%@\n\n%@\n\n%@",startE2EDesc1,startE2EDesc2,startE2EDesc3)
Section(header: Text(""), footer: Text(startE2EDesc)) {
HStack {
Label {
Text(NSLocalizedString("_e2e_settings_start_", comment: ""))
} icon: {
Image(systemName: "play.circle")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 25, height: 25)
.foregroundColor(.green)
}
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
if NCKeychain().passcode != nil {
if let passcode = NCKeychain().passcode {
model.requestPasscodeType("startE2E")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
}
}
}

#if DEBUG
deleteCerificateSection
#endif
}
.listStyle(GroupedListStyle())
}
}
.navigationBarTitle(NSLocalizedString("_e2e_settings_", comment: ""))
.navigationBarTitleDisplayMode(.inline)
.background(Color(UIColor.systemGroupedBackground))
.defaultViewModifier(model)
.onChange(of: model.navigateBack) { newValue in
if newValue {
presentationMode.wrappedValue.dismiss()
}
}
}

@ViewBuilder
Expand All @@ -144,7 +147,7 @@ struct NCManageE2EEView: View {
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 25, height: 25)
.foregroundColor(Color(NCBrandColor.shared.textColor2))
.foregroundColor(Color(UIColor.systemGray))
}
Spacer()
}
Expand All @@ -167,7 +170,7 @@ struct NCManageE2EEView: View {
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 25, height: 25)
.foregroundColor(Color(NCBrandColor.shared.textColor2))
.foregroundColor(Color(UIColor.systemGray))
}
Spacer()
}
Expand All @@ -186,5 +189,64 @@ struct NCManageE2EEView: View {
}

#Preview {
NCManageE2EEView(model: NCManageE2EE(controller: nil))
let controller = UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController
NCManageE2EEView(model: NCManageE2EE(controller: controller))
}

// MARK: - Preview / Test

struct SectionView: View {

@State var height: CGFloat = 0
@State var text: String = ""

var body: some View {
HStack {
Text(text)
}
.frame(maxWidth: .infinity, minHeight: height, alignment: .bottomLeading)
}
}

struct NCManageE2EEViewTest: View {

var body: some View {

VStack {
List {
Section(header: SectionView(height: 50, text: "Section Header View")) {
Label {
Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
} icon: {
Image(systemName: "checkmark.circle.fill")
.resizable()
.scaledToFit()
.frame(width: 25, height: 25)
.foregroundColor(.green)
}
}
Section(header: SectionView(text: "Section Header View 42")) {
Label {
Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
} icon: {
Image(systemName: "checkmark.circle.fill")
.resizable()
.scaledToFit()
.frame(width: 25, height: 25)
.foregroundColor(.red)
}
}
}
}
}
}

struct NCManageE2EEView_Previews: PreviewProvider {
static var previews: some View {

// swiftlint:disable force_cast
let controller = UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController
NCManageE2EEView(model: NCManageE2EE(controller: controller))
// swiftlint:enable force_cast
}
}
Loading