From f55a960c53f7ce7edff02ffb01e070a8e971d97e Mon Sep 17 00:00:00 2001 From: Paul Kilar Date: Tue, 1 Sep 2026 14:02:09 -0400 Subject: [PATCH 1/2] ePassport: keep the personal number caption on one line "Personal number (from DG13)" renders 203px wide and the caption column is dp(190), so it wrapped and left the source sitting on a line of its own. Without the "from" it comes to 167px and fits, with room to spare over the 140px of the longest caption already in that tab. Co-Authored-By: Claude Opus 5 --- CHANGELOG.md | 1 + tools/ePassport/epassport/ui/tabs/pages.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dde66bee..9440909c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Fixed `tools/ePassport` - the PERSONAL tab's personal-number caption wrapped, dropping the source onto a line of its own (@pkilar) - Added `tools/ePassport` - EF_DG13 is decoded, and a Polish document's PESEL is shown as the personal number when it carries no EF_DG11 (@pkilar) - Fixed `tools/ePassport` - a disabled button drew Kivy's banded disabled texture, which left its label unreadable (@pkilar) - Fixed `hf 14b` - a card asking for a waiting time extension of 4 or more left the timeout at zero, so any ISO14443-B card needing time to answer looked like it had stopped responding (@pkilar) diff --git a/tools/ePassport/epassport/ui/tabs/pages.py b/tools/ePassport/epassport/ui/tabs/pages.py index a11f90f7c..2440840f4 100644 --- a/tools/ePassport/epassport/ui/tabs/pages.py +++ b/tools/ePassport/epassport/ui/tabs/pages.py @@ -51,10 +51,15 @@ class DetailPage(TabPage): def _personal_number_label(record) -> str: - """Name the source when it is not DG11, so the row is not misread.""" + """Name the source when it is not DG11, so the row is not misread. + + Without the "from" it fits the caption column: dp(190) holds 167px of + "Personal number (DG13)" but not the 203px the longer wording needs, and + a caption that wraps drops the source onto a line of its own. + """ source = record.personal_number_source if source in ("MRZ", "DG13"): - return f"Personal number (from {source})" + return f"Personal number ({source})" return "Personal number" From ce9148d9ada5fd72525aa1ce44f015931322c52f Mon Sep 17 00:00:00 2001 From: Paul Kilar Date: Tue, 1 Sep 2026 14:17:22 -0400 Subject: [PATCH 2/2] ePassport: name the files each detail tab actually drew from MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tab headers carried their file names as fixed text - "Additional personal details · EF_DG11" - so a Polish passport, which ships DG13 and no DG11, was told its details came from a file it does not carry. The ISSUER header claimed EF_DG12 on the same document, and SECURITY listed EF_DG15 whether or not it was there. personal_files, document_files and security_files report what each tab drew from, and the pages compose their header from those. They sit on the record rather than in the widgets so they can be tested without a display, which is how the rest of the suite is built. PERSONAL names EF_DG1 when the personal number came from the MRZ, that being the file which supplied it, rather than crediting DG11 for a value DG11 did not provide. With nothing read the header stays the bare description: the record is an empty PassportRecord at startup rather than None, and reporting an absence on a chip nobody read reads as a fault. "none present" rather than "nothing on this chip", since the app opens offline dumps too. The same document showed the other half of this: "Personal number (from DG13)" renders 203px against a dp(190) caption column, so it wrapped and left the source on a line of its own. Without the "from" it is 167px. Co-Authored-By: Claude Opus 5 --- CHANGELOG.md | 2 +- tools/ePassport/epassport/app.py | 8 ++- tools/ePassport/epassport/emrtd/model.py | 32 ++++++++++ tools/ePassport/epassport/ui/tabs/pages.py | 18 ++++++ tools/ePassport/tests/test_tab_sources.py | 74 ++++++++++++++++++++++ 5 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 tools/ePassport/tests/test_tab_sources.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 9440909c7..1b2215dd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] -- Fixed `tools/ePassport` - the PERSONAL tab's personal-number caption wrapped, dropping the source onto a line of its own (@pkilar) +- Fixed `tools/ePassport` - the detail tabs named the files their data came from as fixed text, so a document without EF_DG11 was told otherwise, and the personal-number caption wrapped (@pkilar) - Added `tools/ePassport` - EF_DG13 is decoded, and a Polish document's PESEL is shown as the personal number when it carries no EF_DG11 (@pkilar) - Fixed `tools/ePassport` - a disabled button drew Kivy's banded disabled texture, which left its label unreadable (@pkilar) - Fixed `hf 14b` - a card asking for a waiting time extension of 4 or more left the timeout at zero, so any ISO14443-B card needing time to answer looked like it had stopped responding (@pkilar) diff --git a/tools/ePassport/epassport/app.py b/tools/ePassport/epassport/app.py index 02d4d1219..f20e1a636 100644 --- a/tools/ePassport/epassport/app.py +++ b/tools/ePassport/epassport/app.py @@ -263,9 +263,11 @@ class Pm3PassportApp(App): box.add_widget(plate) else: cls, title = { - 1: (PersonalPage, "Additional personal details · EF_DG11"), - 2: (IssuerPage, "Additional document details · EF_DG12"), - 3: (SecurityPage, "Document security · EF_SOD, EF_DG14, EF_DG15"), + # The files are appended by the page itself, from what + # the document actually turned out to carry. + 1: (PersonalPage, "Additional personal details"), + 2: (IssuerPage, "Additional document details"), + 3: (SecurityPage, "Document security"), 4: (FilesPage, "Dumped files"), 5: (LogPage, "pm3 client output"), }[index] diff --git a/tools/ePassport/epassport/emrtd/model.py b/tools/ePassport/epassport/emrtd/model.py index e98973ae2..15e3cf93c 100644 --- a/tools/ePassport/epassport/emrtd/model.py +++ b/tools/ePassport/epassport/emrtd/model.py @@ -294,6 +294,38 @@ class PassportRecord: "EF_DG7": self.signature_png, }.get(name.upper(), b"") + def has_file(self, name: str) -> bool: + entry = self.file(name) + return entry is not None and entry.state == FileState.PRESENT + + @property + def personal_files(self) -> list[str]: + """The files the PERSONAL tab drew from, in file order. + + Naming them beats a fixed caption: plenty of documents carry no DG11, + and the personal number can arrive from the MRZ or from DG13 instead. + """ + out = [] + if self.personal_number_source == "MRZ": + out.append("EF_DG1") + if self.has_dg(11): + out.append("EF_DG11") + if self.personal_number_source == "DG13": + out.append("EF_DG13") + return out + + @property + def document_files(self) -> list[str]: + """The files the ISSUER tab drew from.""" + return ["EF_DG12"] if self.has_dg(12) else [] + + @property + def security_files(self) -> list[str]: + """The files the SECURITY tab drew from.""" + return [ + name for name in ("EF_SOD", "EF_DG14", "EF_DG15") if self.has_file(name) + ] + def has_dg(self, number: int) -> bool: f = self.file(f"EF_DG{number}") return f is not None and f.state == FileState.PRESENT diff --git a/tools/ePassport/epassport/ui/tabs/pages.py b/tools/ePassport/epassport/ui/tabs/pages.py index 2440840f4..bb2e4547a 100644 --- a/tools/ePassport/epassport/ui/tabs/pages.py +++ b/tools/ePassport/epassport/ui/tabs/pages.py @@ -50,6 +50,17 @@ class DetailPage(TabPage): box.add_widget(KeyValueRow(key=key, value=value, palette=self.palette)) +def _titled(base: str, record, files: list[str]) -> str: + """The tab header: what the tab shows, then the files it came from. + + With nothing read there is no document to describe, so the header stays + the bare description rather than reporting an absence. + """ + if record.is_empty: + return base + return f"{base} · {', '.join(files)}" if files else f"{base} · none present" + + def _personal_number_label(record) -> str: """Name the source when it is not DG11, so the row is not misread. @@ -71,6 +82,9 @@ class PersonalPage(DetailPage): if record is None: self.set_rows([]) return + self.title = _titled( + "Additional personal details", record, record.personal_files + ) p = record.personal self.set_rows( [ @@ -114,6 +128,9 @@ class IssuerPage(DetailPage): if record is None: self.set_rows([]) return + self.title = _titled( + "Additional document details", record, record.document_files + ) d = record.document self.set_rows( [ @@ -192,6 +209,7 @@ class SecurityPage(TabPage): self.rows, self.hashes = [], [] self.headline = "No document loaded." return + self.title = _titled("Document security", record, record.security_files) sod = record.sod if not sod.available: self.headline = sod.message or "EF_SOD could not be inspected." diff --git a/tools/ePassport/tests/test_tab_sources.py b/tools/ePassport/tests/test_tab_sources.py new file mode 100644 index 000000000..d20eae07a --- /dev/null +++ b/tools/ePassport/tests/test_tab_sources.py @@ -0,0 +1,74 @@ +"""Which files each detail tab actually drew from. + +The tab headers named their files as fixed text - "Additional personal +details · EF_DG11" - so a document without DG11 was told its details came +from a file it does not carry, and the SECURITY header listed EF_DG15 whether +or not it was there. +""" + +from __future__ import annotations + +from pathlib import Path + +from epassport.emrtd import dg, tlv +from epassport.emrtd.model import PassportRecord +from epassport.emrtd.mrz import Checked, Mrz + + +def _pesel_dg13(digits: str = "10030912345") -> bytes: + return tlv.encode( + 0x6D, tlv.encode(0x5C, b"\x5f\x70") + tlv.encode(0x5F70, digits.encode()) + ) + + +def _polish_record() -> PassportRecord: + """DG13 and no DG11, the shape that exposed this.""" + record = PassportRecord() + blank = Checked("") + record.mrz = Mrz( + kind="TD3", + lines=[], + document_number=blank, + date_of_birth=blank, + date_of_expiry=blank, + composite=blank, + nationality="POL", + optional_data=Checked(""), + ) + record.optional = dg.parse_dg13(_pesel_dg13()) + return record + + +def test_personal_names_dg11_when_the_document_carries_it(td3: Path) -> None: + assert "EF_DG11" in dg.load_dump(td3).personal_files + + +def test_personal_names_dg13_when_that_is_where_the_number_came_from() -> None: + record = _polish_record() + assert record.personal_files == ["EF_DG13"] + assert "EF_DG11" not in record.personal_files + + +def test_personal_names_nothing_when_nothing_fed_it(tmp_path: Path) -> None: + assert dg.load_dump(tmp_path).personal_files == [] + + +def test_document_follows_dg12(td3: Path, td1: Path) -> None: + assert dg.load_dump(td3).document_files == ["EF_DG12"] + assert dg.load_dump(td1).document_files == [] + + +def test_security_lists_only_the_files_that_are_there(td3: Path) -> None: + files = dg.load_dump(td3).security_files + assert "EF_SOD" in files + assert files == [f for f in ("EF_SOD", "EF_DG14", "EF_DG15") if f in files] + + +def test_security_drops_a_missing_dg15(tmp_path: Path, td3: Path) -> None: + import shutil + + for name in ("EF_SOD.bin", "EF_DG14.bin"): + shutil.copy(td3 / name, tmp_path / name) + files = dg.load_dump(tmp_path).security_files + assert "EF_DG15" not in files + assert "EF_DG14" in files