|
1 | | -- [Ülevaade](#ülevaade) |
2 | | -- [Demorakenduse jooksutamise juhend](#demorakenduse-jooksutamise-juhend) |
3 | | -- [Integreerimise juhend](#integreerimise-juhend) |
4 | | - - [Rakenduse nõuded](#rakenduse-nõuded) |
5 | | - - [Lubada NFC Võimekus](#lubada-nfc-võimekus) |
6 | | - - [Uuendada Info.plist](#uuendada-infoplist) |
7 | | - - [Teegi ehitamine](#teegi-ehitamine) |
8 | | - - [Teegi lisamine rakendusse](#teegi-lisamine-rakendusse) |
9 | | -- [Teegi liidesed id-kaardiga suhtluseks](#teegi-liidesed-id-kaardiga-suhtluseks) |
10 | | - |
11 | | -# Ülevaade |
12 | | - |
13 | | -NFC-ID teek pakub võimalust kasutada ID-kaardi autentimis- ja signeerimisfunktsionaalsust üle NFC liidese. Teegist on kaks versiooni - Android ja iOS platvormile. |
14 | | - |
15 | | -NFC-ID teek ei ole mõeldud avalikuks kasutamiseks. Tegemist on tehnilise taseme teegiga, mis delegeerib kasutajaga suhtlemise rakendusele. Pikema aja jooksul ei ole ohutu võimaldada lõppkasutajal sisestada oma ID-kaardi PIN-koode igasse mobiilirakendusse. ID-kaardiga suhtluseks, usaldusväärse kasutajaliidese ning muude vajalike funktsioonide jaoks on vajalik luua tulevikus spetsiaalne mobiilirakendus. Selline lahendus võimaldab edaspidi mobiilirakendust kiiremini uuendada ning rünnete korral kaitsemeetmeid kohandada ja täiendada. |
16 | | -NFC-ID teek on arendatud m-valimiste projektis lähtudes vajadusest kasutada ID-kaarti m valijarakenduses. |
17 | | - |
18 | | -# Demorakenduse jooksutamise juhend |
19 | | -- Avada mvtng-nfc-demo.xcworkspace. Antud töökeskkond sisaldab endas nii demorakendust kui nfclib teeki. |
20 | | -- Oodata, kuni Swift Package Manager'i sõltuvused laetakse alla |
21 | | -- Product -> Run |
22 | | - |
23 | | -Simulaator pole toetatud, sest simulaatoril puudub NFC tugi. |
24 | | - |
25 | | -# Integreerimise juhend |
26 | | - |
27 | | -## Rakenduse nõuded |
28 | | -### Lubada NFC Võimekus |
29 | | -Xcode projektis tuleb seadistada NFC võimekuse loa küsimine |
30 | | - |
31 | | -- Projekti navigaatoris valida oma projekt. |
32 | | -- Valida oma rakenduse sihtmärk ja seejärel minna vahelehele "Signing & Capabilities". |
33 | | -- Klikkida nupul "+ Capability". |
34 | | -- Otsida "Near Field Communication Tag Reading" ja lisada see oma projekti. |
35 | | - |
36 | | -### Uuendada Info.plist |
37 | | -Info.plist failis peab deklareerima NFC kasutuse, et selgitada, miks rakendus vajab juurdepääsu sellele tehnoloogiale. |
38 | | - |
39 | | -- Avada oma Info.plist fail. |
40 | | -- Lisada uus võti Privacy - NFC Scan Usage Description (NFCReaderUsageDescription). |
41 | | -- Määrata selle väärtuseks string, mis kirjeldab, miks rakendus vajab juurdepääsu NFC-le. See kirjeldus kuvatakse kasutajale esmakordselt, kui rakendus üritab NFC-d kasutada. |
42 | | - |
43 | | -### Teegi ehitamine |
44 | | -Eesmärk on ehitada .xcframework failikogumik, mida saab lisata sõltuvusena teistesse projektidesse. |
45 | | - |
46 | | -- Jooksuta skripti nimega build_xcframework.sh, mis asub projekti kaustas |
47 | | - - Selle tagajärjel ilmub projekti kaustas build kausta nflib.xcframework |
48 | | - |
49 | | -### Teegi lisamine rakendusse |
50 | | -- Ava projekt, kuhu soovid integreerida nfclib teegi |
51 | | -- Vali projekt ja TARGETS menüü all õige programm |
52 | | -- Selle tagajärjel peaks olema nähtav General osa sihtprogrammi kohta |
53 | | -- Otsida Frameworks and Libraries |
54 | | -- Vajutada + -> Add Other... -> Add Files -> Valida nfclib.xcframework |
55 | | - |
56 | | -Nüüd on nfc teek rakendusse integreeritud. |
57 | | - |
58 | | -# Teegi liidesed id-kaardiga suhtluseks |
59 | | -Kõik avalikud operatsioonid on kirjeldatud `CardOperations` protokollis. |
60 | | - |
61 | | -Järgnevalt on nimetatud operatsioonid, mida teek võimaldab. |
62 | | - |
63 | | -Tagastab, kas NFC on seadmel toetatud. |
64 | | -`public func isNFCSupported() -> Bool` |
65 | | - |
66 | | -Loeb asünkroonselt kaardilt avalikku teavet kaardi omaniku kohta |
67 | | -`public func readPublicInfo(CAN: String) async throws -> CardInfo` |
68 | | - |
69 | | -Loeb asünkroonselt kaardilt autentimise sertifikaadi. |
70 | | -`public func readAuthenticationCertificate(CAN: String) async throws -> SecCertificate` |
71 | | - |
72 | | -Loeb asünkroonselt kaardilt allkirjastamise sertifikaadi. |
73 | | -`public func readSigningCertificate(CAN: String) async throws -> SecCertificate` |
74 | | - |
75 | | -Hangib andmeid WebEID autentimiseks, kasutades antud volikirju ja väljakutset. |
76 | | -`public func loadWebEIDAuthenticationData(CAN: String, pin1: String, challenge: String, origin: String) async throws -> WebEidData` |
77 | | - |
78 | | -Viib läbi allkirjastamise operatsiooni, kasutades eelnevalt arvutatud räsi (toetatud on ainult SHA-384) ja PIN-koodi |
79 | | -`public func sign(CAN: String, hash: Data, pin2: String) async throws -> Data` |
| 1 | +- [Overview](#overview) |
| 2 | +- [Demo Application Run Guide](#demo-application-run-guide) |
| 3 | +- [Integration Guide](#integration-guide) |
| 4 | + - [Application Requirements](#application-requirements) |
| 5 | + - [Enable NFC Capability](#enable-nfc-capability) |
| 6 | + - [Update Info.plist](#update-infoplist) |
| 7 | + - [Build the Library](#build-the-library) |
| 8 | + - [Add the Library to the Application](#add-the-library-to-the-application) |
| 9 | +- [Library Interfaces for ID Card Communication](#library-interfaces-for-id-card-communication) |
| 10 | + |
| 11 | +# Overview |
| 12 | + |
| 13 | +The NFC-ID library provides functionality to use ID card authentication and digital signing over the NFC interface. Two platform-specific versions of the library are available – one for Android and one for iOS. |
| 14 | + |
| 15 | +The NFC-ID library is not intended for public use. It is a low-level technical library that delegates user interaction to the application itself. In the long term, it is not safe to allow end users to enter their ID card PIN codes directly into every mobile app. For secure ID card interaction, a trusted user interface, and additional required features, a dedicated mobile application must be developed in the future. Such a solution would also allow faster updates to the application and enable quick adjustments of countermeasures in case of attacks. |
| 16 | + |
| 17 | +The NFC-ID library was originally developed within the m-valimiste project, based on the need to use the ID card inside the m-Voting client application. |
| 18 | + |
| 19 | +# Demo Application Run Guide |
| 20 | +- Open **mvtng-nfc-demo.xcworkspace**. This workspace includes both the demo app and the `nfclib` library. |
| 21 | +- Wait until **Swift Package Manager** dependencies are fully downloaded. |
| 22 | +- Select **Product → Run**. |
| 23 | + |
| 24 | +⚠️ The simulator is not supported, since it does not provide NFC functionality. |
| 25 | + |
| 26 | +# Integration Guide |
| 27 | + |
| 28 | +## Application Requirements |
| 29 | +### Enable NFC Capability |
| 30 | +You must configure your Xcode project to request NFC capability access: |
| 31 | + |
| 32 | +- In the project navigator, select your project. |
| 33 | +- Select your app target, then go to the **Signing & Capabilities** tab. |
| 34 | +- Click **+ Capability**. |
| 35 | +- Search for **Near Field Communication Tag Reading** and add it to your project. |
| 36 | + |
| 37 | +### Update Info.plist |
| 38 | +You must declare NFC usage in your **Info.plist** file to explain why the application requires access to this technology. |
| 39 | + |
| 40 | +- Open your **Info.plist** file. |
| 41 | +- Add a new key: **Privacy – NFC Scan Usage Description** (`NFCReaderUsageDescription`). |
| 42 | +- Set its value to a string explaining why the app requires NFC access. This text will be displayed to the user the first time the app attempts to use NFC. |
| 43 | + |
| 44 | +### Build the Library |
| 45 | +The goal is to build an `.xcframework` bundle that can be added as a dependency to other projects. |
| 46 | + |
| 47 | +- Run the script `build_xcframework.sh`, located at `nfc-lib/nfc-lib/build_xcframework.sh`. |
| 48 | + - After execution, the project’s **build** folder will contain the file **nfclib.xcframework**. |
| 49 | + |
| 50 | +### Add the Library to the Application |
| 51 | +- Open the project where you want to integrate the `nfclib` library. |
| 52 | +- Select the project, then under **TARGETS**, choose the correct target. |
| 53 | +- In the **General** tab of the target, find the **Frameworks and Libraries** section. |
| 54 | +- Click **+ → Add Other… → Add Files… → Select nfclib.xcframework**. |
| 55 | + |
| 56 | +The NFC library is now integrated into your application. |
| 57 | + |
| 58 | +# Library Interfaces for ID Card Communication |
| 59 | +The library provides the following operation classes for ID card communication: |
| 60 | +- `OperationReadPublicData` - Reads cardholder information |
| 61 | +- `OperationReadCertificate` - Extracts authentication/signing certificates |
| 62 | +- `OperationSignHash` - Performs a signing operation using the provided hash and PIN |
| 63 | +- `OperationUnblockPin` - Unblock PIN1 or PIN2 using PUK |
| 64 | +- `OperationAuthenticateWithWebEID` - Web-eID authentication flow |
| 65 | + |
| 66 | +For a complete integration example, see the demo app's `CardOperations` protocol (`mvoting-nfc/nfc-demo/CardOperations.swift`) and its implementation in `Operator.swift`, which provides a convenient wrapper around these operations: |
| 67 | + |
| 68 | +Returns whether NFC is supported on the device: |
| 69 | +```swift |
| 70 | +public func isNFCSupported() -> Bool |
| 71 | +``` |
| 72 | + |
| 73 | +Asynchronously reads public information about the cardholder from the card: |
| 74 | +```swift |
| 75 | +public func readPublicInfo(CAN: String) async throws -> CardInfo |
| 76 | +``` |
| 77 | + |
| 78 | +Asynchronously reads the authentication certificate from the card: |
| 79 | +```swift |
| 80 | +public func readAuthenticationCertificate(CAN: String) async throws -> SecCertificate |
| 81 | +``` |
| 82 | + |
| 83 | +Asynchronously reads the signing certificate from the card: |
| 84 | +```swift |
| 85 | +public func readSigningCertificate(CAN: String) async throws -> SecCertificate |
| 86 | +``` |
| 87 | + |
| 88 | +Retrieves data required for WebEID authentication, using the provided credentials and challenge: |
| 89 | +```swift |
| 90 | +public func loadWebEIDAuthenticationData(CAN: String, pin1: String, challenge: String, origin: String) async throws -> WebEidData |
| 91 | +``` |
| 92 | + |
| 93 | +Performs a signing operation using a precomputed hash (only SHA-384 supported) and the PIN2 code: |
| 94 | +```swift |
| 95 | +public func sign(CAN: String, hash: Data, pin2: String) async throws -> Data |
| 96 | +``` |
| 97 | + |
| 98 | +Unblocks PIN1 using the PUK code and sets a new PIN: |
| 99 | +```swift |
| 100 | +public func unblockPin1(CAN: String, puk: String, newCode: String) async throws |
| 101 | +``` |
| 102 | + |
| 103 | +Unblocks PIN2 using the PUK code and sets a new PIN: |
| 104 | +```swift |
| 105 | +public func unblockPin2(CAN: String, puk: String, newCode: String) async throws |
| 106 | +``` |
0 commit comments