Table of Contents
Phần trước đã tìm hiểu cách tổ chức thư mục và cách lưu dữ liệu trên thể CCCD.
Phần này sẽ tìm hiểu làm thế nào để đọc được nội dung thông tin, hình ảnh
trong thẻ CCCD.
Hardware
Mình sử dụng thiết bị IDENTIV hỗ trợ chuẩn ISO/IEC 7810. Bạn cũng có thể sử
dụng thiết bị bất kỳ.
Software
Sử dụng code mẫu của chương trình scsh3. Do làm lâu không còn nhớ các
"EL.DG" xem code thì nhớ DL2 là vùng nhớ chứa hình ảnh.
Để đọc được sẽ cần mã hóa PDU bằng giao thức "PACE protocol". Mỗi thẻ CCCD
sẽ có một mã riêng "xxx" bạn nào làm có thể nhắn riêng tránh mục đích xấu.
Sau quá trình xác thực thành công tiếp bạn sẽ có khả năng đọc các vùng nhớ
trên thể. Vùng security sẽ chứa 16 mã hash cho các vùng "EL.DG 1,2,3" để đảm
bảo tính toàn vện
Code mẫu
/** * --------- * |.##> <##.| Open Smart Card Development Platform (www.openscdp.org) * |# #| * |# #| Copyright (c) 1999-2009 CardContact Software & System Consulting * |'##> <##'| Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de) * --------- * * This file is part of OpenSCDP. * * OpenSCDP is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * OpenSCDP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with OpenSCDP; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @fileoverview Do a complete eID authentication session with PACE, TA and CA */ load("scsh/eac/EAC20.js"); load("scsh/file/File.js"); var can = "xxx"; // Create the crypto object we require to perform all cryptographic operations var crypto = new Crypto(); // Allocate a certificate store that contains the required certificate chain and // a key for terminal authentication var certstorepath = GPSystem.mapFilename("cvc", GPSystem.CWD); var terminalpath = "/UTISCVCA/UTISDVCAOD/UTTERM"; var path_img = GPSystem.mapFilename("image.jpg", GPSystem.CWD); // Create object to access certificate store // var certstore = new CVCertificateStore(certstorepath); // Allocate a card object for access to the card var card = new Card(_scsh3.reader); var file = new File("image.bin", "./"); // Reset the card card.reset(Card.RESET_COLD); // Define the CHAT object we use for the PACE protocol var chat = new ASN1(0x7F4C, new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString(PACE.id_IS, OID)), new ASN1(0x53, new ByteString("23", HEX)) ); // Create an EAC object that controls the protocol execution var eac = new EAC20(crypto, card); eac.verbose = true; print("Reading EF.CardInfo..."); eac.readCardInfo(); print("Performing PACE..."); var pwd = new ByteString(can, ASCII); var sm = eac.performPACE(0, EAC20.ID_CAN, pwd, chat); print("Performing TA..."); // Determine current trust anchor in nPA var car = eac.getTrustAnchorCAR(false); print("Reading EF.CardSecurity..."); var securityInfos = eac.readCardSecurity(); print("Algorithm: ", securityInfos.get(1)); var lds_hash_obj = securityInfos.get(2) var array_lds = [] for(var ilds = 0; ilds < lds_hash_obj.elements; ilds++){ var ef = lds_hash_obj.get(ilds); print(ef.get(0).value, ef.get(1).value) array_lds.push({'EL.DG': parseInt(ef.get(0).value, 16), 'HASH': ef.get(1).value}) } eac.select_eID(); var file = new java.io.FileOutputStream(path_img); for(var ilds = 0; ilds < array_lds.length; ilds++){ try{ var lds = array_lds[ilds]; print("DG: ", lds['EL.DG']) // Read DG using short file identifier var dg = eac.readEFwithSFI(lds['EL.DG']); if(lds['EL.DG'] == 0){ }else if(lds['EL.DG'] == 1){ }else if(lds['EL.DG'] == 2){ var match = ByteString.valueOf(0xFFD8FFE0, 4); var cstlv = new ASN1(dg); var img = cstlv.get(0).get(1).get(1); var offset_img = img.value.find(ByteString.valueOf(0xFFD8FFE0, 4)); var image = img.value.right(img.value.length - offset_img); print(image) file.write(image); file.close(); }else if(lds['EL.DG'] == 13){ }else if(lds['EL.DG'] == 14){ }else if(lds['EL.DG'] == 15){ }else{ } // print(dg); } catch(err) { print(err) } }
Vùng EL.DG 2 chứa IMG và có thể trích xuất ra file như trên.
SET SIZE( 36 ) SEQUENCE SIZE( 34 ) OBJECT IDENTIFIER = { id-at-organizationName } UTF8-STRING SIZE( 27 ) 0000 4D 69 6E 69 73 74 72 79 20 6F 66 20 50 75 62 6C Ministry of Publ 0010 69 63 20 53 65 63 75 72 69 74 79 ic Security SET SIZE( 72 ) SEQUENCE SIZE( 70 ) OBJECT IDENTIFIER = { id-at-organizationalUnitName } UTF8-STRING SIZE( 63 ) 0000 50 6F 6C 69 63 65 20 44 65 70 61 72 74 6D 65 6E Police Departmen 0010 74 20 66 6F 72 20 41 64 6D 69 6E 69 73 74 72 61 t for Administra 0020 74 69 76 65 20 4D 61 6E 61 67 65 6D 65 6E 74 20 tive Management 0030 6F 66 20 53 6F 63 69 61 6C 20 4F 72 64 65 72 of Social Order SET SIZE( 54 ) SEQUENCE SIZE( 52 ) OBJECT IDENTIFIER = { id-at-commonName } UTF8-STRING SIZE( 45 ) 0000 44 6F 63 75 6D 65 6E 74 20 53 69 67 6E 65 72 20 Document Signer 0010 4E 61 74 69 6F 6E 61 6C 20 49 64 65 6E 74 69 66 National Identif 0020 69 63 61 74 69 6F 6E 20 30 30 30 32 39 ication 00029
Anh chị em mà biết các ý nghĩa vùng DG1, .... chứa thông tin gì nhớ comment
lại cho mọi người được biết
Nguồn: https://v-xs.com/
Backup: https://archive.org/