Skip to content

Commit 44edcff

Browse files
authored
Fixes to CDOC2 Recipient info display, CDOC2 settings saving, and Encrypt flow. (#140)
MOPPIOS-1677 Fixes to CDOC2 Recipient info display. MOPPIOS-1677 Fixes to CDOC2 settings saving. MOPPIOS-1677 Fixes to Decrypt and Encrypt flow.
1 parent 7b1d10c commit 44edcff

13 files changed

Lines changed: 238 additions & 39 deletions

File tree

Modules/CryptoLib/Sources/CryptoObjC/include/Decrypt.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ @implementation Addressee (label)
3333
- (instancetype)initWithLabel:(const std::string &)label pub:(NSData*)pub concatKDFAlgorithmURI:(NSString *)concatKDFAlgorithmURI {
3434
std::map<std::string, std::string> info = libcdoc::Recipient::parseLabel(label);
3535
id cn = info.contains("cn") ? [NSString stringWithStdString:info["cn"]] : nil;
36-
id first = info.contains("first_name") ? [NSString stringWithStdString:info["first_name"]] : nil;
37-
id last = info.contains("last_name") ? [NSString stringWithStdString:info["last_name"]] : nil;
36+
id type = info.contains("last_name") ? [NSString stringWithStdString:info["type"]] : nil;
3837
id serial = info.contains("serial_number") ? [NSString stringWithStdString:info["serial_number"]] : nil;
39-
id type = info.contains("type") ? [NSString stringWithStdString:info["type"]] : nil;
4038
CertType certType = CertTypeUnknownType;
41-
if ([type isEqualToString:@"ID-card"]) {
39+
if ([type isEqualToString:@"ID-card"] || [type isEqualToString:@"cert"]) {
4240
certType = CertTypeIDCardType;
4341
} else if ([type isEqualToString:@"Digi-ID"]) {
4442
certType = CertTypeDigiIDType;
4543
} else if ([type isEqualToString:@"Digi-ID E-RESIDENT"]) {
4644
certType = CertTypeEResidentType;
45+
} else if (type == nil) {
46+
certType = CertTypeESealType;
4747
}
4848
id validTo = nil;
4949
if (info.contains("server_exp")) {
5050
long long epochTime = [[NSString stringWithStdString:info["server_exp"]] longLongValue];
5151
validTo = [NSDate dateWithTimeIntervalSince1970:epochTime];
5252
}
53-
if (self = [self initWithData:pub cnVal:cn givenName:first surname:last serialNumber:serial certType:certType validTo:validTo concatKDFAlgorithmURI:concatKDFAlgorithmURI]) {
53+
if (self = [self initWithCnVal:cn serialNumber:serial certType:certType validTo:validTo data:pub concatKDFAlgorithmURI:concatKDFAlgorithmURI]) {
5454
}
5555
return self;
5656
}

Modules/CryptoLib/Sources/CryptoObjCWrapper/Domain/Addressee.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ import Foundation
6363
)
6464
}
6565

66+
@objc public init(
67+
cnVal: String,
68+
serialNumber: String?,
69+
certType: CertType,
70+
validTo: Date?,
71+
data: Data,
72+
concatKDFAlgorithmURI: String = ""
73+
) {
74+
let split = cnVal.split(separator: ",").map { String($0) }
75+
if split.count > 1 {
76+
surname = split[0]
77+
givenName = split[1]
78+
identifier = split[2]
79+
} else {
80+
surname = nil
81+
givenName = nil
82+
identifier = cnVal
83+
}
84+
self.serialNumber = serialNumber
85+
self.certType = certType
86+
self.validTo = validTo
87+
self.data = data
88+
self.concatKDFAlgorithmURI = concatKDFAlgorithmURI
89+
}
90+
6691
public init(cert: Data, x509: X509Certificate?) {
6792
data = cert
6893
let cnVal = x509?.subject(oid: .commonName)?.joined(separator: ",") ?? ""

RIADigiDoc/CryptoSetup.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ actor CryptoSetup: CryptoSetupProtocol {
101101
}
102102
}
103103

104-
public func setCdoc2Settings(_ configurationProvider: ConfigurationProvider?, _ certData: Data? = nil) async {
104+
public func setCdoc2Settings(_ configurationProvider: ConfigurationProvider?) async {
105105
var defaultUseCdoc2Encryption = Constants.CryptoDefaultValues.encryptionUseCdoc2
106106
if let useCdoc2Encryption = configurationProvider?.cdoc2Default {
107107
defaultUseCdoc2Encryption = useCdoc2Encryption
@@ -129,8 +129,23 @@ actor CryptoSetup: CryptoSetupProtocol {
129129
Decrypt.setCdoc2Config(cdoc2Conf.asNSDictionary())
130130
}
131131

132+
if let certBundle = configurationProvider?.certBundle {
133+
Encrypt.setCerts(certBundle)
134+
Decrypt.setCerts(certBundle)
135+
}
136+
132137
let proxyInfo = await proxyUtil.getProxyInfo()
138+
await setCdoc2ProxyInfo(proxyInfo)
139+
}
140+
141+
public func setCdoc2CustomCert(_ certData: Data? = nil) async {
142+
if let certData {
143+
Encrypt.setCert(certData)
144+
Decrypt.setCert(certData)
145+
}
146+
}
133147

148+
public func setCdoc2ProxyInfo(_ proxyInfo: ProxyInfo) async {
134149
Encrypt.setProxy(
135150
proxyInfo.host,
136151
port: proxyInfo.port,
@@ -144,16 +159,5 @@ actor CryptoSetup: CryptoSetupProtocol {
144159
username: proxyInfo.username,
145160
password: proxyInfo.password
146161
)
147-
148-
if let certBundle = configurationProvider?.certBundle {
149-
Encrypt.setCerts(certBundle)
150-
Decrypt.setCerts(certBundle)
151-
}
152-
153-
if let certData {
154-
Encrypt.setCert(certData)
155-
Decrypt.setCert(certData)
156-
}
157162
}
158-
159163
}

RIADigiDoc/CryptoSetupProtocol.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
*/
1919

2020
import Foundation
21+
import CommonsLib
2122
import ConfigLib
2223

2324
/// @mockable
2425
public protocol CryptoSetupProtocol: Sendable {
2526
func setLdapConfig(_ configurationProvider: ConfigurationProvider?) async
2627
func setCdoc2Config(_ configurationProvider: ConfigurationProvider?) async
27-
func setCdoc2Settings(_ configurationProvider: ConfigurationProvider?, _ certData: Data?) async
28+
func setCdoc2Settings(_ configurationProvider: ConfigurationProvider?) async
29+
func setCdoc2CustomCert(_ certData: Data?) async
30+
func setCdoc2ProxyInfo(_ proxyInfo: ProxyInfo) async
2831
}

RIADigiDoc/DI/AppContainer.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ extension Container {
255255
dataStore: self.dataStore(),
256256
proxyUtil: self.proxyUtil(),
257257
userAgentUtil: self.userAgentUtil(),
258-
fileUtil: self.fileUtil()
258+
fileUtil: self.fileUtil(),
259+
cryptoSetup: self.cryptoSetup()
259260
)
260261
}
261262
}
@@ -324,7 +325,8 @@ extension Container {
324325
ProxySettingsViewModel(
325326
proxyUtil: self.proxyUtil(),
326327
userAgentUtil: self.userAgentUtil(),
327-
dataStore: self.dataStore()
328+
dataStore: self.dataStore(),
329+
cryptoSetup: self.cryptoSetup()
328330
)
329331
}
330332
}

