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
11 changes: 10 additions & 1 deletion RIADigiDoc/Domain/NFC/NFCOperationBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ public class NFCOperationBase: NSObject, Loggable, @MainActor NFCTagReaderSessio
nfcError = strings?.technicalErrorMessage ?? ""
}
}


func handleNoCertLockError(
error: Error,
session: NFCTagReaderSession
) {
Self.logger().error("NFC: Failed to find lock for cert")
nfcError = strings?.wrongCardErrorMessage ?? ""
session.invalidate(errorMessage: nfcError)
}

func handleIdCardInternalError(
_ error: IdCardInternalError,
session: NFCTagReaderSession
Expand Down
1 change: 1 addition & 0 deletions RIADigiDoc/Domain/NFC/NFCSessionStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public struct NFCSessionStrings: Sendable {
let pinWrongMultipleErrorMessage: String
let pinWrongErrorMessage: String
let pinBlockedErrorMessage: String
let wrongCardErrorMessage: String
let technicalErrorMessage: String
let sessionErrorMessage: String
let ocspTimeslotErrorMessage: String
Expand Down
2 changes: 2 additions & 0 deletions RIADigiDoc/Domain/NFC/NFCSessionStringsUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public struct NFCSessionStringsUtil {
pinWrongMultipleErrorMessage: String? = nil,
pinWrongErrorMessage: String? = nil,
pinBlockedErrorMessage: String? = nil,
wrongCardErrorMessage: String? = nil,
technicalErrorMessage: String? = nil,
sessionErrorMessage: String? = nil,
ocspTimeslotErrorMessage: String? = nil,
Expand Down Expand Up @@ -103,6 +104,7 @@ public struct NFCSessionStringsUtil {
"PIN blocked",
[pinAction == .unblock ? CodeType.puk.name : pinName]
),
wrongCardErrorMessage: wrongCardErrorMessage ?? localize("Failed to find lock for cert", []),
technicalErrorMessage: technicalErrorMessage ?? localize("NFC technical error", []),
sessionErrorMessage: sessionErrorMessage ?? localize("NFC session error", []),
ocspTimeslotErrorMessage: ocspTimeslotErrorMessage ?? localize("OCSP response not in valid time slot", []),
Expand Down
5 changes: 5 additions & 0 deletions RIADigiDoc/Domain/NFC/OperationChangePin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class OperationChangePin: NFCOperationBase, OperationChangePinProtocol {

success()
} catch {
if (error as NSError).localizedDescription == "Failed to find lock for cert" {
handleNoCertLockError(error: error, session: session)
return
}

if let idCardInternalError = error as? IdCardInternalError {
handleIdCardInternalError(idCardInternalError, session: session)
return
Expand Down
5 changes: 5 additions & 0 deletions RIADigiDoc/Domain/NFC/OperationDecrypt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public class OperationDecrypt: NFCOperationBase, OperationDecryptProtocol {

success()
} catch {
if (error as NSError).localizedDescription == "Failed to find lock for cert" {
handleNoCertLockError(error: error, session: session)
return
}

if let idCardInternalError = error as? IdCardInternalError {
handleIdCardInternalError(idCardInternalError, session: session)
return
Expand Down
5 changes: 5 additions & 0 deletions RIADigiDoc/Domain/NFC/OperationReadCardData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ final public class OperationReadCardData: NFCOperationBase, OperationReadCardDat

success()
} catch {
if (error as NSError).localizedDescription == "Failed to find lock for cert" {
handleNoCertLockError(error: error, session: session)
return
}

if let idCardInternalError = error as? IdCardInternalError {
handleIdCardInternalError(idCardInternalError, session: session)
return
Expand Down
5 changes: 5 additions & 0 deletions RIADigiDoc/Domain/NFC/OperationReadCertAndSign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ public class OperationReadCertAndSign: NFCOperationBase, OperationReadCertAndSig

success()
} catch {
if (error as NSError).localizedDescription == "Failed to find lock for cert" {
handleNoCertLockError(error: error, session: session)
return
}

if let idCardInternalError = error as? IdCardInternalError {
handleIdCardInternalError(idCardInternalError, session: session)
return
Expand Down
5 changes: 5 additions & 0 deletions RIADigiDoc/Domain/NFC/OperationUnblockPin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class OperationUnblockPin: NFCOperationBase, OperationUnblockPinProtocol

success()
} catch {
if (error as NSError).localizedDescription == "Failed to find lock for cert" {
handleNoCertLockError(error: error, session: session)
return
}

if let idCardInternalError = error as? IdCardInternalError {
handleIdCardInternalError(idCardInternalError, session: session)
return
Expand Down
18 changes: 18 additions & 0 deletions RIADigiDoc/Supporting files/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,24 @@
}
}
},
"Failed to find lock for cert" : {
"comment" : "Decrypting with ID-card not in recipient list",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Failed to find lock for cert"
}
},
"et" : {
"stringUnit" : {
"state" : "translated",
"value" : "Sertifikaadi võtmega lukku ei leitud"
}
}
}
},
"Failed to open container" : {
"comment" : "Error message when unable to create a new container",
"extractionState" : "manual",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ struct IdCardView: View {
await MainActor.run {
Toast.show(errorMessage)
viewModel.resetErrors()
resetIdCardAction()
if shouldDismiss {
dismiss()
}
Expand All @@ -198,6 +199,7 @@ struct IdCardView: View {

await viewModel.stopDiscoveringReaders()
cancelIdCardAction()
resetIdCardAction()
isInProgress = false
isShowingPinView = false
isShowingLoadingView = false
Expand Down Expand Up @@ -388,6 +390,7 @@ struct IdCardView: View {
await MainActor.run {
Toast.show(errorMessage)
viewModel.resetErrors()
resetIdCardAction()

// Let ID-card alert closure handle dismiss
// Dismiss is run when user has pressed OK button on alert
Expand Down Expand Up @@ -416,7 +419,6 @@ struct IdCardView: View {
pinNumber.isEmpty ? () : (pinNumber.removeAll())
isActionEnabled = viewModel
.isActionEnabled(pinNumber: pinNumber, pinType: pinCodeType)
resetIdCardAction()
}

private func resetIdCardAction() {
Expand Down Expand Up @@ -461,6 +463,7 @@ struct IdCardView: View {
await MainActor.run {
Toast.show(errorMessage)
viewModel.resetErrors()
resetIdCardAction()
if shouldDismiss {
dismiss()
}
Expand Down
22 changes: 16 additions & 6 deletions RIADigiDoc/ViewModel/Signing/IdCard/IdCardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ class IdCardViewModel: IdCardViewModelProtocol, Loggable {
return container
} catch {
IdCardViewModel.logger().error("ID-CARD: Unable to decrypt container with ID-card reader. \(error)")

let nsError = error as NSError
if nsError.localizedDescription == "Failed to find lock for cert" {
IdCardViewModel.logger().error("ID-CARD: Failed to find lock for cert")
errorMessage = "Failed to find lock for cert"
errorExtraArguments = []
shouldDismissForError = true
return nil
}

guard let exception = error as? IdCardInternalError else {
IdCardViewModel.logger().error("ID-CARD: ID Card General error.")
errorMessage = "General error"
Expand Down Expand Up @@ -195,19 +205,19 @@ class IdCardViewModel: IdCardViewModelProtocol, Loggable {
let pinResponse = try await readCodeTryCounterRecord()
let isPUKChangeable = try await isPukChangeable()

if codeType == CodeType.pin1 {
if codeType == .pin1 {
if pinResponse.pin1RetryCount == 0 {
throw IdCardInternalError.remainingPinRetryCount(0)
}
}
if codeType == CodeType.pin2 {
if codeType == .pin2 {
if pinResponse.pin2RetryCount == 0 {
throw IdCardInternalError.remainingPinRetryCount(0)
}
}

if !pinResponse.pin2Active {
throw IdCardInternalError.pinLocked
if !pinResponse.pin2Active {
throw IdCardInternalError.pinLocked
}
}

return IdCardData(
Expand Down
Loading