Droidcedas : Emulating A Pki Smart Carte Alongside Cyanogenmod 9.1
PKI has been getting a lot of bad rep due to major CAs getting compromised every other month, together with it has been stated multiple times that it
secure element available inwards recent Android devices, it's
cloud-based NFC secure element. We, however, volition await at a different work case: PKI.
PKI has been getting a lot of bad rep due to major CAs getting compromised every other month, together with it has been stated multiple times that it execution environment together with how cloud-based NFC secure element. We, however, volition await at a different work case: PKI. PKI has been getting a lot of bad rep due to major CAs getting compromised every other month, together with it has been stated multiple times that it
Google Wallet makes work if it inwards the in conclusion serial of articles. We also saw that unless y'all have got a contract amongst Google together with have got them (or the TSM they use) distribute your applets to supported devices, at that topographic point is currently no way to install anything on the embedded secure element. We briefly mentioned that
CyanogenMod 9.1
supports software carte emulation together with it is a to a greater extent than practical way to create your ain NFC-enabled applications. We'll instantly come across how software carte emulation plant together with exhibit how y'all tin work it to create a elementary PKI 'applet' that tin last accessed via NFC from whatsoever machine amongst a contactless carte reader.
Software carte emulation
We already know that if the embedded secure chemical component is seat inwards virtual vogue it is visible to external readers every bit a contactless smartcard. Software carte emulation (sometimes referred to every bit Host Card Emulation or HCE) does something really similar, but instead of routing commands received past times the NFC controller to the SE, it delivers them to the application processor, together with they tin last processed past times regular applications. Responses are together with so sent via NFC to the reader, together with thence your app takes the role of a virtual contactless 'smartcard' (refer to
this paper for a to a greater extent than thorough discussion). Software carte emulation is currently available on BlackBerry phones, which offering criterion
APIs for apps to register amongst the OS together with procedure carte commands received over NFC. Besides a BlackBerry device, y'all tin work some contactless readers inwards emulation vogue to emulate NFC tags or a full-featured smart card. Stock Android doesn't (yet) back upwardly software carte emulation, fifty-fifty though the NFC controllers inwards around electrical flow phones have got this capability. Fortunately, recent version of
CyanogenMod integrate a
set of patches that unlock this functionality of the
PN544 NFC controller flora inwards recent Nexus (and other) devices. Let's come across how it plant inwards a flake to a greater extent than detail.
CyanogenMod implementation
Android doesn't render a direct interface to its NFC subsystem to user-level apps. Instead, it leverages the OS's intent together with intent filter infrastructure to permit apps register for a especial NFC trial (
ACTION_NDEF_DISCOVERED
,
ACTION_TAG_DISCOVERED
together with
ACTION_TECH_DISCOVERED
) together with specify additional filters based on tag type or features. When a matching NFC tag is found, interested applications are notified together with i of them is selected to handgrip the event, either past times the user or automatically if it is inwards the foreground together with has registered for
foreground dispatch. The app tin together with so access a generic
Tag
object representing the target NFC device together with work it to recall a concrete
tag technology interface such every bit
MifareClassic
or
IsoDep
that lets it communicate amongst the device together with work its native features. Card emulation back upwardly inwards CyanogenMod doesn't endeavour to alter or improve Android's NFC architecture, but integrates amongst it past times adding back upwardly for 2 novel tag technologies:
IsoPcdA
together with
IsoPcdB
. 'ISO' here is the
International Organization for Standardization, which amid other things, is responsible for defining NFC communication standards. 'PCD' stands for Proximity Coupling Device, which is precisely ISO-speak for a contactless reader. The 2 classes comprehend the 2 principal NFC flavours inwards work today (outside of Japan, at least) -- Type Influenza A virus subtype H5N1 (based on NXP technology) together with Type B (based on Motorolla technology). As y'all mightiness have got guessed past times now, the patch reverses the usual roles inwards the Android NFC API: the external contactless reader is presented every bit a 'tag', together with 'commands' y'all shipping from the telephone are genuinely replies to the reader-initiated communication. If y'all have got Google Wallet installed the embedded secure chemical component is activated every bit well, so touching the telephone to a reader would create a potential conflict: should it road commands to the embedded SE or to applications than tin handgrip
IsoPcdA/B
tags? The CyanogenMod patch handles this past times using Android's native foreground dispatch mechanism: software carte emulation is only enabled for apps that register for foreground dispatch of the relevant tag technologies. So unless y'all have got an emulation app inwards the foreground, all communication would last routed to Google Wallet (i.e., the embedded SE). In exercise though, starting upwardly Google Wallet on ROMs amongst the electrical flow version of the patch mightiness block software carte emulation, so it plant best if Google Wallet is non installed. Influenza A virus subtype H5N1 laid upwardly is
available, but non yet merged in CyanogenMod master copy (Updated: instantly merged, should ringlet out amongst CM10 nightlies) .
Both of the newly introduced tag technologies extend
BasicTagTechnology
together with offering methods to open, banking concern check together with unopen the connexion to the reader. They add together a world
transceive()
method that acts every bit the principal communication interface: it receives reader commands together with sends the responses generated past times your app to the PCD. Here's a summary of the interface:
abstract course of education BasicTagTechnology implements TagTechnology { world boolean isConnected() {...} world void connect() throws IOException {...} world void reconnect() throws IOException {...} world void close() throws IOException {...} byte[] transceive(byte[] data, boolean raw) throws IOException {...} }
Now that nosotros know (basically) how it works, let's attempt to work software carte emulation inwards practice.
Emulating a contactless card
As discussed inwards the previous section, to last able to respond to reader commands nosotros ask to register our app for i of the PCD tag technologies together with enable foreground dispatch. This is no different than treatment stock-supported NFC technologies. We ask to add together an intent filter together with a reference to a applied scientific discipline filter file to the app's manifest:
<activity android:label="@string/app_name" android:launchmode="singleTop" android:name=".MainActivity" <intent-filter> <action android:name="android.nfc.action.TECH_DISCOVERED" /> </intent-filter> <meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/filter_nfc" /> </activity>
We register the
IsoPcdA
tag applied scientific discipline inwards
filter_nfc.xml
:
<resources> <tech-list> <tech>android.nfc.tech.IsoPcdA</tech> </tech-list> </resources>
And together with so work the same applied scientific discipline listing to register for foreground dispatch inwards our activity:
public course of education MainActivity extends Activity { world void onCreate(Bundle savedInstanceState) { pendingIntent = PendingIntent.getActivity(this, 0, novel Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); filters = novel IntentFilter[] { novel IntentFilter( NfcAdapter.ACTION_TECH_DISCOVERED) }; techLists = novel String[][] { { "android.nfc.tech.IsoPcdA" } }; } world void onResume() { super.onResume(); if (adapter != null) { adapter.enableForegroundDispatch(this, pendingIntent, filters, techLists); } } world void onPause() { super.onPause(); if (adapter != null) { adapter.disableForegroundDispatch(this); } } }
With this inwards place, each fourth dimension the telephone is touched to an active reader, nosotros volition teach notified via the activity's
onNewIntent()
method. We tin teach a reference to the
Tag
object using the intent's extras every bit usual. However, since neither
IsoPcdA
nor its superclass are component subdivision of Blue Planet SDK, nosotros ask to either construct the app every bit component subdivision of CyanogenMod's source, or, every bit usual, resort to reflection. We select to create a elementary wrapper course of education that calls
IsoPcdA
methods via reflection, later getting an illustration using the static
get()
method similar this:
Class cls = Class.forName("android.nfc.tech.IsoPcdA"); Method teach = cls.getMethod("get", Tag.class); // this returns an IsoPcdA illustration tagTech = get.invoke(null, tag);
Now later nosotros
connect()
nosotros tin work the
transceive()
method to respond to reader commands. Note that since the API is non event-driven, y'all won't teach notified amongst the reader command automatically. You ask to shipping a dummy payload to recall the get-go reader command APDU. This tin last a flake awkward at first, but y'all precisely have got to travel on inwards heed that each fourth dimension y'all telephone call upwardly
transceive()
the side past times side reader command comes inwards via the render value. Unfortunately this way that later y'all shipping your in conclusion response, the thread volition block on I/O waiting for
transceive()
to return, which only happens later the reader sends its side past times side command, which mightiness last never. The thread volition only halt if an exception is thrown, such every bit when communication is lost later separating the telephone from the reader. Needless to say, this makes writing robust code a flake tricky. Here's how to start off the communication:
// shipping dummy information to teach get-go command APDU // at to the lowest degree 2 bytes to travel on smartcardio happy byte[] cmd = transceive(new byte[] { (byte) 0x90, 0x00 });
Writing a virtual PKI applet
Software carte emulation inwards CyanogneMod is express to ISO 14443-4 (used generally for APDU-based communication), which way that y'all cannot emulate cards that operate on a lower-level protocol such every bit MIFARE Classic. This leaves out opening door locks that rely on the carte UID amongst your telephone (the UID of the emulated carte is random) or getting a gratis ride on the subway scheme (you cannot clone a traffic carte amongst software alone), but allows for emulating payment (EMV) cards which work an APDU-based protocol. In fact, the get-go commercial application (
cloud-based NFC secure element. We, however, volition await at a different work case: PKI.
PKI has been getting a lot of bad rep due to major CAs getting compromised every other month, together with it has been stated multiple times that it
doesn't genuinely work on the Internet. It is nevertheless soundless a valid way of authentication inwards a corporate surroundings where personal certificates are used for anything from desktop login to remote VPN access. Certificates together with associated individual keys are ofttimes distributed on smart cards, sometimes contactless or dual-interface. Since Android instantly has criterion
cloud-based NFC secure element. We, however, volition await at a different work case: PKI.
PKI has been getting a lot of bad rep due to major CAs getting compromised every other month, together with it has been stated multiple times that it
. We, however, volition await at a different work case: PKI.
0 Komentar untuk "Droidcedas : Emulating A Pki Smart Carte Alongside Cyanogenmod 9.1"