taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 19b2485d7d51205eff6820191473ac7d05fa3afa
parent 7600dde63e872446d3a23858ce73cecdd6d536a7
Author: Marc Stibane <marc@taler.net>
Date:   Tue, 30 Jun 2026 08:34:40 +0200

limit talerURIs to 8k lenght (w.i.p.)

Diffstat:
MTalerWallet1/Helper/TagEmulation.swift | 3++-
MTalerWallet1/Helper/apdu.swift | 19+++++++++++++++----
2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/TalerWallet1/Helper/TagEmulation.swift b/TalerWallet1/Helper/TagEmulation.swift @@ -48,6 +48,7 @@ class TagEmulation: ObservableObject { // presentmentIntent.isValid to ensure the assertion remains active. var result = false + guard emulatedData.count < 8192 else { return false } do { if presentmentIntent == nil { presentmentIntent = try await NFCPresentmentIntentAssertion.acquire() @@ -108,7 +109,7 @@ class TagEmulation: ObservableObject { } private func eventStream(_ mySession: CardSession, data emulatedData: String) async throws { - let apdu = APDU(emulatedData) + let apdu = try APDU(emulatedData) // Iterate over events as the card session produces them. for try await event in mySession.eventStream { // if presentmentIntent?.isValid ?? false { diff --git a/TalerWallet1/Helper/apdu.swift b/TalerWallet1/Helper/apdu.swift @@ -8,14 +8,22 @@ import Foundation import os.log +enum APDUError: Error { + case invalidStringValue +} + @MainActor class APDU { - let talerUri: String + let talerUri: String // contains only ASCII, never Unicode nonisolated let logger = Logger(subsystem: "net.taler.gnu", category: "APDU") private var readCapabilityContainerCheck = false - init(_ talerUri: String) { - self.talerUri = talerUri + init(_ talerUri: String) throws { + if talerUri.count < 8192 { + self.talerUri = talerUri + } else { + throw APDUError.invalidStringValue + } } private var APDU_SELECT: Data { @@ -204,8 +212,11 @@ class APDU { return A_OKAY } // 00a4000c02e104 + // TODO: This only works for talerURIs < 256 bytes + // but they may be up to 8192 bytes long + // So we need to change to long header... let uriCount = talerUri.count - let ndefLen = UInt16(uriCount + 5) // NDEF_RECORD_HEADER is 4 bytes + let ndefLen = UInt16(uriCount + 5) // NDEF_RECORD_HEADER_SHORT + len + "U" + 0 /// Fifth Command: Read the Length of the NDEF File // 00b0 00 00 02 if NDEF_READ_BINARY_NLEN == commandApdu { logger.info("NDEF_READ_BINARY_NLEN triggered. Our Response: length \(ndefLen) + A_OKAY")