Skip to content

Commit

Permalink
Merge pull request #473 from martenrebane/MOPPIOS-1287
Browse files Browse the repository at this point in the history
Replace too many requests error
  • Loading branch information
Counter178 authored Feb 2, 2024
2 parents 93ecdc4 + e950c14 commit 06eb5ed
Show file tree
Hide file tree
Showing 361 changed files with 196 additions and 90,480 deletions.
42 changes: 37 additions & 5 deletions MoppApp/MoppApp/AlertUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,53 @@ class AlertUtil {
static func errorMessageDialog(_ notification: Notification, topViewController: UIViewController) {
guard let userInfo = notification.userInfo else { return }
let error = userInfo[kErrorKey] as? NSError
let signingErrorMessage = (error as? SigningError)?.signingErrorDescription
let signingErrorMessage = (error as? SigningError)?.errorDescription
let signingError = error?.userInfo[NSLocalizedDescriptionKey] as? SigningError

// Don't show an error when request is cancelled
if let err = error, ((err as? SigningError) == SigningError.cancelled) || signingError == .cancelled {
if let signErr = signingError {
switch signErr {
case .cancelled:
topViewController.dismiss(animated: true)
return
default:
break
}
} else if let err = error as? SigningError {
switch err {
case .cancelled:
topViewController.dismiss(animated: true)
return
default:
break
}
}

if let signErr = signingError, signErr == .cancelled {
topViewController.dismiss(animated: true)
return
} else if let err = error as? SigningError, err == .cancelled {
topViewController.dismiss(animated: true)
return
}

let signingStringError = error?.userInfo[NSLocalizedDescriptionKey] as? String
let detailedErrorMessage = error?.userInfo[NSLocalizedFailureReasonErrorKey] as? String
var errorMessage = userInfo[kErrorMessage] as? String ?? SkSigningLib_LocalizedString(signingError?.signingErrorDescription ?? signingErrorMessage ?? signingStringError ?? "")
var errorMessage = userInfo[kErrorMessage] as? String
if errorMessage.isNilOrEmpty && signingError == .tooManyRequests(signingMethod: SigningType.mobileId.rawValue) {
errorMessage = L(.signingErrorTooManyRequests, [L(.signTitleMobileId).lowercasedStart()])
} else if errorMessage.isNilOrEmpty && signingError == .tooManyRequests(signingMethod: SigningType.smartId.rawValue) {
errorMessage = L(.signingErrorTooManyRequests, [L(.signTitleSmartId)])
} else if errorMessage.isNilOrEmpty && signingError == .tooManyRequests(signingMethod: SigningType.idCard.rawValue) {
errorMessage = L(.signingErrorTooManyRequests, [L(.idCardConditionalSpeech)])
} else {
errorMessage = SkSigningLib_LocalizedString(signingError?.errorDescription ?? signingErrorMessage ?? signingStringError ?? "")
}
if !detailedErrorMessage.isNilOrEmpty {
errorMessage = "\(userInfo[kErrorMessage] as? String ?? SkSigningLib_LocalizedString(signingError?.signingErrorDescription ?? signingErrorMessage ?? "")) \n\(detailedErrorMessage ?? "")"
errorMessage = "\(errorMessage ?? L(.genericErrorMessage)) \n\(detailedErrorMessage ?? "")"
}

let errorDialog = errorDialog(errorMessage: errorMessage, topViewController: topViewController)
let errorDialog = errorDialog(errorMessage: errorMessage ?? L(.genericErrorMessage), topViewController: topViewController)

if !(topViewController is UIAlertController) {
topViewController.present(errorDialog, animated: true, completion: nil)
Expand Down
7 changes: 7 additions & 0 deletions MoppApp/MoppApp/Extensions/String+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ extension String {
return MoppLibManager.sanitize(normalizedName)
.removeForbiddenCharacters().trimWhitespacesAndNewlines()
}

func lowercasedStart() -> String {
guard let firstLetter = first else {
return self
}
return String(firstLetter.lowercased()) + dropFirst()
}
}

extension Optional where Wrapped == String {
Expand Down
1 change: 1 addition & 0 deletions MoppApp/MoppApp/LocalizationKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ enum LocKey : String
case genericErrorMessage = "generic-error-message"
case decryptionErrorMessage = "decryption-error-message"
case signingErrorTooManyRequests = "signing-error-too-many-requests"
case idCardConditionalSpeech = "id-card-conditional-speech"
case noConnectionMessage = "no-response-error"
case sslHandshakeMessage = "ssl-handshake-error"
case ocspInvalidTimeSlot = "ocsp-invalid-time-slot"
Expand Down
15 changes: 9 additions & 6 deletions MoppApp/MoppApp/MobileIDSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class MobileIDSignature {

let error: Error = certificateError as? SigningError ?? certificateError

printLog("\nRIA.MobileID - Certificate error: \(SkSigningLib_LocalizedString(SigningError(rawValue: "\(certificateError)")?.signingErrorDescription ?? "\(certificateError)"))\n")
printLog("\nRIA.MobileID - Certificate error: \(SkSigningLib_LocalizedString(SigningError(rawValue: "\(certificateError)")?.errorDescription ?? "\(certificateError)"))\n")

guard let mobileCertificateError = certificateError as? SigningError else {
return ErrorUtil.generateError(signingError: certificateError as? SigningError ?? SigningError(rawValue: "\(certificateError)") ?? .generalError, details: MessageUtil.errorMessageWithDetails(details: "Unknown error"))
return ErrorUtil.generateError(signingError: (certificateError as? SigningError ?? SigningError(rawValue: "\(certificateError)")) ?? SigningError.generalError , details: MessageUtil.errorMessageWithDetails(details: "Unknown error"))
}

if self.isCountryCodeError(phoneNumber: phoneNumber, errorDesc: "\(mobileCertificateError)") {
Expand Down Expand Up @@ -189,7 +189,7 @@ class MobileIDSignature {

if sessionStatus.result != SessionResultCode.OK {
guard let sessionStatusResultString = sessionStatus.result else { return }
printLog("\nRIA.MobileID - Error completing signing: \(SkSigningLib_LocalizedString(self.handleSessionStatusError(sessionResultCode: sessionStatusResultString).signingErrorDescription ?? "Unable to log session status description"))\n")
printLog("\nRIA.MobileID - Error completing signing: \(SkSigningLib_LocalizedString(self.handleSessionStatusError(sessionResultCode: sessionStatusResultString).errorDescription ?? "Unable to log session status description"))\n")

return ErrorUtil.generateError(signingError: self.handleSessionStatusError(sessionResultCode: sessionStatusResultString))
}
Expand All @@ -209,9 +209,12 @@ class MobileIDSignature {
}
}

// MARK: Check country code
// MARK: Check country code
private func isCountryCodeError(phoneNumber: String, errorDesc: String) -> Bool {
return phoneNumber.count <= 8 && (SigningError.notFound == SigningError(rawValue: errorDesc) || SigningError.internalError == SigningError(rawValue: errorDesc))
let signingError = SigningError(rawValue: errorDesc)

return phoneNumber.count <= 8 &&
(signingError == .notFound || signingError == .internalError)
}

// MARK: Signature validation
Expand Down Expand Up @@ -241,7 +244,7 @@ class MobileIDSignature {
return
} else if err.code == 18 {
printLog("\nRIA.MobileID - Too many requests. \(err.domain)")
ErrorUtil.generateError(signingError: .tooManyRequests, details:
ErrorUtil.generateError(signingError: .tooManyRequests(signingMethod: SigningType.mobileId.rawValue), details:
MessageUtil.generateDetailedErrorMessage(error: err) ?? "")
return
}
Expand Down
2 changes: 1 addition & 1 deletion MoppApp/MoppApp/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Session {
printLog("\nReceived Session (session ID): \(response.sessionID ?? "Unable to display session ID")\n")
completionHandler(.success(response))
case .failure(let sessionError):
printLog("Getting session error: \(SkSigningLib_LocalizedString(sessionError.signingErrorDescription ?? sessionError.rawValue))")
printLog("Getting session error: \(SkSigningLib_LocalizedString((sessionError.errorDescription ?? sessionError.errorDescription) ?? "Error not available"))")
return completionHandler(.failure(sessionError))
}
}
Expand Down
2 changes: 1 addition & 1 deletion MoppApp/MoppApp/SessionCertificate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SessionCertificate {
printLog("Received certificate response: \(response.result?.rawValue ?? "-")")
return completionHandler(.success(response))
case .failure(let error):
printLog("Getting certificate error: \(SkSigningLib_LocalizedString(error.signingErrorDescription ?? error.rawValue))")
printLog("Getting certificate error: \(SkSigningLib_LocalizedString(error.errorDescription ?? "Not available"))")
return completionHandler(.failure(error))
}
}
Expand Down
2 changes: 1 addition & 1 deletion MoppApp/MoppApp/SessionStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SessionStatus {
printLog("Received session status response: \(sessionStatus.result?.rawValue ?? "-")")
}
case .failure(let sessionError):
printLog("Getting Session Status error: \(SkSigningLib_LocalizedString(sessionError.signingErrorDescription ?? sessionError.rawValue))")
printLog("Getting Session Status error: \(SkSigningLib_LocalizedString(sessionError.errorDescription ?? "Not available"))")
return completionHandler(.failure(sessionError))
}
}
Expand Down
5 changes: 4 additions & 1 deletion MoppApp/MoppApp/SigningActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import Foundation
import CommonCrypto
import SkSigningLib

protocol SigningActions {
func startSigningProcess()
Expand Down Expand Up @@ -193,11 +194,13 @@ extension SigningContainerViewController : IdCardSignViewControllerDelegate {
if nsError.code == Int(MoppLibErrorCode.moppLibErrorPinBlocked.rawValue) {
ErrorUtil.generateError(signingError: L(.pin2BlockedAlert))
} else if nsError.code == Int(MoppLibErrorCode.moppLibErrorTooManyRequests.rawValue) {
ErrorUtil.generateError(signingError: .tooManyRequests)
ErrorUtil.generateError(signingError: .tooManyRequests(signingMethod: SigningType.idCard.rawValue))
} else if nsError.code == Int(MoppLibErrorCode.moppLibErrorNoInternetConnection.rawValue) {
ErrorUtil.generateError(signingError: .noResponseError)
} else if nsError.code == Int(MoppLibErrorCode.moppLibErrorOCSPTimeSlot.rawValue) {
ErrorUtil.generateError(signingError: .ocspInvalidTimeSlot)
} else if nsError.code == Int(MoppLibErrorCode.moppLibErrorSslHandshakeFailed.rawValue) {
ErrorUtil.generateError(signingError: .invalidSSLCert)
} else {
ErrorUtil.generateError(signingError: .empty, details: MessageUtil.errorMessageWithDetails(details: nsError.localizedDescription))
}
Expand Down
4 changes: 2 additions & 2 deletions MoppApp/MoppApp/SmartIDSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SmartIDSignature {
let certparams = SIDCertificateRequestParameters(relyingPartyName: kRelyingPartyName, relyingPartyUUID: uuid)
let errorHandler: (SigningError, String) -> Void = { error, log in
UIApplication.shared.endBackgroundTask(backgroundTask)
printLog("\(log): \(SkSigningLib_LocalizedString(error.signingErrorDescription ?? error.rawValue))")
printLog("\(log): \(SkSigningLib_LocalizedString(error.errorDescription ?? "Not available"))")
ErrorUtil.generateError(signingError: error, details: MessageUtil.errorMessageWithDetails(details: log))
}

Expand Down Expand Up @@ -197,7 +197,7 @@ class SmartIDSignature {
return
} else if err.code == 18 {
printLog("\nRIA.SmartID - Too many requests. \(err.domain)")
ErrorUtil.generateError(signingError: .tooManyRequests, details:
ErrorUtil.generateError(signingError: .tooManyRequests(signingMethod: SigningType.smartId.rawValue), details:
MessageUtil.generateDetailedErrorMessage(error: error as NSError) ?? err.domain)
return
}
Expand Down
3 changes: 2 additions & 1 deletion MoppApp/MoppApp/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@
"card-reader-state-ready-for-pin1" = "Ready to decrypt with ID-card.\n%@ (%@)";
"signing-in-progress" = "Signing in progress.\nPlease wait.";
"decryption-in-progress" = "Decryption in progress.\nPlease wait.";
"signing-error-too-many-requests" = "The limit for digital signatures per month has been reached for this IP address. https://www.id.ee/en/article/for-organisations-that-sign-large-quantities-of-documents-using-digidoc4-client/";
"signing-error-too-many-requests" = "The limit for %@ digital signatures per month has been reached. https://www.id.ee/en/article/for-organisations-that-sign-large-quantities-of-documents-using-digidoc4-client/";
"id-card-conditional-speech" = "ID-card's";
"no-response-error" = "Please check your internet connection";
"ssl-handshake-error" = "SSL handshake failed. Check your application settings or software upgrades";
"ocsp-invalid-time-slot" = "Please check your smart device time. https://www.id.ee/en/article/ria-digidoc-error-please-check-your-smart-device-time/";
Expand Down
3 changes: 2 additions & 1 deletion MoppApp/MoppApp/et.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@
"pin1-blocked-alert" = "PIN1 on lukus. PIN-koodi saab lukust avada Minu eID lehel.";
"generic-error-message" = "Midagi läks valesti. Palun proovi uuesti.";
"decryption-error-message" = "Midagi läks dekrüpteerimisel valesti. Palun proovi uuesti.";
"signing-error-too-many-requests" = "Sinu IP-aadressi tasuta allkirjade kuulimiit on ületatud. https://www.id.ee/artikkel/asutustele-kus-allkirjastatakse-digidoc4-kliendi-kaudu-suuremates-kogustes-dokumente/";
"signing-error-too-many-requests" = "Sinu %@ tasuta allkirjade kuulimiit on ületatud. https://www.id.ee/artikkel/asutustele-kus-allkirjastatakse-digidoc4-kliendi-kaudu-suuremates-kogustes-dokumente/";
"id-card-conditional-speech" = "ID-kaardi";
"no-response-error" = "Palun kontrolli internetiühendust";
"ssl-handshake-error" = "SSL ühenduskanali loomine ebaõnnestus. Kontrolli rakenduse seadeid või tarkvara uuendusi";
"ocsp-invalid-time-slot" = "Palun kontrolli oma nutiseadme kellaaega. https://www.id.ee/artikkel/ria-digidoc-viga-palun-kontrollige-oma-nutiseadme-kellaaega/";
Expand Down
3 changes: 2 additions & 1 deletion MoppApp/MoppApp/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@
"card-reader-state-ready-for-pin1" = "Готово к дешифрованию с помощью ID-карты.\n%@ (%@)";
"signing-in-progress" = "Происходит подписание.\nПожалуйста, подождите.";
"decryption-in-progress" = "Происходит дешифрование. Пожалуйста, подождите.";
"signing-error-too-many-requests" = "Предел для цифровых подписей в месяц был достигнут для этого IP-адреса. https://www.id.ee/ru/artikkel/dlya-uchrezhdenij-v-kotoryh-v-bolshom-obeme-podpisyvayutsya-dokumenty-s-pomoshhyu-digidoc4-klienta/";
"signing-error-too-many-requests" = "Ваш месячный лимит бесплатных подписей для %@ превышен. https://www.id.ee/ru/artikkel/dlya-uchrezhdenij-v-kotoryh-v-bolshom-obeme-podpisyvayutsya-dokumenty-s-pomoshhyu-digidoc4-klienta/";
"id-card-conditional-speech" = "ID-карты";
"no-response-error" = "Пожалуйста проверьте подключение к интернету";
"ssl-handshake-error" = "Не удалось создать SSL канал передачи данных. Проверьте настройки вашего приложения или обновления программного обеспечения";
"ocsp-invalid-time-slot" = "Пожалуйста, проверьте время на своем смарт-устройстве. https://www.id.ee/ru/artikkel/oshibka-ria-digidoc-pozhalujsta-proverte-vremya-na-svoem-smart-ustrojstve/";
Expand Down

This file was deleted.

Loading

0 comments on commit 06eb5ed

Please sign in to comment.