Skip to content
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
12 changes: 11 additions & 1 deletion Modules/CryptoLib/Sources/CryptoObjC/include/Decrypt.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,17 @@ + (CdocInfo*)cdocInfo:(NSString *)fullPath error:(NSError**)error {
} else if(lock.isPKI()) {
[addressees addObject:[[Addressee alloc] initWithLabel:lock.label pub:[NSData dataFromVector:lock.getBytes(libcdoc::Lock::RCPT_KEY)] concatKDFAlgorithmURI:@""]];
} else if(lock.isSymmetric()) {
[addressees addObject:[[Addressee alloc] initWithData:[NSData data] cnVal:[NSString stringWithStdString:lock.label]]];
std::map<std::string, std::string> info = libcdoc::Recipient::parseLabel(lock.label);
NSString *cnVal = info.contains("label")
? [NSString stringWithStdString:info["label"]]
: @"";
[addressees addObject:[[Addressee alloc]
initWithCnVal:cnVal
serialNumber:nil
certType:CertTypePasswordType
validTo:nil
data:[NSData data]
concatKDFAlgorithmURI:@""]];
} else {
[addressees addObject:[[Addressee alloc] initWithData:[NSData data] cnVal:@"Unknown capsule"]];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import Foundation
concatKDFAlgorithmURI: String = ""
) {
let split = cnVal.split(separator: ",").map { String($0) }
if split.count > 1 {
if split.count >= 3 {
surname = split[0]
givenName = split[1]
identifier = split[2]
Expand All @@ -92,7 +92,7 @@ import Foundation
data = cert
let cnVal = x509?.subject(oid: .commonName)?.joined(separator: ",") ?? ""
let split = cnVal.split(separator: ",").map { String($0) }
if split.count > 1 {
if split.count >= 3 {
surname = split[0]
givenName = split[1]
identifier = split[2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import ASN1Decoder
case mobileIDType
case smartIDType
case eSealType
case passwordType
}

extension X509Certificate {
Expand Down
45 changes: 45 additions & 0 deletions Modules/CryptoLib/Sources/CryptoSwift/CryptoContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,51 @@ extension CryptoContainer {
)
}

@MainActor
public static func decryptWithPassword(
containerFile: URL,
recipients: [Addressee],
password: String,
fileManager: FileManagerProtocol = Container.shared.fileManager()
) async throws -> CryptoContainerProtocol {
let path = containerFile.resolvedPath
let decryptedData: [String: Data] = try await withCheckedThrowingContinuation { continuation in
DispatchQueue.global(qos: .userInitiated).async {
do {
let result = try Decrypt.decryptFile(path, withPassword: password)
continuation.resume(returning: result)
} catch {
continuation.resume(throwing: error)
}
}
}

var urlDataFiles: [URL] = []
for dataFile in decryptedData {
let sanitizedName = dataFile.key.sanitized()
let destinationPath = try Directories.getCacheDirectory(
subfolders: [Constants.Folder.ContainerFolder, Constants.Folder.Temp],
fileManager: fileManager
)
let fileUrl = destinationPath.appending(path: sanitizedName, directoryHint: .notDirectory)
urlDataFiles.append(fileUrl)
let isCreated = fileManager.createFile(
atPath: fileUrl.resolvedPath, contents: dataFile.value, attributes: nil
)
if !isCreated {
CryptoContainer.logger().error("Unable to create file at path: \(destinationPath.resolvedPath)")
}
}

return try await create(
containerFile: containerFile,
dataFiles: urlDataFiles,
recipients: recipients,
isDecrypted: true,
isEncrypted: false
)
}

@MainActor
public static func encrypt(
containerFile: URL,
Expand Down
23 changes: 23 additions & 0 deletions RIADigiDoc/Domain/Model/Crypto/EncryptRecipientViewTab.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2017 - 2026 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
*
*/

enum EncryptRecipientViewTab: Int, Sendable {
case recipient = 0
case password = 1
}
2 changes: 1 addition & 1 deletion RIADigiDoc/Domain/Model/Crypto/EncryptViewTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

enum EncryptViewTab: Int, Sendable {
public enum EncryptViewTab: Int, Sendable {
case files = 0
case recipients = 1
}
2 changes: 1 addition & 1 deletion RIADigiDoc/Domain/Model/EncryptionCdocOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

public enum EncryptionCdocOption: Int, Sendable {
public enum EncryptionCdocOption: Int, Sendable, Hashable {
case cdoc1 = 0
case cdoc2 = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum NavigationDestination: Hashable {
extensions: [String]
)

case encryptRecipientView
case encryptRecipientView(cdocOption: EncryptionCdocOption)

case signingView
case signatureDetailView(
Expand All @@ -51,8 +51,11 @@ public enum NavigationDestination: Hashable {
)

case encryptView(
isWithEncryption: Bool
isWithEncryption: Bool,
cdocOption: EncryptionCdocOption,
selectedTab: EncryptViewTab
)

case recipientDetailView(
recipient: Addressee,
)
Expand Down
Loading
Loading