Skip to content

Commit 0c23296

Browse files
authored
Merge develop-main to main (#3)
* Fix web-eid auth * MVAL-171: Add a progress bar for webeid * MVAL-171: Add missing progress bar to sign operation * Use signature algorithm lenght on challenge and origin hashing * remove redundant stuff from pr * update switch to throw on default * Fix alertMessage updating on sign operation * MVAL-349 Add Thales support (#10) * NFC-73 Refactor and optimize nfclib, swiftlint warnings fixes, added header licenses. * NFC-78 Update README.md, translate to English. (#2)
1 parent 41359f1 commit 0c23296

40 files changed

+2424
-1144
lines changed

README.md

Lines changed: 106 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,106 @@
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+
```

mvoting-nfc/nfc-demo.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
139195AE2AFA29CC00EDA022 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 139195AD2AFA29CC00EDA022 /* ContentView.swift */; };
1515
139195B02AFA29CD00EDA022 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 139195AF2AFA29CD00EDA022 /* Assets.xcassets */; };
1616
139195B32AFA29CD00EDA022 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 139195B22AFA29CD00EDA022 /* Preview Assets.xcassets */; };
17+
1A0AA6F32E8EB4D2000B11FA /* CardOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A0AA6F22E8EB4D2000B11FA /* CardOperations.swift */; };
18+
1A0AA6F42E8EB4D2000B11FA /* Operator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A0AA6F12E8EB4D2000B11FA /* Operator.swift */; };
1719
/* End PBXBuildFile section */
1820

1921
/* Begin PBXCopyFilesBuildPhase section */
@@ -40,6 +42,8 @@
4042
139195AF2AFA29CD00EDA022 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4143
139195B22AFA29CD00EDA022 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
4244
1392583F2B04B06A00AD38EA /* nfc-demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "nfc-demo.entitlements"; sourceTree = "<group>"; };
45+
1A0AA6F12E8EB4D2000B11FA /* Operator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Operator.swift; sourceTree = "<group>"; };
46+
1A0AA6F22E8EB4D2000B11FA /* CardOperations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardOperations.swift; sourceTree = "<group>"; };
4347
5A2C028B2B060E9D00C6D249 /* SkSigningLib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SkSigningLib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4448
5A9969882B03B9A4002A1060 /* nfc_lib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = nfc_lib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4549
/* End PBXFileReference section */
@@ -83,6 +87,8 @@
8387
13176D742B3193F70093D806 /* CardInfoView.swift */,
8488
139195AF2AFA29CD00EDA022 /* Assets.xcassets */,
8589
139195B12AFA29CD00EDA022 /* Preview Content */,
90+
1A0AA6F12E8EB4D2000B11FA /* Operator.swift */,
91+
1A0AA6F22E8EB4D2000B11FA /* CardOperations.swift */,
8692
);
8793
path = "nfc-demo";
8894
sourceTree = "<group>";
@@ -182,6 +188,8 @@
182188
files = (
183189
139195AE2AFA29CC00EDA022 /* ContentView.swift in Sources */,
184190
139195AC2AFA29CC00EDA022 /* nfc_demoApp.swift in Sources */,
191+
1A0AA6F32E8EB4D2000B11FA /* CardOperations.swift in Sources */,
192+
1A0AA6F42E8EB4D2000B11FA /* Operator.swift in Sources */,
185193
13176D752B3193F70093D806 /* CardInfoView.swift in Sources */,
186194
);
187195
runOnlyForDeploymentPostprocessing = 0;

mvoting-nfc/nfc-demo/CardInfoView.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
//
2-
// CardInfoView.swift
3-
// nfc-demo
4-
//
5-
// Created by Timo Kallaste on 19.12.2023.
6-
//
1+
/*
2+
* Copyright 2017 - 2025 Riigi Infosüsteemi Amet
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
*/
719

820
import SwiftUI
921
import nfclib

nfc-lib/nfc-lib/nfclib/CardOperations.swift renamed to mvoting-nfc/nfc-demo/CardOperations.swift

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
//
2-
// CardOperations.swift
3-
// nfclib
4-
//
5-
// Created by Timo Kallaste on 31.01.2024.
6-
//
1+
/*
2+
* Copyright 2017 - 2025 Riigi Infosüsteemi Amet
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
*/
719

820
/// `CardOperations` protocol
921
///
1022
/// This protocol defines a set of operations for interacting with a card,
1123
/// including NFC support checking, reading card information, and performing
1224
/// authentication and signing operations.
25+
import nfclib
1326

1427
public protocol CardOperations {
1528

@@ -59,4 +72,22 @@ public protocol CardOperations {
5972
/// - Returns: A `Data` object containing the signature.
6073
/// - Throws: An error if the signing operation fails.
6174
func sign(CAN: String, hash: Data, pin2: String) async throws -> Data
75+
76+
/// Unblocks a PIN1 using the PUK code.
77+
///
78+
/// - Parameters:
79+
/// - CAN: A `String` representing the Card Access Number.
80+
/// - puk: The current PUK code for verification.
81+
/// - newCode: The new PIN code.
82+
/// - Throws: An error if the operation fails.
83+
func unblockPin1(CAN: String, puk: String, newCode: String) async throws
84+
85+
/// Unblocks a PIN2 using the PUK code.
86+
///
87+
/// - Parameters:
88+
/// - CAN: A `String` representing the Card Access Number.
89+
/// - puk: The current PUK code for verification.
90+
/// - newCode: The new PIN code.
91+
/// - Throws: An error if the operation fails.
92+
func unblockPin2(CAN: String, puk: String, newCode: String) async throws
6293
}

0 commit comments

Comments
 (0)