Skip to content

Commit

Permalink
Add revision: v1.26.3
Browse files Browse the repository at this point in the history
  • Loading branch information
GovernikusAusweisApp2 committed Mar 9, 2023
0 parents commit 3762211
Show file tree
Hide file tree
Showing 12 changed files with 1,611 additions and 0 deletions.
11 changes: 11 additions & 0 deletions AA2SDKWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2020-2023 Governikus GmbH & Co. KG, Germany
*/

import Foundation
import SwiftUI

@available(iOS 13, *)
public enum AA2SDKWrapper {
public static let workflowController = WorkflowController(withConnection: AA2SdkConnection.shared)
}
72 changes: 72 additions & 0 deletions card/core/AusweisApp2/AA2SdkConnection.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2020-2023 Governikus GmbH & Co. KG, Germany
*/

import AusweisApp2
import Foundation

class AA2SdkConnection: SdkConnection {
static let shared = AA2SdkConnection()

var isStarted: Bool {
ausweisapp2_is_running()
}

var onConnected: (() -> Void)?
var onMessageReceived: ((_ message: AA2Message) -> Void)?

private let ausweisApp2Callback: AusweisApp2Callback = { (msg: UnsafePointer<CChar>?) in
guard let msg = msg else {
AA2SdkConnection.shared.onNewMessage(messageJson: nil)
return
}
let messageString = String(cString: msg)
AA2SdkConnection.shared.onNewMessage(messageJson: messageString)
}

private let jsonDecoder = JSONDecoder()
private let jsonEncoder = JSONEncoder()

private init() {}

func start() {
ausweisapp2_init(ausweisApp2Callback, nil)
}

func stop() {
ausweisapp2_shutdown()
}

func send<T: Command>(command: T) {
do {
let messageData = try jsonEncoder.encode(command)
if let messageJson = String(data: messageData, encoding: .utf8) {
print("Send message: \(messageJson)")
ausweisapp2_send(messageJson)
}
} catch {
print("Could not send json message")
}
}

private func onNewMessage(messageJson: String?) {
guard let messageJson = messageJson else {
if let onConnected = onConnected {
onConnected()
}
return
}

print("Received message: \(messageJson)")
do {
let messageData = Data(messageJson.utf8)
let message = try jsonDecoder.decode(AA2Message.self, from: messageData)

if let onMessageReceived = onMessageReceived {
onMessageReceived(message)
}
} catch {
print("Could not parse json message")
}
}
}
133 changes: 133 additions & 0 deletions card/core/AusweisApp2/MessageExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* Copyright (c) 2020-2023 Governikus GmbH & Co. KG, Germany
*/

import Foundation