RIADigiDoc/LibrarySetup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ actor LibrarySetup: Loggable {
124124

125125
await cryptoSetup.setLdapConfig(configurationProvider)
126126
await cryptoSetup.setCdoc2Config(configurationProvider)
127-
await cryptoSetup.setCdoc2Settings(configurationProvider, nil)
127+
await cryptoSetup.setCdoc2Settings(configurationProvider)
128128

129129
try saveLDAPCertsToLibrary(ldapCertsBundle: configurationProvider?.ldapCerts)
130130
} catch let error {

RIADigiDoc/Supporting files/Localizable.xcstrings

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,42 @@
287287
}
288288
}
289289
},
290+
"Cannot create an empty crypto container" : {
291+
"comment" : "CryptoContainer empty error message",
292+
"extractionState" : "manual",
293+
"localizations" : {
294+
"en" : {
295+
"stringUnit" : {
296+
"state" : "translated",
297+
"value" : "Cannot create an empty crypto container"
298+
}
299+
},
300+
"et" : {
301+
"stringUnit" : {
302+
"state" : "translated",
303+
"value" : "Ei saa luua tühja krüptokonteinerit"
304+
}
305+
}
306+
}
307+
},
308+
"Cannot create crypto container without recipients" : {
309+
"comment" : "CryptoContainer no recipients error message",
310+
"extractionState" : "manual",
311+
"localizations" : {
312+
"en" : {
313+
"stringUnit" : {
314+
"state" : "translated",
315+
"value" : "Cannot create crypto container without recipients"
316+
}
317+
},
318+
"et" : {
319+
"stringUnit" : {
320+
"state" : "translated",
321+
"value" : "Ei saa luua krüptokonteinerit ilma adressaatideta"
322+
}
323+
}
324+
}
325+
},
290326
"Certificate details" : {
291327
"comment" : "Title of Certificate Details view",
292328
"localizations" : {
@@ -304,6 +340,24 @@
304340
}
305341
}
306342
},
343+
"Certificate for Encryption" : {
344+
"comment" : "Certificate type",
345+
"extractionState" : "manual",
346+
"localizations" : {
347+
"en" : {
348+
"stringUnit" : {
349+
"state" : "translated",
350+
"value" : "Certificate for Encryption"
351+
}
352+
},
353+
"et" : {
354+
"stringUnit" : {
355+
"state" : "translated",
356+
"value" : "Krüpteerimissertifikaat"
357+
}
358+
}
359+
}
360+
},
307361
"Certificate has expired" : {
308362
"comment" : "OperationAuthenticateWithWebEID Certificate validity check",
309363
"extractionState" : "manual",
@@ -1272,6 +1326,24 @@
12721326
}
12731327
}
12741328
},
1329+
"Digi-ID" : {
1330+
"comment" : "Certificate type",
1331+
"extractionState" : "manual",
1332+
"localizations" : {
1333+
"en" : {
1334+
"stringUnit" : {
1335+
"state" : "translated",
1336+
"value" : "Digi-ID"
1337+
}
1338+
},
1339+
"et" : {
1340+
"stringUnit" : {
1341+
"state" : "translated",
1342+
"value" : "Digi-ID"
1343+
}
1344+
}
1345+
}
1346+
},
12751347
"DigiDoc" : {
12761348
"comment" : "DigiDoc title on homesview",
12771349
"extractionState" : "manual",
@@ -1344,6 +1416,24 @@
13441416
}
13451417
}
13461418
},
1419+
"E-Resident" : {
1420+
"comment" : "Certificate type",
1421+
"extractionState" : "manual",
1422+
"localizations" : {
1423+
"en" : {
1424+
"stringUnit" : {
1425+
"state" : "translated",
1426+
"value" : "E-Resident"
1427+
}
1428+
},
1429+
"et" : {
1430+
"stringUnit" : {
1431+
"state" : "translated",
1432+
"value" : "E-Resident"
1433+
}
1434+
}
1435+
}
1436+
},
13471437
"Empty file in container" : {
13481438
"comment" : "Empty file message in container notifications",
13491439
"extractionState" : "manual",
@@ -1398,6 +1488,24 @@
13981488
}
13991489
}
14001490
},
1491+
"Encrypt general error" : {
1492+
"comment" : "CryptoContainer encrypt error message",
1493+
"extractionState" : "manual",
1494+
"localizations" : {
1495+
"en" : {
1496+
"stringUnit" : {
1497+
"state" : "translated",
1498+
"value" : "Container encryption was unsuccessful"
1499+
}
1500+
},
1501+
"et" : {
1502+
"stringUnit" : {
1503+
"state" : "needs_review",
1504+
"value" : "Ümbriku krüpteerimine ebaõnnestus"
1505+
}
1506+
}
1507+
}
1508+
},
14011509
"Enter current PIN code" : {
14021510
"comment" : "My eID current PIN or PUK code step title",
14031511
"extractionState" : "manual",
@@ -1973,6 +2081,24 @@
19732081
}
19742082
}
19752083
},
2084+
"ID-card" : {
2085+
"comment" : "Certificate type",
2086+
"extractionState" : "manual",
2087+
"localizations" : {
2088+
"en" : {
2089+
"stringUnit" : {
2090+
"state" : "translated",
2091+
"value" : "ID-card"
2092+
}
2093+
},
2094+
"et" : {
2095+
"stringUnit" : {
2096+
"state" : "translated",
2097+
"value" : "ID-kaart"
2098+
}
2099+
}
2100+
}
2101+
},
19762102
"ID-card via NFC" : {
19772103
"comment" : "ID-card via NFC signing method",
19782104
"extractionState" : "manual",
@@ -7675,6 +7801,24 @@
76757801
}
76767802
}
76777803
},
7804+
"Unknown" : {
7805+
"comment" : "Certificate type",
7806+
"extractionState" : "manual",
7807+
"localizations" : {
7808+
"en" : {
7809+
"stringUnit" : {
7810+
"state" : "translated",
7811+
"value" : "Unknown"
7812+
}
7813+
},
7814+
"et" : {
7815+
"stringUnit" : {
7816+
"state" : "translated",
7817+
"value" : "Tundmatu"
7818+
}
7819+
}
7820+
}
7821+
},
76787822
"Unknown signature" : {
76797823
"comment" : "Unknown signature message in container notifications",
76807824
"extractionState" : "manual",

RIADigiDoc/UI/Component/Container/Crypto/EncryptView.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,8 @@ struct EncryptView: View {
364364
await updateAsyncLabels()
365365
await viewModel.updateAsyncProperties()
366366

367-
Toast.show(languageSettings.localized(
368-
"Container successfully encrypted"
369-
))
370-
371367
encryptionButtonEnabled = true
368+
isWithEncryption = false
372369
}
373370
}
374371
}
@@ -407,10 +404,6 @@ struct EncryptView: View {
407404
await updateAsyncLabels()
408405
await viewModel.updateAsyncProperties()
409406

410-
Toast.show(languageSettings.localized(
411-
"Container successfully encrypted"
412-
))
413-
414407
encryptionButtonEnabled = true
415408
isWithEncryption = false
416409
} else if isWithDecryption {
@@ -479,12 +472,19 @@ struct EncryptView: View {
479472
.animation(.easeInOut, value: showRenameModal)
480473
.onChange(of: viewModel.errorMessage) { _, error in
481474
guard let error else { return }
482-
Toast.show(String(
483-
format: languageSettings.localized(error.key),
484-
error.args.joined(separator: ", "))
475+
Toast.show(
476+
languageSettings.localized(error.key, [error.args.joined(separator: ", ")])
485477
)
478+
viewModel.resetErrorMessage()
486479
encryptionButtonEnabled = true
487480
}
481+
.onChange(of: viewModel.successMessage) { _, message in
482+
guard let message else { return }
483+
Toast.show(
484+
languageSettings.localized(message.key, [message.args.joined(separator: ", ")])
485+
)
486+
viewModel.resetSuccessMessage()
487+
}
488488
}
489489

490490
func updateAsyncLabels() async {

0 commit comments

Comments
 (0)