Skip to content

Commit f37b1be

Browse files
committed
MOPPIOS-1677 Fixes to CDOC2 Recipient info display, CDOC2 settings saving, and Encrypt flow.
1 parent f395e0d commit f37b1be

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
@@ -253,7 +253,8 @@ extension Container {
253253
tslUtil: self.tslUtil(),
254254
dataStore: self.dataStore(),
255255
proxyUtil: self.proxyUtil(),
256-
userAgentUtil: self.userAgentUtil()
256+
userAgentUtil: self.userAgentUtil(),
257+
cryptoSetup: self.cryptoSetup()
257258
)
258259
}
259260
}
@@ -322,7 +323,8 @@ extension Container {
322323
ProxySettingsViewModel(
323324
proxyUtil: self.proxyUtil(),
324325
userAgentUtil: self.userAgentUtil(),
325-
dataStore: self.dataStore()
326+
dataStore: self.dataStore(),
327+
cryptoSetup: self.cryptoSetup()
326328
)
327329
}
328330
}

RIADigiDoc/LibrarySetup.swift

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

118118
await cryptoSetup.setLdapConfig(configurationProvider)
119119
await cryptoSetup.setCdoc2Config(configurationProvider)
120-
await cryptoSetup.setCdoc2Settings(configurationProvider, nil)
120+
await cryptoSetup.setCdoc2Settings(configurationProvider)
121121

122122
try saveLDAPCertsToLibrary(ldapCertsBundle: configurationProvider?.ldapCerts)
123123
} 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",
@@ -1164,6 +1218,24 @@
11641218
}
11651219
}
11661220
},
1221+
"Digi-ID" : {
1222+
"comment" : "Certificate type",
1223+
"extractionState" : "manual",
1224+
"localizations" : {
1225+
"en" : {
1226+
"stringUnit" : {
1227+
"state" : "translated",
1228+
"value" : "Digi-ID"
1229+
}
1230+
},
1231+
"et" : {
1232+
"stringUnit" : {
1233+
"state" : "translated",
1234+
"value" : "Digi-ID"
1235+
}
1236+
}
1237+
}
1238+
},
11671239
"DigiDoc" : {
11681240
"comment" : "DigiDoc title on homesview",
11691241
"extractionState" : "manual",
@@ -1236,6 +1308,24 @@
12361308
}
12371309
}
12381310
},
1311+
"E-Resident" : {
1312+
"comment" : "Certificate type",
1313+
"extractionState" : "manual",
1314+
"localizations" : {
1315+
"en" : {
1316+
"stringUnit" : {
1317+
"state" : "translated",
1318+
"value" : "E-Resident"
1319+
}
1320+
},
1321+
"et" : {
1322+
"stringUnit" : {
1323+
"state" : "translated",
1324+
"value" : "E-Resident"
1325+
}
1326+
}
1327+
}
1328+
},
12391329
"Empty file in container" : {
12401330
"comment" : "Empty file message in container notifications",
12411331
"extractionState" : "manual",
@@ -1290,6 +1380,24 @@
12901380
}
12911381
}
12921382
},
1383+
"Encrypt general error" : {
1384+
"comment" : "CryptoContainer encrypt error message",
1385+
"extractionState" : "manual",
1386+
"localizations" : {
1387+
"en" : {
1388+
"stringUnit" : {
1389+
"state" : "translated",
1390+
"value" : "Container encryption was unsuccessful"
1391+
}
1392+
},
1393+
"et" : {
1394+
"stringUnit" : {
1395+
"state" : "needs_review",
1396+
"value" : "Ümbriku krüpteerimine ebaõnnestus"
1397+
}
1398+
}
1399+
}
1400+
},
12931401
"Enter current PIN code" : {
12941402
"comment" : "My eID current PIN or PUK code step title",
12951403
"extractionState" : "manual",
@@ -1865,6 +1973,24 @@
18651973
}
18661974
}
18671975
},
1976+
"ID-card" : {
1977+
"comment" : "Certificate type",
1978+
"extractionState" : "manual",
1979+
"localizations" : {
1980+
"en" : {
1981+
"stringUnit" : {
1982+
"state" : "translated",
1983+
"value" : "ID-card"
1984+
}
1985+
},
1986+
"et" : {
1987+
"stringUnit" : {
1988+
"state" : "translated",
1989+
"value" : "ID-kaart"
1990+
}
1991+
}
1992+
}
1993+
},
18681994
"ID-card via NFC" : {
18691995
"comment" : "ID-card via NFC signing method",
18701996
"extractionState" : "manual",
@@ -7495,6 +7621,24 @@
74957621
}
74967622
}
74977623
},
7624+
"Unknown" : {
7625+
"comment" : "Certificate type",
7626+
"extractionState" : "manual",
7627+
"localizations" : {
7628+
"en" : {
7629+
"stringUnit" : {
7630+
"state" : "translated",
7631+
"value" : "Unknown"
7632+
}
7633+
},
7634+
"et" : {
7635+
"stringUnit" : {
7636+
"state" : "translated",
7637+
"value" : "Tundmatu"
7638+
}
7639+
}
7640+
}
7641+
},
74987642
"Unknown signature" : {
74997643
"comment" : "Unknown signature message in container notifications",
75007644
"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)