Грешка приликом читања личне карте за странце
X3KT0 opened this issue · 21 comments
Графички Баш Челик одма улази у циклус "читање-грешка".
CLI верзия каже "Error saving document: reading card: reading card: reading document 0 file: parsing file header: invalid length" па се завршава.
Исти баш челик са истим хардвер читачом ради са картицом здравственог осигурања на истом рачунару (онда проблем није у хардверу).
Исти хардвер читач добро ради са проблематичном картом на другом рачунару со Виндовзом (онда проблем није у карти).
ЛК има на себи сертификате.
ATR је 3bff9400008131804380318065b0850201f3120fff82900079
Издата је у априлу 2023.
Немам држављанске карте, онда не могу да проверим са њом.
Preći ću na engleski, pošto mislim da ćemo se tako lakše razumeti:
First, thank you for bringing this up, and thank you for very detailed description of the problem. I suppose you have ID card for foreigners, and it has a slightly different structure of data on card. As BasCelik is developed completely independently from official apps, there are some edge cases like this that I didn't cover. Unfortunately, I don't have access to ID cards for foreigners on which I could test, so I can't resolve bug, even if I am pretty sure what is happening.
You can try to fix bug yourself (I can introduce you to the code and the workflow), or maybe we could meet for a coffee so I could see what is exactly happening (if you are in Belgrade).
Thank you for the answer.
I'm not in Belgrade, but sometimes go there.
Will contact you by email before that (I found your email address on your website).
I will answer here your question from #29 about reading from smart cards (because that issue isn't a bug, a this really is).
There is no way (AFAIK) you can read all data from smart card. Smart card behaves like small filesystem, and data is divided into 'files'. Each file has an address, and you must send a request with the exact address to be able to read that file.
On Serbian ID cards, data is stored in 4 files.
Because the Serbian vehicle card has the same ATR as the Serbian ID card, Bas Celik tries to distinct these two documents by reading DOCUMENT_FILE
on address 0f02
. This file is present on ID cards but not on vehicle cards. But, it seems that cards for foreigners don't have this file, and therefore your card is wrongly processed as a vehicle card.
Please, in card.go
, on line 41, change
tempIdCard := Gemalto{smartCard: sc}
if tempIdCard.testGemalto() {
card = Gemalto{smartCard: sc}
} else {
card = VehicleCard{smartCard: sc}
}
to
card = Gemalto{smartCard: sc}
This will force the program to process your card as an ID card.
Your card will be processed inside readIdCard
form idCard.go
. You can add there fmt.Printf
to see raw data. That function will fail because your card don't have file on the address 0f02
. You can modify this function to see if other files are present. For example, replace the whole function with this:
func readIdCard[Id IdDocument](card Id) (*document.IdDocument, error) {
doc := document.IdDocument{}
rsp, err := card.readFile(DOCUMENT_FILE_LOC, false)
if err != nil {
fmt.Println("reading document file:", err)
} else {
fields, err := parseTLV(rsp)
if err != nil {
fmt.Println(err)
} else {
assignField(fields, 1546, &doc.DocumentNumber)
assignField(fields, 1547, &doc.DocumentType)
assignField(fields, 1548, &doc.DocumentSerialNumber)
assignField(fields, 1549, &doc.IssuingDate)
assignField(fields, 1550, &doc.ExpiryDate)
assignField(fields, 1551, &doc.IssuingAuthority)
localization.FormatDate(&doc.IssuingDate)
localization.FormatDate(&doc.ExpiryDate)
}
}
rsp, err = card.readFile(PERSONAL_FILE_LOC, false)
if err != nil {
fmt.Println("reading personal file:", err)
} else {
fields, err := parseTLV(rsp)
if err != nil {
fmt.Println(err)
} else {
assignField(fields, 1558, &doc.PersonalNumber)
assignField(fields, 1559, &doc.Surname)
assignField(fields, 1560, &doc.GivenName)
assignField(fields, 1561, &doc.ParentGivenName)
assignField(fields, 1562, &doc.Sex)
assignField(fields, 1563, &doc.PlaceOfBirth)
assignField(fields, 1564, &doc.CommunityOfBirth)
assignField(fields, 1565, &doc.StateOfBirth)
assignField(fields, 1566, &doc.DateOfBirth)
localization.FormatDate(&doc.DateOfBirth)
}
}
rsp, err = card.readFile(RESIDENCE_FILE_LOC, false)
if err != nil {
fmt.Println("reading residence file:", err)
} else {
fields, err := parseTLV(rsp)
if err != nil {
fmt.Println(err)
} else {
assignField(fields, 1568, &doc.State)
assignField(fields, 1569, &doc.Community)
assignField(fields, 1570, &doc.Place)
assignField(fields, 1571, &doc.Street)
assignField(fields, 1572, &doc.AddressNumber)
assignField(fields, 1573, &doc.AddressLetter)
assignField(fields, 1574, &doc.AddressEntrance)
assignField(fields, 1575, &doc.AddressFloor)
assignField(fields, 1578, &doc.AddressApartmentNumber)
assignField(fields, 1580, &doc.AddressDate)
localization.FormatDate(&doc.AddressDate)
}
}
rsp, err = card.readFile(PHOTO_FILE_LOC, true)
if err != nil {
fmt.Println("reading photo file:", err)
} else {
doc.Portrait, _, err = image.Decode(bytes.NewReader(rsp))
if err != nil {
fmt.Println("decoding photo file:", err)
}
}
return &doc, nil
}
If you don't conclude anything from this, then we need to peek into the official app to see how it communicates with foreigners cards.
Btw, I suppose that you know how to compile go programs. Compiling Bas Celik should not be a problem on Linux. If you want to skip building the whole GUI version you can do:
go build -tags "cli" .
Thank you for the help!
I managed to compile it with the patches you gave. Actually, with the first one only, because after applying it, the program stops with Error saving document: reading card: initializing card: initializing card: response not OK
I think we have two possible ways: either I take my card and go to Belgrade; or I can install linux on a machine with the cardreader plugged in and give you an ssh access to it (if you like the idea, of course).
Hm, interesting. It seem that ID cards for foreigners have different initialization sequence. This complicates things
Very cool idea with ssh :) We can try that, but I am afraid I will have to test your card with the official app. Then I will be able to see exactly what data is transferred to the card.
BTW, if you are in NS, or somewhere near BG, I can drop by there.
Feel free to send me a mail when you have time