-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: support for Belgian eID cards #104
Open
yoe
wants to merge
19
commits into
frankmorgner:master
Choose a base branch
from
yoe:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
99ff2a4
Start work on adding a belpic implementation
yoe 793a305
Do not allow creation of files
yoe 5c6c522
Upon initialisation, read the XML file
yoe 8e6266a
Initialize the Belpic card as a BelpicMF
yoe 0751076
Update TODO note
yoe 6bba615
Add an example XML file
yoe cdbe8fc
Clarify this here, too
yoe 9dc0f73
Disable coverity for fork...
yoe a8ca1d3
Make the Relay card still parse and log the APDU
yoe e3a1aac
Allow for unparsed logging
yoe efb57b0
Only respond to the commands that this card actually implements
yoe ddc0df1
Make the virtual card act slightly more like an actual belpic card
yoe a53b172
Drop unneeded function
yoe fb7ec85
Add note of what we're doing here
yoe 5fc6018
Filter the SELECT FILE command
yoe 5eb000d
Filter out warnings
yoe 03a1136
Add one more TODO item
yoe 75f5b49
Make sure these files actually have some content
yoe e65e13a
Drop bogus TODO item (the MF works, the SAM doesn't yet)
yoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,15 +82,6 @@ before_script: | |
./configure OPENSC_LIBS="-L$PREFIX/lib -lopensc" || cat config.log; | ||
fi | ||
|
||
addons: | ||
coverity_scan: | ||
project: | ||
name: "frankmorgner/vsmartcard" | ||
description: "Umbrella project for various projects concerned with the emulation of different types of smart card readers or smart cards themselves" | ||
notification_email: [email protected] | ||
build_command: make -C $TRAVIS_BUILD_DIR/virtualsmartcard -C $TRAVIS_BUILD_DIR/ccid -C $TRAVIS_BUILD_DIR/pcsc-relay | ||
branch_pattern: master | ||
|
||
script: | ||
# Build virtualsmartcard | ||
- make -C $TRAVIS_BUILD_DIR/virtualsmartcard | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The .xml file in this directory was generated by [the scripts in the | ||
eid-test-cards project](https://github.com/Fedict/eid-test-cards). We'll | ||
make this look better at some point in the future, but not now. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
virtualsmartcard/src/vpicc/virtualsmartcard/cards/belpic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# | ||
# Copyright (C) 2017 Wouter Verhelst, Federal Public Service BOSA, DG DT | ||
# | ||
# This file is part of virtualsmartcard. | ||
# | ||
# virtualsmartcard is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License as published by the Free | ||
# Software Foundation, either version 3 of the License, or (at your option) any | ||
# later version. | ||
# | ||
# virtualsmartcard 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 | ||
# virtualsmartcard. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from virtualsmartcard.VirtualSmartcard import Iso7816OS | ||
from virtualsmartcard.ConstantDefinitions import MAX_SHORT_LE, FDB, LCB, REF | ||
from virtualsmartcard.SmartcardFilesystem import MF, DF, TransparentStructureEF | ||
from virtualsmartcard.SWutils import SW, SwError | ||
from virtualsmartcard.utils import C_APDU, R_APDU | ||
|
||
import logging | ||
|
||
import xml.etree.ElementTree as ET | ||
|
||
class BelpicOS(Iso7816OS): | ||
def __init__(self, mf, sam, ins2handler=None, maxle=MAX_SHORT_LE): | ||
Iso7816OS.__init__(self, mf, sam, ins2handler, maxle) | ||
self.ins2handler = { | ||
0xc0: self.getResponse, | ||
0xa4: self.mf.selectFile, | ||
0xb0: self.mf.readBinaryPlain, | ||
0x20: self.SAM.verify, | ||
0x24: self.SAM.change_reference_data, | ||
0x22: self.SAM.manage_security_environment, | ||
0x2a: self.SAM.perform_security_operation, | ||
0xe4: self.getCardData, | ||
0xe6: self.logOff | ||
} | ||
self.atr = '\x3B\x98\x13\x40\x0A\xA5\x03\x01\x01\x01\xAD\x13\x11' | ||
|
||
# TODO: don't hardcode the value below, so that we can also emulate the v1.1 applet | ||
def getCardData(self, p1, p2, data): | ||
return SW["NORMAL"], "534C494E0123456789ABCDEF01234567F3360125011700030021010f".decode("hex") | ||
|
||
# TODO: actually log off | ||
def logOff(self, p1, p2, data): | ||
return SW["NORMAL"] | ||
|
||
def execute(self, msg): | ||
c = C_APDU(msg) | ||
if (c.ins == 0xa4 and c.p1 == 0x02): | ||
# The belpic applet is a bit loose with interpretation of | ||
# the ISO 7816 standard on the A4 command: | ||
# - The MF can be selected by name from anywhere with P1 == | ||
# 0x02, rather than 0x00 as ISO 7816 requires | ||
if (c.data == '3F00'.decode('hex')): | ||
logging.info("Original APDU:\n%s\nRewritten to:\n", str(c)) | ||
c.p1 = 0 | ||
msg = c.render() | ||
# - Child DFs can be selected with P1 == 0x02, rather than | ||
# 0x01 as ISO 7816 requires | ||
if (c.data == 'DF00'.decode('hex') or c.data == 'DF01'.decode('hex')): | ||
logging.info("Original APDU:\n%s\nRewritten to:\n", str(c)) | ||
c.p1 = 1 | ||
msg = c.render() | ||
return Iso7816OS.execute(self, msg) | ||
|
||
def formatResult(self, seekable, le, data, sw, sm): | ||
r = R_APDU(Iso7816OS.formatResult(self, seekable, le, data, sw, sm)) | ||
# The Belpic applet provides a bogus file length of 65536 for | ||
# every file, and does not return an error or warning when the | ||
# actual file length is shorter that the file as found; so | ||
# filter out the EOFBEFORENEREAD warning | ||
if (r.sw1 == 0x62 and r.sw2 == 0x82): | ||
logging.info("Filtering out warning") | ||
r.sw = "9000".decode("hex") | ||
return r.render() | ||
|
||
class BelpicMF(MF): | ||
def __init__(self, datafile, filedescriptor=FDB["NOTSHAREABLEFILE" ] | FDB["DF"], | ||
lifecycle=LCB["ACTIVATED"],simpletlv_data = None, bertlv_data = None): | ||
MF.__init__(self, filedescriptor, lifecycle, simpletlv_data, bertlv_data, dfname = "A00000003029057000AD13100101FF".decode('hex')) | ||
tree = ET.parse(datafile) | ||
root = tree.getroot() | ||
ns = {'f': 'urn:be:fedict:eid:dev:virtualcard:1.0'} | ||
DF00 = DF(self, 0xDF00, dfname="A000000177504B43532D3135".decode('hex')) | ||
self.append(DF00) | ||
DF01 = DF(self, 0xDF01) | ||
self.append(DF01) | ||
parent = self | ||
fid = 0 | ||
for f in root.findall('f:file', ns): | ||
id = f.find('f:id', ns).text | ||
content = f.find('f:content', ns).text | ||
if content is not None: | ||
if(len(id) == 12): | ||
fid = int(id[8:], 16) | ||
if (id[4:8] == 'DF00'): | ||
parent = DF00 | ||
if (id[4:8] == 'DF01'): | ||
parent = DF01 | ||
else: | ||
fid = int(id[4:], 16) | ||
parent.append(TransparentStructureEF(parent, fid, data = content.decode('hex'))) | ||
|
||
def select(self, attribute, value, reference=REF["IDENTIFIER_FIRST"], index_current=0): | ||
if (hasattr(self, attribute) and | ||
((getattr(self, attribute) == value) or | ||
(attribute == 'dfname' and | ||
getattr(self, attribute).startswith(value)))): | ||
return self | ||
return DF.select(self, attribute, value, reference, index_current) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo