Merge branch 'master' into epassport-extended-docnum
Signed-off-by: Iceman <iceman@iuse.se>
This commit is contained in:
5 files changed
+137
-5
No files matched your search
@@ -4,6 +4,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
|
||||
|
||||
## [unreleased][unreleased]
|
||||
- Fixed `tools/ePassport` - the personal number read from the MRZ optional-data field showed a filler character where a space belonged, and a document number longer than nine characters left its overflow there (@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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -305,6 +305,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
|
||||
|
||||
@@ -50,11 +50,27 @@ 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."""
|
||||
"""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"
|
||||
|
||||
|
||||
@@ -66,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(
|
||||
[
|
||||
@@ -109,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(
|
||||
[
|
||||
@@ -187,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."
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user