extension AA2Message {
var aa2DateFormat: String { "yyyy-MM-dd" }

func getCertificateDescription() -> CertificateDescription? {
guard
let description = description,
let validity = validity,
let effectiveDate = validity.effectiveDate.parseDate(format: aa2DateFormat),
let expirationDate = validity.expirationDate.parseDate(format: aa2DateFormat)
else { return nil }

return CertificateDescription(
issuerName: description.issuerName,
issuerUrl: URL(string: description.issuerUrl),
purpose: description.purpose,
subjectName: description.subjectName,
subjectUrl: URL(string: description.subjectUrl),
termsOfUsage: description.termsOfUsage,
validity: CertificateValidity(
effectiveDate: effectiveDate,
expirationDate: expirationDate
)
)
}

func getReaders() -> [Reader]? {
guard let readers = readers else { return nil }

let readerList = readers.compactMap { reader -> Reader? in Reader(reader: reader)
}
return readerList
}

func getReader() -> Reader? {
if let reader = reader {
return Reader(reader: reader)
}

guard let name = name else { return nil }
guard let insertable = insertable else { return nil }
guard let attached = attached else { return nil }
guard let keypad = keypad else { return nil }

return Reader(
name: name,
insertable: insertable,
attached: attached,
keypad: keypad,
card: getCard()
)
}

func getCard() -> Card? {
guard let card = card ?? reader?.card else { return nil }

return Card(card: card)
}

func getAccessRights() -> AccessRights? {
guard let chat = chat else { return nil }

var auxiliaryData: AuxiliaryData?
if let aux = aux {
auxiliaryData = AuxiliaryData(
ageVerificationDate: aux.ageVerificationDate?.parseDate(format: aa2DateFormat),
requiredAge: Int(aux.requiredAge ?? ""),
validityDate: aux.validityDate?.parseDate(format: aa2DateFormat),
communityId: aux.communityId
)
}

let requiredRights = chat.required.compactMap { accessRight -> AccessRight? in
AccessRight(rawValue: accessRight)
}
let optionalRights = chat.optional.compactMap { accessRight -> AccessRight? in
AccessRight(rawValue: accessRight)
}
let effectiveRights = chat.effective.compactMap { accessRight -> AccessRight? in
AccessRight(rawValue: accessRight)
}

return AccessRights(
requiredRights: requiredRights,
optionalRights: optionalRights,
effectiveRights: effectiveRights,
transactionInfo: transactionInfo,
auxiliaryData: auxiliaryData
)
}

func getAuthResult() -> AuthResult? {
let result = getAuthResultData()

var resultUrl: URL?
if let url = url {
resultUrl = URL(string: url)
}

if result != nil || resultUrl != nil {
return AuthResult(
url: resultUrl,
result: result
)
}

return nil
}

func getAuthResultData() -> AuthResultData? {
guard let major = result?.major else { return nil }

let minor = result?.minor
let description = result?.description
let message = result?.message
let reason = result?.reason
let language = result?.language

return AuthResultData(
major: major,
minor: minor,
language: language,
description: description,
message: message,
reason: reason
)
}
}
100 changes: 100 additions & 0 deletions card/core/AusweisApp2/protocol/Commands.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright (c) 2020-2023 Governikus GmbH & Co. KG, Germany
*/

import Foundation

protocol Command: Encodable {
var cmd: String { get }
}

struct Accept: Command {
let cmd = "ACCEPT"
}

struct Cancel: Command {
let cmd = "CANCEL"
}

struct GetCertificate: Command {
let cmd = "GET_CERTIFICATE"
}

struct RunAuth: Command {
let cmd = "RUN_AUTH"
let tcTokenURL: String
let developerMode: Bool
let messages: AA2UserInfoMessages?
let status: Bool
}

struct RunChangePin: Command {
let cmd = "RUN_CHANGE_PIN"
let messages: AA2UserInfoMessages?
let status: Bool
}

struct SetAccessRights: Command {
let cmd = "SET_ACCESS_RIGHTS"
let chat: [String]
}

struct GetAccessRights: Command {
let cmd = "GET_ACCESS_RIGHTS"
}

struct SetCan: Command {
let cmd = "SET_CAN"
let value: String?
}

struct SetPin: Command {
let cmd = "SET_PIN"
let value: String?
}

struct SetNewPin: Command {
let cmd = "SET_NEW_PIN"
let value: String?
}

struct SetPuk: Command {
let cmd = "SET_PUK"
let value: String?
}

struct Interrupt: Command {
let cmd = "INTERRUPT"
}

struct GetStatus: Command {
let cmd = "GET_STATUS"
}

struct GetInfo: Command {
let cmd = "GET_INFO"
}

struct GetReader: Command {
let cmd = "GET_READER"
let name: String
}

struct GetReaderList: Command {
let cmd = "GET_READER_LIST"
}

struct GetApiLevel: Command {
let cmd = "GET_API_LEVEL"
}

struct SetApiLevel: Command {
let cmd = "SET_API_LEVEL"
let level: Int
}

struct SetCard: Command {
let cmd = "SET_CARD"
let name: String
let simulator: Simulator?
}
Loading

0 comments on commit 3762211

Please sign in to comment.