From 4c2023b4526dcb0bc9c686a96b6ca9c2e21e83c0 Mon Sep 17 00:00:00 2001 From: Marten Rebane <54431068+martenrebane@users.noreply.github.com> Date: Thu, 13 Jun 2024 12:15:01 +0300 Subject: [PATCH] Fixes --- MoppApp/MoppApp.xcodeproj/project.pbxproj | 4 --- .../MoppApp/Extensions/URL+Additions.swift | 30 ------------------- MoppApp/MoppApp/FileManager.swift | 13 -------- MoppApp/MoppApp/MimeTypeExtractor.swift | 16 ---------- MoppApp/MoppApp/MoppApp.swift | 12 -------- 5 files changed, 75 deletions(-) delete mode 100644 MoppApp/MoppApp/Extensions/URL+Additions.swift diff --git a/MoppApp/MoppApp.xcodeproj/project.pbxproj b/MoppApp/MoppApp.xcodeproj/project.pbxproj index fb35cef0..1bd5e064 100644 --- a/MoppApp/MoppApp.xcodeproj/project.pbxproj +++ b/MoppApp/MoppApp.xcodeproj/project.pbxproj @@ -253,7 +253,6 @@ DFDF02BE241EB5D3006CF443 /* SessionCertificate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFDF02BD241EB5D3006CF443 /* SessionCertificate.swift */; }; DFDF02C0241EC72D006CF443 /* SessionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFDF02BF241EC72C006CF443 /* SessionStatus.swift */; }; DFDF02C4241ED0CA006CF443 /* MobileIDSignature.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFDF02C3241ED0CA006CF443 /* MobileIDSignature.swift */; }; - DFE7B68A2C191A1200C598FC /* URL+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFE7B6892C191A1200C598FC /* URL+Additions.swift */; }; DFEE73042A151423003428E4 /* ScaledTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFEE73032A151423003428E4 /* ScaledTextView.swift */; }; DFEFF8DD2AD6DCE3003D452B /* TokenFlowSigning.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFEFF8DC2AD6DCE3003D452B /* TokenFlowSigning.swift */; }; DFF3C3AE233231190079458A /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFF3C3AC233231180079458A /* Configuration.swift */; }; @@ -605,7 +604,6 @@ DFDF02BD241EB5D3006CF443 /* SessionCertificate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionCertificate.swift; sourceTree = ""; }; DFDF02BF241EC72C006CF443 /* SessionStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionStatus.swift; sourceTree = ""; }; DFDF02C3241ED0CA006CF443 /* MobileIDSignature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobileIDSignature.swift; sourceTree = ""; }; - DFE7B6892C191A1200C598FC /* URL+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Additions.swift"; sourceTree = ""; }; DFEE73032A151423003428E4 /* ScaledTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScaledTextView.swift; sourceTree = ""; }; DFEEFCCD29AD062C0013E66B /* DiagnosticError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiagnosticError.swift; sourceTree = ""; }; DFEFF8DC2AD6DCE3003D452B /* TokenFlowSigning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenFlowSigning.swift; sourceTree = ""; }; @@ -734,7 +732,6 @@ DFF3C3B4233231F20079458A /* Notification+Additions.swift */, DF13562D2902018A00F61823 /* MoppApp+Additions.swift */, DF8A948929AFD11A004F6E4B /* CharacterSet+Additions.swift */, - DFE7B6892C191A1200C598FC /* URL+Additions.swift */, ); path = Extensions; sourceTree = ""; @@ -1682,7 +1679,6 @@ C593D9F0208F1C16000B3BF6 /* SettingsFieldCell.swift in Sources */, C593D9E8208F1986000B3BF6 /* SettingsViewController.swift in Sources */, DFBDF20227DF7ED700A5CF3C /* IDCardSignature.swift in Sources */, - DFE7B68A2C191A1200C598FC /* URL+Additions.swift in Sources */, C54EA6E520444EC90039AC78 /* TokenFlowSelectionViewController.swift in Sources */, DFF3C3B32332314A0079458A /* SignatureVerifier.swift in Sources */, DF17ABCE29C0F86E009711DF /* BarButton.swift in Sources */, diff --git a/MoppApp/MoppApp/Extensions/URL+Additions.swift b/MoppApp/MoppApp/Extensions/URL+Additions.swift deleted file mode 100644 index 89ca5623..00000000 --- a/MoppApp/MoppApp/Extensions/URL+Additions.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// URL+Additions.swift -// MoppApp -// -/* - * Copyright 2017 - 2024 Riigi Infosüsteemi Amet - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -import Foundation - -extension URL { - func isValidPath() -> Bool { - return !self.pathComponents.contains("..") - } -} diff --git a/MoppApp/MoppApp/FileManager.swift b/MoppApp/MoppApp/FileManager.swift index 361e1df2..b003f767 100644 --- a/MoppApp/MoppApp/FileManager.swift +++ b/MoppApp/MoppApp/FileManager.swift @@ -311,11 +311,6 @@ class MoppFileManager { func removeFile(withPath filePath: String) { let filePathURL = URL(fileURLWithPath: filePath) - guard filePathURL.isValidPath() else { - printLog("Unable to remove file. Invalid path: \(filePathURL.path)") - return - } - do { try fileManager.removeItem(atPath: FileUtil.getValidPath(url: filePathURL)?.path ?? "") } catch { @@ -333,10 +328,6 @@ class MoppFileManager { func fileExists(_ sourcePath: String) -> Bool { let sourcePathURL = URL(fileURLWithPath: sourcePath) - guard sourcePathURL.isValidPath() else { - printLog("Unable to check if file exists. Invalid path: \(sourcePathURL.path)") - return false - } return fileManager.fileExists(atPath: FileUtil.getValidPath(url: sourcePathURL)?.path ?? "") } @@ -349,10 +340,6 @@ class MoppFileManager { func moveFile(withPath sourcePath: String, toPath destinationPath: String, overwrite: Bool) -> Bool { let sourcePathURL = URL(fileURLWithPath: sourcePath) let destinationPathURL = URL(fileURLWithPath: destinationPath) - guard sourcePathURL.isValidPath() && destinationPathURL.isValidPath() else { - printLog("Unable to move file to destination. Invalid path: \(sourcePathURL.path) or \(destinationPathURL.path)") - return false - } if overwrite && fileExists(FileUtil.getValidPath(url: destinationPathURL)?.path ?? "") { removeFile(withPath: FileUtil.getValidPath(url: destinationPathURL)?.path ?? "") } diff --git a/MoppApp/MoppApp/MimeTypeExtractor.swift b/MoppApp/MoppApp/MimeTypeExtractor.swift index e2118c6c..b38e12df 100644 --- a/MoppApp/MoppApp/MimeTypeExtractor.swift +++ b/MoppApp/MoppApp/MimeTypeExtractor.swift @@ -185,22 +185,11 @@ class MimeTypeExtractor { } private static func removeUnzippedFolder(folderPath: URL) -> Void { - guard folderPath.isValidPath() else { - printLog("Unable to remove unzipped folder. Invalid path: \(folderPath.path)") - return - } - MoppFileManager().removeFile(withPath: FileUtil.getValidPath(url: folderPath)?.path ?? "") } private static func isDdoc(url: URL) -> Bool { - guard url.isValidPath(), FileUtil.getValidPath(url: url) != nil else { - printLog("Unable to check if file is DDOC container. Invalid path: \(url.path)") - return false - } - do { - let fileData = try Data(contentsOf: FileUtil.getValidPath(url: url)!) guard !fileData.isEmpty else { return false @@ -224,11 +213,6 @@ class MimeTypeExtractor { } private static func isCdoc(url: URL) -> Bool { - guard url.isValidPath(), FileUtil.getValidPath(url: url) != nil else { - printLog("Unable to check if file is CDOC container. Invalid path: \(url.path)") - return false - } - do { let fileData = try Data(contentsOf: FileUtil.getValidPath(url: url)!) guard !fileData.isEmpty else { diff --git a/MoppApp/MoppApp/MoppApp.swift b/MoppApp/MoppApp/MoppApp.swift index 49ae8d9a..d3d63cd6 100644 --- a/MoppApp/MoppApp/MoppApp.swift +++ b/MoppApp/MoppApp/MoppApp.swift @@ -323,10 +323,6 @@ class MoppApp: UIApplication, URLSessionDelegate, URLSessionDownloadDelegate { pathExtension = MimeTypeExtractor.determineContainer(mimetype: MimeTypeExtractor.getMimeTypeFromContainer(filePath: newUrl), fileExtension: newUrl.pathExtension) do { - guard newUrl.isValidPath(), FileUtil.getValidPath(url: url) != nil else { - printLog("Unable to open file. Invalid path: \(newUrl.path)") - return false - } let validUrl = FileUtil.getValidPath(url: url)! let newData: Data? = try Data(contentsOf: validUrl) let fileName: String = validUrl.deletingPathExtension().lastPathComponent.sanitize() @@ -344,10 +340,6 @@ class MoppApp: UIApplication, URLSessionDelegate, URLSessionDownloadDelegate { return false } do { - guard filePath.isValidPath(), FileUtil.getValidPath(url: url) != nil else { - printLog("Unable to write to file. Invalid path: \(filePath.path)") - return false - } try newUrlData.write(to: FileUtil.getValidPath(url: filePath)!, options: .atomic) newUrl = validUrl if !isFileEmpty { @@ -376,10 +368,6 @@ class MoppApp: UIApplication, URLSessionDelegate, URLSessionDownloadDelegate { newUrl.deletePathExtension() newUrl.appendPathExtension(ContainerFormatCdoc) } - guard url.isValidPath(), newUrl.isValidPath() else { - printLog("Unable to move file. Invalid path: \(newUrl.path)") - return false - } let isFileMoved = MoppFileManager.shared.moveFile(withPath: FileUtil.getValidPath(url: url)?.path ?? "", toPath: FileUtil.getValidPath(url: newUrl)?.path ?? "", overwrite: true) if !isFileMoved { newUrl = url