Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Feb 1, 2025
1 parent e681f36 commit fe2a436
Show file tree
Hide file tree
Showing 34 changed files with 55 additions and 418 deletions.
6 changes: 3 additions & 3 deletions MoppApp/MoppApp/ContainerSignatureCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ class ContainerSignatureCell: UITableViewCell {
}

private func checkSignatureValidity(signature: MoppLibSignature) -> Void {
if (signature.timestamp == nil) {
signedInfoLabel.text = ""
if let timestamp = ISO8601DateFormatter().date(from: signature.timestamp) {
signedInfoLabel.text = L(LocKey.containerSignatureSigned, [MoppDateFormatter.shared.hHmmssddMMYYYY(toString: timestamp)])
} else {
signedInfoLabel.text = L(LocKey.containerSignatureSigned, [MoppDateFormatter.shared.hHmmssddMMYYYY(toString: signature.timestamp)])
signedInfoLabel.text = ""
}
if (signature.subjectName == "") {
nameLabel.text = L(LocKey.containerTimestampInvalid)
Expand Down
5 changes: 3 additions & 2 deletions MoppApp/MoppApp/ContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,9 @@ extension ContainerViewController : UITableViewDataSource {
if signingContainer.isAsics(), signingContainer.dataFiles.count == 1, signingContainer.signatures.count == 1,
let singleFile: MoppLibDataFile = signingContainer.dataFiles[0] as? MoppLibDataFile,
singleFile.fileName.hasSuffix(ContainerFormatDdoc),
let singleSignature: MoppLibSignature = signingContainer.signatures[0] as? MoppLibSignature {
DefaultsHelper.isTimestampedDdoc = !singleSignature.timestamp.isAfter(anotherDate: calendarDate)
let singleSignature: MoppLibSignature = signingContainer.signatures[0] as? MoppLibSignature,
let timestamp = ISO8601DateFormatter().date(from: singleSignature.timestamp) {
DefaultsHelper.isTimestampedDdoc = !timestamp.isAfter(anotherDate: calendarDate)
return
} else if signingContainer.isDdoc(), state != .preview {
DefaultsHelper.isTimestampedDdoc = false
Expand Down
7 changes: 2 additions & 5 deletions MoppApp/MoppApp/MobileIDChallengeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MobileIDChallengeViewController : UIViewController {
@IBOutlet weak var helpLabel: UILabel!

var challengeID = String()
var sessCode = String()

var currentProgress: Double = 0.0
var sessionTimer: Timer?
Expand Down Expand Up @@ -144,14 +143,12 @@ class MobileIDChallengeViewController : UIViewController {

@objc func receiveMobileCreateSignatureNotification(_ notification: Notification) {

guard let response = notification.userInfo?[kCreateSignatureResponseKey] as? MoppLibMobileCreateSignatureResponse else {
guard let challengeID = notification.userInfo?[kCreateSignatureResponseKey] as? String else {
return
}

challengeID = response.challengeId!
sessCode = "\(Int(response.sessCode))"
challengeIdNumbers = Array<Character>(challengeID)

let challengeIdAccessibilityLabel: NSAttributedString = NSAttributedString(string: "\(L(.signingProgress)) \(Int(0))%. \((L(LocKey.challengeCodeLabelAccessibility, [String(challengeIdNumbers[0]), String(challengeIdNumbers[1]), String(challengeIdNumbers[2]), String(challengeIdNumbers[3])]))). \(self.helpLabel.text!)", attributes: [.accessibilitySpeechQueueAnnouncement: true])

codeLabel.text = L(LocKey.challengeCodeLabel, [challengeID])
Expand Down
41 changes: 14 additions & 27 deletions MoppApp/MoppApp/MobileIDSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class MobileIDSignature {
}

// MARK: Get hash
guard let hash: String = self.getHash(cert: cert, containerPath: containerPath, roleData: roleData) else {
guard let hash = self.getHash(cert: cert, containerPath: containerPath, roleData: roleData) else {
printLog("\nRIA.MobileID - Error getting hash. Is 'cert' empty: \(cert.isEmpty). ContainerPath: \(containerPath)\n")
return ErrorUtil.generateError(signingError: .generalError, details: MessageUtil.errorMessageWithDetails(details: "Unable to get hash"))
}
Expand All @@ -121,9 +121,9 @@ class MobileIDSignature {

// MARK: Get control / verification code
printLog("\nRIA.MobileID - Getting control code\n")
self.setupControlCode()
self.setupControlCode(dataToSign: hash)

completionHandler(hash, cert)
completionHandler(hash.base64EncodedString(), cert)
}
}

Expand Down Expand Up @@ -270,28 +270,24 @@ class MobileIDSignature {
}

// MARK: Control / verification code setup
private func setupControlCode() {
guard let verificationCode = self.getVerificationCode() else {
private func setupControlCode(dataToSign: Data) {
guard let verificationCode = ControlCode.shared.getVerificationCode(hash: dataToSign) else {
printLog("\nRIA.MobileID - Failed to get verification code\n")
return ErrorUtil.generateError(signingError: .generalError, details: MessageUtil.errorMessageWithDetails(details: "Failed to get verification code"))
}

DispatchQueue.main.async {
let response: MoppLibMobileCreateSignatureResponse = MoppLibMobileCreateSignatureResponse()
response.challengeId = verificationCode
DispatchQueue.main.async {
NotificationCenter.default.post(
name: .createSignatureNotificationName,
object: nil,
userInfo: [kCreateSignatureResponseKey: response]
)
}
NotificationCenter.default.post(
name: .createSignatureNotificationName,
object: nil,
userInfo: [kCreateSignatureResponseKey: verificationCode]
)
}
}

// MARK: Get hash
private func getHash(cert: String, containerPath: String, roleData: MoppLibRoleAddressData?) -> String? {
guard let hash: String = MoppLibManager.prepareSignature(cert, containerPath: containerPath, roleData: roleData) else {
private func getHash(cert: String, containerPath: String, roleData: MoppLibRoleAddressData?) -> Data? {
guard let hash = MoppLibManager.prepareSignature(cert, containerPath: containerPath, roleData: roleData) else {
printLog("RIA.MobileID - Failed to get hash:\n" +
"\tCert: \(cert)\n" +
"\tContainer path: \(containerPath)\n"
Expand All @@ -303,16 +299,7 @@ class MobileIDSignature {

return hash
}

// MARK: Get verification code
private func getVerificationCode() -> String? {
guard let dataToSign = MoppLibManager.getDataToSign(), let verificationCode: String = ControlCode.shared.getVerificationCode(hash: dataToSign) else {
ErrorUtil.generateError(signingError: .generalError, details: MessageUtil.errorMessageWithDetails(details: "Failed to get verification code"))
return nil
}
return verificationCode
}


// MARK: Handle session status error
private func handleSessionStatusError(sessionResultCode: SessionResultCode) -> SigningError {
switch sessionResultCode {
Expand Down
1 change: 0 additions & 1 deletion MoppApp/MoppApp/MoppApp-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

#import <MoppLib/MoppLib.h>
#import <MoppLib/MoppLibConstants.h>
#import <MoppLib/MoppLibMobileCreateSignatureResponse.h>
#import <MoppLib/MoppLibCardReaderManager.h>
#import <MoppLib/MoppLibProxyConfiguration.h>
2 changes: 1 addition & 1 deletion MoppApp/MoppApp/MyeIDInfoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class MyeIDInfoManager {
guard let personalData = personalData else { return }
let certOrganization = authCertData?.organization ?? MoppLibCertificateOrganization.Unknown
personalInfo.items.append((type: .myeID, value: organizationDisplayString(certOrganization)))
personalInfo.items.append((type: .givenNames, value: personalData.givenNames()))
personalInfo.items.append((type: .givenNames, value: personalData.givenNames))
personalInfo.items.append((type: .surname, value: personalData.surname))
personalInfo.items.append((type: .personalCode, value: personalData.personalIdentificationCode))
personalInfo.items.append((type: .citizenship, value: personalData.nationality))
Expand Down
2 changes: 1 addition & 1 deletion MoppApp/MoppApp/NFCSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class NFCSignature : NSObject, NFCTagReaderSessionDelegate {
pin.replaceSubrange(0..<PIN!.count, with: PIN!.utf8)
_ = try await sendWrapped(tag: tag, cls: 0x00, ins: 0x22, p1: 0x41, p2: 0xb6, data: Bytes(hex: "80015484019f")!)
_ = try await sendWrapped(tag: tag, cls: 0x00, ins: 0x20, p1: 0x00, p2: 0x85, data: pin)
let signatureValue = try await sendWrapped(tag: tag, cls:0x00, ins: 0x2A, p1: 0x9E, p2: 0x9A, data: Bytes(Data(base64Encoded: hash)!), le: 256);
let signatureValue = try await sendWrapped(tag: tag, cls:0x00, ins: 0x2A, p1: 0x9E, p2: 0x9A, data: Bytes(hash), le: 256);
printLog("\nRIA.NFC - Validating signature...\n")
MoppLibManager.isSignatureValid(cert.base64EncodedString(), signatureValue: signatureValue.base64EncodedString(), success: { _ in
printLog("\nRIA.NFC - Successfully validated signature!\n")
Expand Down
10 changes: 4 additions & 6 deletions MoppApp/MoppApp/SmartIDSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SmartIDSignature {
guard let hash = self.setupControlCode(certificateValue: certificateValue, containerPath: containerPath, roleData: roleData) else {
return errorHandler(.generalError, "Error getting hash. Is 'cert' empty: \(certificateValue.isEmpty). ContainerPath: \(containerPath)")
}
completionHandler(documentNumber, certificateValue, hash)
completionHandler(documentNumber, certificateValue, hash.base64EncodedString())
case .failure(let error):
errorHandler(error, "Unable to get certificate status")
}
Expand Down Expand Up @@ -207,14 +207,12 @@ class SmartIDSignature {
})
}

private func setupControlCode(certificateValue: String, containerPath: String, roleData: MoppLibRoleAddressData?) -> String? {
private func setupControlCode(certificateValue: String, containerPath: String, roleData: MoppLibRoleAddressData?) -> Data? {
guard let hash = MoppLibManager.prepareSignature(certificateValue, containerPath: containerPath, roleData: roleData) else {
return nil
}

guard let hashData = Data(base64Encoded: hash) else { return nil }

let digest = sha256(data: hashData)

let digest = sha256(data: hash)
let code = UInt16(digest[digest.count - 2]) << 8 | UInt16(digest[digest.count - 1])
let challengeId = String(format: "%04d", (code % 10000))
DispatchQueue.main.async {
Expand Down
Loading

0 comments on commit fe2a436

Please sign in to comment.