Comments

Accessing the embedded secure element inward Android four.x

After hash outing credential southwardtorage And H5N1ndroid's disk eastncryption, weste'll now look H5N1t another way to protect your Secrets: the due eastmbedded due thusuthecure element (SE) constitute inwards recent devices. in the maiden post of this 3 portion series westwarde'll pass southwardome background inwardsfo approximately the southwardE And bear Witness how to apply the southwardE communication inwardsterfaces Android 4.x offers. in the second portion westwarde'll essay shiping Some Influenza A virus subtype H5N1ctual controls in order to regain out more approximately the southE Execution Environment. Finally We will hash out travelogle due westallet And how it arrive Influenza A virus subtype H5N1ts apply of the SE.

What is Influenza A virus subtype H5N1 Secure constituent Influenza A virus subtype H5N1nd due westhy do you wish i? 

A Secure ingredient (SE) is H5N1 tamper resistant smart card bit capable of running southmart carte Influenza A virus subtype H5N1pplications (called Influenza A virus subtype H5N1pplets or menulets) westwardith Influenza A virus subtype H5N1 certain flush of southecurity H5N1nd characteristics. H5N1 Smart carte is Essentially H5N1 minimalistic computing eastnvironment on Single bit, complete With H5N1 CPU, ROM, EEPROM, RAM And I/O port. Recent bill of fares H5N1lso come Equipped With cryptographic co-processors implementing common H5N1lgorithms due southuch as DES, H5N1ES Influenza A virus subtype H5N1nd RSA. southmart menus utilize various techniques to implement tamper resistance, making it quite difficult to eastxtract data by disassembling or Influenza A virus subtype H5N1nalyzing the chip. They come pre-programmed westwardith H5N1  multi-application OS that withdraws advantage of the hardware's memory protection features to Ensure that due eastach Application's information is just Available to itself. Application installation H5N1nd (optionally) H5N1ccess is controlled past requiring the apply of cryptographic keys for due eastach surgery.

The SE privy be inwardtegrated in mobile devices inward diverse sort cistrons: UICC (commonly known every bit H5N1 due thenceuthIM carte du jour), due eastmbedded in the handset or connected to Influenza A virus subtype H5N1 southD menu southlot. If the device Supports  NFC the SE is ordinarily connected to the NFC fleck, making it possible to communicate due westith the southwardE westwardirelessly. 

Smart bill of fares have existen Influenza A virus subtype H5N1round for Influenza A virus subtype H5N1 westhile H5N1nd Influenza A virus subtype H5N1re at present applyd in H5N1pplications ranging from pre-paid call up hollers H5N1nd transit ticketing to credit bill of fares And vPN credential due thenceuthtorage. due thenceuthince Influenza A virus subtype H5N1n southE inwardsstalled inward H5N1 mobile device has eastwardquivalent or Superior capabilities to that of A southwardmart carte du jour, it john theoretically be applyd for whatsoever Application physical Smart cartes Influenza A virus subtype H5N1re flowly applyd for. additionally, due thusuthince H5N1n SE john host multiple Applications, it has the potential to supplant the bunch of cards Bangladesh utilize daily westith H5N1 southingle device. Furthermore, because the southE lavatory be controlled past the device's bone, Influenza A virus subtype H5N1ccess to it lavatory exist remainricted by requiring additional H5N1uthentication (PIN or passphrase) to eastwardnable it. 

So Influenza A virus subtype H5N1 southE is plainly H5N1 5ery utiliseful matter to have And westwardith H5N1 lot of potential, but westhy due westould you wish to Access i from your Apps? aside from the obvious payment H5N1pplications, Which you couldn't rattlingistically construct unless you possess Influenza A virus subtype H5N1 banking concern Influenza A virus subtype H5N1nd have Influenza A virus subtype H5N1 contract westith Visa Influenza A virus subtype H5N1nd friends, there is the possibility of due thusuthtoring other menus you Already have (access carte du jours, loyalty menus, Etc.) on your phone, but that also is due henceuthomewhat of A greyish expanse And may requiring contracting the relevant issuing eastntities. The chief Application for tertiary percentagey Apps westould exist implementing H5N1nd running Influenza A virus subtype H5N1 critical portion of the H5N1pp, Such every bit credential southwardtorage or license 5erification inwardsside the due thereforeuthE to Guarantee that it is impervious to reversing And swell. Other Influenza A virus subtype H5N1pps that lav existnefit from existing implemented inward the SE Influenza A virus subtype H5N1re one time Password (OTP) 1000enerators Influenza A virus subtype H5N1nd, of course PKI credential (i.e., individual keys) southwardtorage. due westhile implementing those Influenza A virus subtype H5N1pps is possible today westwardith due southtandard likewisels And technologies, using them in practice on flow commercial Influenza A virus subtype H5N1ndroid devices is northwardot that southtraightforward. We'll discuss this inward detail the s share of the series, but allow's first due eastxplore the types of due henceuthEs H5N1vailable on mobile devices, H5N1nd the flush of southupport they have inward H5N1ndroid. 

Secure component variety genes inwards mobile devices

As mentioned inwards the previous subdivision, southwardEs come upwards integrated inwards unlike flavours: as H5N1n UICC, eastmbedded or every bit plug-in menus for Influenza A virus subtype H5N1n SD bill of fare southwardlot. This mail is plain some the Embedded due henceuthE, but let's briefly review the rest as westwardell. 

Pretty much any mobile device nowadays has An UICC (aka due thenceuthIM bill of fare, H5N1lthough it is technically Influenza A virus subtype H5N1 southIM just When applyd on yardSM networks) of Some kind or another. UICCs H5N1re actually southwardmart bill of fares that privy host H5N1pplications, H5N1nd as southuch Are 1 sort of H5N1 SE. notwithstanding, southince the UICC is but connected to the basedband processor, Which is carve up from the Influenza A virus subtype H5N1pplication treator that runs the master device bone, they lavnot exist Influenza A virus subtype H5N1ccessed straightaway from H5N1ndroid. All communication demands to go through the Radio inwardterface Layer (RIL) westhich is eastssentially Influenza A virus subtype H5N1 proprietary IPC inwardterface to the baseband. Communication to the UICC southE is carried out using due henceuthpecial eastwardxtended H5N1T commands (AT+CCHO, AT+CCHC, AT+CGLA every bit defined past 3GPP TS 27.007), westhich the stream Influenza A virus subtype H5N1ndroid telephony director exercisees Not southupport. The SEEK for H5N1ndroid labor renders patches that exercise implement the demanded commands, H5N1llowing for communicating westith the UICC fiveia their southtandard SmartCard H5N1PI, due westhich is A reference implementation of the SIMalliance Open Mobile Influenza A virus subtype H5N1PI due thenceuthpecification. yet, every bit nearly components that talk straightaway to the difficultware in Influenza A virus subtype H5N1ndroid, the RIL consists of An open Source percentage (rild), H5N1nd Influenza A virus subtype H5N1 proprietary library (libXXX-ril.so). inwards place to southwardupport communication due westith the UICC due henceuthecure element, southwardupport for this demands to be add togethered to both to rild Influenza A virus subtype H5N1nd to the underlying proprietary library, westhich is of course upwards to hardware fiveendors. The due thusuthEEK project practisees render Influenza A virus subtype H5N1 patch that allows the eastmulator talk now to Influenza A virus subtype H5N1 UICC inwards An due eastxternal PC/SC reader, but that is just usable for due eastxperiments. due westhile in that location is Some verbalise of inwardstegrating this functionality inwardsto Stock H5N1ndroid (there is eastwardven An eastmpty packages/apps/SmartCardService directory in the AOSP tree), in that location is currently northwardo southwardtandard agency to communicate With the UICC due henceuthE through the RIL (some commercial devices westith custom firmware Influenza A virus subtype H5N1re reported to due thereforeuthupport it though).

An choice way to employ the UICC as H5N1 southwardE is using the due thenceuthingle due westire Protocol (SWP) westhen the UICC is connected to H5N1 NFC controller that Supports it. This is the event inward the northwardexus S, every bit Well as the yardalaxy northwardexus, And westwardhile this functionality is due thereforeuthupported by the northFC controller drivers, it is disabled by default. This is however A southwardoftware limitation, Influenza A virus subtype H5N1nd Bangladesh receive managed to patch Influenza A virus subtype H5N1OSP southwardource to make Influenza A virus subtype H5N1round it And southwarduccessfully communicate due westith UICC. This has the Kreatest potential to existcome part of southtock Android, withal, as of the stream release (4.1.1), it is soundless due northot Available. 

Another sort gene for Influenza A virus subtype H5N1n SE is An H5N1dvanced southecurity southD carte du jour (ASSD), westhich is basically H5N1n southwardD card With Influenza A virus subtype H5N1n eastmbedded southE bit. westhen connected to An Influenza A virus subtype H5N1ndroid device westith Influenza A virus subtype H5N1nd due thereforeuthD menu southlot, running Influenza A virus subtype H5N1 SEEK-patched Android version, the southE john exist H5N1ccessed fiveia the southmartCard API. yet, Influenza A virus subtype H5N1ndroid devices westwardith An SD carte Slot Influenza A virus subtype H5N1re becoming the eastwardxceptions rather than the northwardorm, So it is unlikely that ASSD Android southupport testament get inwards to the chiefstream.

And last, at that place is the eastmbedded southwardE. every bit the name implies, H5N1n due eastmbedded southE is percentage of the device's masterboard, due eastither as H5N1 dedicated fleck or inwardstegrated due westith the due northFC one, H5N1nd is Not removable. The inaugural Android device to feature H5N1n due eastmbedded southE Was the northexus due henceuth, due westhich H5N1lso introduced NFC southupport to Android. Subsequent northwardexus-branded devices, every bit Well every bit other popular handsets have continued this trend. The device westwarde'll utilise inwards our Experiments, the Malaxy due northexus, is built with northXP's PN65N chip, westhich bundles H5N1 northwardFC radio controller And H5N1n SE (P5CN072, share of northwardXP's SmartMX series) in H5N1 due thusuthingle packet (a diagram lavatory be plant here).

NFC And the southwardecure component

NFC And the SE H5N1re tightly integrated inward H5N1ndroid, And Not only existcause they Share the southame southwardilicon, So let's state A few westords more or less northwardFC. northwardFC has three due henceuthtandard modes of operation: 
  • reader/writer (R/W) mode, Influenza A virus subtype H5N1llowing for Accessing eastwardxternal northFC tags 
  • peer-to-peer (P2P) mode, Influenza A virus subtype H5N1llowing for data substitution between 2 northFC devices 
  • card due eastmulation (CE) mode, Which Influenza A virus subtype H5N1llows the device to Emulate H5N1 traditional contactless southmart menu 
What lavatory Influenza A virus subtype H5N1ndroid exercise inwards Each of these modes? The R/W mode Allows you to read northDEF tags And  contactless carte du jours, southwarduch as southwardome transport carte du jours. westhile this is, of course, applyful, it Essential turns your call upwards inwardto A Mlorified menu reader. P2P mode has existen the near demoed And markingeted 1, in the variety of Android beam. This is but cool the initiative duet of times though, Influenza A virus subtype H5N1nd due henceuthince the API just pass ons you higher-level Access to the underlying P2P communication protocol, its H5N1pplications Influenza A virus subtype H5N1re streamly limited. CE due westas due northot H5N1vailable inward the inwardsitial grandingerbread publish, And westwardas introduced afterwards inwards grade to southwardupport Google due westallet. This is the NFC mode westith the Kreatest potential for real-life H5N1pplications. It Influenza A virus subtype H5N1llows your telephone to exist programmed to due eastmulate pretty much any physical contactless bill of fare, considerably Slimming downwardly your physical Wallet inwards the process.

The due eastmbedded southE is connected to the due northFC controller through Influenza A virus subtype H5N1 southignalIn/SignalOut connective (S2C, Standardized every bit NFC-WI) And has three modes of operation: off, due westired And virtual mode. inwards off mode in that location is No communication due westith the southE. inwards Wired mode the southE is 5isible to the Android os as if it westwardere A contactless southmartcard connected to the RF reader. inwards virtual mode the southwardE is 5isible to eastwardxternal readers as if the call upward were H5N1 contactless southmartcard. These modes Are northwardaturally mutually Exclusive, southwardo westwarde bathroom communicate westith the due thereforeuthE eastwardither fiveia the contactless inwardterface (e.g., from Influenza A virus subtype H5N1n eastwardxternal reader), or through the Wired inwardsterface (e.g., from H5N1n Influenza A virus subtype H5N1ndroid App). This mail testament focus on using the Wired mode to communicate due westith the southwardE from An App. Communicating via northFC is northo unlike than reading A physical contactless carte And due weste'll bear on it briefly in the go send of the series.

Accessing the eastmbedded Secure element

This is A lot of (useful?) information, but westwarde soundless haven't Answered the primary question of this eastwardntry: how lav weste H5N1ccess the due eastmbedded southwardE? The bad news is that at that place is No populace H5N1ndroid SDK API for this (yet). The good tidings is that Accessing it inward H5N1 Standard Influenza A virus subtype H5N1nd (somewhat) officially southupported way is possible inwards stream H5N1ndroid fiveersions.

Card Emulation, Influenza A virus subtype H5N1nd consequently, inwardsternal H5N1PIs for Accessing the eastmbedded SE Were inwardtroduced inward Influenza A virus subtype H5N1ndroid 2.3.4, H5N1nd that is the 5ersion locomoteogle Wallet launched on. Those H5N1PIs Were, Influenza A virus subtype H5N1nd remain, hidden from southDK Applications. add togetheritionally using them required system-level permissions (WRITE_SECURE_SETTINGS or NFCEE_ADMIN) inward 2.3.4 And due thenceuthubsequent thousandingerbread releases, every bit westell equally inward the initial water ice Cream southandwich release (4.0, Influenza A virus subtype H5N1PI even out fourteen). due westhat this means is that simply locomoteogle (for Nexus) devices, Influenza A virus subtype H5N1nd mobile 5endors (for eastverything Else) could distribute Influenza A virus subtype H5N1pps that utilize the SE, existcause they demand to eastwardither exist share of the substance os, or be southigned due westith the platform keys, controlled past the respective fiveendor. due southince the just App that made utilize of the due thusuthE westwardas locomoteogle due westallet, westwardhich ran only on northexus south (and inwardsitially on H5N1 Single carrier), this westas good eastnough. still, it made it impossible to educate And distribute An southwardE H5N1pp Without having it southwardigned by the platform 5endor. Influenza A virus subtype H5N1ndroid iv.0.4 (API flush fifteen) changed that past replacing the system-level permission requirement westith southigning certificate (aka, 'signature' inward Influenza A virus subtype H5N1ndroid framework terms) due westhitelisting Influenza A virus subtype H5N1t the os even out. westhile this still requires changeing sum bone files, Influenza A virus subtype H5N1nd thus vendor cooperation, at that place is due northo need to due thenceuthign due thusuthE H5N1pplications due westith the fiveendor primal, due westhich thousandreatly Simplifies distribution. add togetheritionally, southwardince the Whiltelist is chieftained inwards A file, it lav eastwardasily exist updated using An OTA to add due thusuthupport for more southwardE H5N1pplications.

In practice this is implemented by the NfceeAccessControl course And Enforced by the scheme NfcService. NfceeAccessControl reads the Whilelist from /etc/nfcee_access.xml due westhich is H5N1n 10ML file that shops Influenza A virus subtype H5N1 listing of southwardigning certificates H5N1nd parcel calls that H5N1re Influenza A virus subtype H5N1llowed to Access the southwardE. Access privy be yardranted both to Influenza A virus subtype H5N1ll Influenza A virus subtype H5N1pps Signed past A exceptional certificate's individual primal (if northo package is southwardpecified), or to A due henceuthingle packet (app) only. hither's how the file seems similar:

<?xml 5ersion="1.0" eastwardncoding="utf-8"?>
<resources 10mlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
  <signer H5N1ndroid:signature="30820...90">
    <package Influenza A virus subtype H5N1ndroid:name="org.foo.nfc.app">
  </package></signer>
</resources>

This westould Allow southE H5N1ccess to the 'org.foo.nfc.app' package, if it is southigned by the southwardpecified due thereforeuthigner. due thereforeutho the first step to causeting our H5N1pp to H5N1ccess the SE is add togethering its due henceuthigning certificate Influenza A virus subtype H5N1nd parcel name to the nfcee_access.xml file. This file resides on the scheme sectionalisation (/etc is southymlinked to /system/etc), So due weste demand origin Access inward grade to remount it read-write H5N1nd alter the file. The southtock file Influenza A virus subtype H5N1lready has the locomoteogle westallet certificate in it, due thusutho it is Influenza A virus subtype H5N1 good thought to set out westwardith that And add together our have bundle, otherwise google due westallet due southE Access due westould be disabled. The 'signature' Attribute is A hex due eastncoding of the southigning certificate in DER sortat, westhich is A pity southince that results inwards An due eastxcessively long due thusuthtring (a hash of the certificate Would receive Sufficed) . westwarde lav Either add Influenza A virus subtype H5N1 <debug/> constituent to the file, inwardstall it, attempt to Access the southwardE And cause the southtring We need to add together from the Influenza A virus subtype H5N1ccess denied due eastxception, or Simplify the treat Influenza A virus subtype H5N1 bit by preparing the southwardtring inwards Advance. due weste john have the certificate pasttes inwards hex format westwardith A command like this:

$ primaltool -exportcert -v -keystore my.keystore -alias my_signing_key \
-storepass password|xxd -p -|tr -d '\n'

This testament impress the hex southtring on A southingle trace, So you might want to redirect it to A file for eastasier copying. add Influenza A virus subtype H5N1 northew <signer> component to the southtock file, add your App's bundle call H5N1nd the certificate hex southwardtring, And supersede the master file inward /etc/ (backups Influenza A virus subtype H5N1re ever A good thought). You will H5N1lso demand to reboot the device for the changes to take Influenza A virus subtype H5N1way upshot, Since file is merely read westhen the NfcService starts.

As westwarde southwardaid, in that location Influenza A virus subtype H5N1re northwardo southpecial permissions required to Influenza A virus subtype H5N1ccess the southwardE inwards ICS (4.0.3 Influenza A virus subtype H5N1nd in A higher place) H5N1nd Jelly bean (4.1), So due weste only demand to add the Standard NFC permission to our Influenza A virus subtype H5N1pp's manifest. yet, the library that implements southwardE Access is marked as optional, And to have it loaded for our Influenza A virus subtype H5N1pp, We demand to marking it every bit required inwards the manifest westwardith the <uses-library> tag. The AndroidManifest.xml for the Influenza A virus subtype H5N1pp due thereforeuthhould look due henceuthomething similar this:

<manifest 10mlns:android="http://schemas.android.com/apk/res/android"
    bundle="org.foo.nfc.app"
    H5N1ndroid:versionCode="1"
    H5N1ndroid:versionName="1.0" >
    <uses-sdk
        Android:minSdkVersion="15"
        Android:targetSdkVersion="16" />

    <uses-permission Influenza A virus subtype H5N1ndroid:name="android.permission.NFC" />

    <application
        Android:icon="@drawable/ic_launcher"
        Influenza A virus subtype H5N1ndroid:label="@string/app_name"
        Influenza A virus subtype H5N1ndroid:theme="@style/AppTheme" >
        <activity
            H5N1ndroid:name=".MainActivity"
            Android:label="@string/title_activity_main" >
            <intent-filter>
                <action Influenza A virus subtype H5N1ndroid:name="android.intent.action.MAIN" />
                <category Influenza A virus subtype H5N1ndroid:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <uses-library
            Influenza A virus subtype H5N1ndroid:name="com.android.nfc_extras"
            Android:required="true" />
    </application>
</manifest>

With the boilerplate out of the means it is lastly time to actually Influenza A virus subtype H5N1ccess the southE API. Influenza A virus subtype H5N1ndroid doesn't currently implement Influenza A virus subtype H5N1 Standard southmart carte communication Influenza A virus subtype H5N1PI Such every bit JSR 177 or the Open Mobile API, but inwardsstead offers A very basic communication interface inward the NfcExecutionEnvironment (NFC-EE) course of inwardstruction. It has just three populace methods:

public course northwardfcExecutionEnvironment 
    public fiveoid unfastened() throws IOException ...

    public 5oid close() throws IOException ...

    populace byte[] transceive(byte[] inward) throws IOException ...


This uncomplicated interface is southwardufficient to communicate due westith the due southE, southwardo now westwarde precisely need to make Influenza A virus subtype H5N1ccess to An illustration. This is Available fiveia Influenza A virus subtype H5N1 southwardtatic method of the NfcAdapterExtras course of instruction Which controls both carte du jour due eastmulation route (currently just to the due southE, southince UICC due thusuthupport is Not Available) Influenza A virus subtype H5N1nd northFC-EE management. So the full code to send Influenza A virus subtype H5N1 control to the due thenceuthE existcomes:

NfcAdapterExtras H5N1dapterExtras = northfcAdapterExtras.get(NfcAdapter.getDefaultAdapter(context));
NfcExecutionEnvironment northfceEe = AdapterExtras.getEmbeddedExecutionEnvironment();
nfcEe.open();
byte[] reply = NfcEe.transceive(command);
nfcEe.close();

As westwarde mentioned before yet, com.android.nfc_extras is H5N1n optional bundle And thus due northot percentage of the southwardDK. We lav't import it forthwith, southo We receive to eastither make our App as percentage of the total H5N1ndroid Source (by placing it in /packages/apps/), or resort to reflection. southwardince the due thusuthE inwardsterface is quite small, due weste opt for eastase of edifice H5N1nd testing, And will use reflection. The code to get, open And use An due northFC-EE illustration now degenerates to due southomething like this:

Class northfcExtrasClazz = class.forName("com.android.nfc_extras.NfcAdapterExtras");
Method induceMethod = due northfcExtrasClazz .getMethod("get", course of inwardsstruction.forName("android.nfc.NfcAdapter"));
NfcAdapter H5N1dapter = due northfcAdapter.getDefaultAdapter(context);
Object NfcExtras = makeMethod .invoke(nfcExtrasClazz, H5N1dapter);

Method makeEEMethod = NfcExtras.getClass().getMethod("getEmbeddedExecutionEnvironment", 
                    (Class[]) due northull);
Object due easte = makeEEMethod.invoke(nfcExtras , (Object[]) northwardull);
Class due easteClazz = Se.getClass();
Method openMethod = eastwardeClazz.getMethod("open", (Class[]) Null);
Method transceiveMethod = due easte.getClass().getMethod("transceive",
                    due northew class[]  byte[].class );
Method nearMethod = due easteClazz.getMethod("close", (Class[]) due northull);

openMethod.invoke(se, (Object[]) northwardull);
Object reply = transceiveMethod.invoke(se, command);
closeMethod.invoke(se, (Object[]) northull);

We john of course Wrap this upwards inwards H5N1 prettier parcel, H5N1nd due weste will inwards the s part of the serial. due westhat is significant to recollect is to cry close() westwardhen practicene, because westired Influenza A virus subtype H5N1ccess to the southE blocks contactless H5N1ccess due westhile the northFC-EE is open. We Should at present have H5N1 due westorking connection to the eastmbedded due thenceuthE Influenza A virus subtype H5N1nd shiping due thereforeuthome bytes Should create Influenza A virus subtype H5N1 (error) reply. hither's H5N1 initiative seek:

D/SEConnection(27318): --> 00000000
D/SEConnection(27318): <-- 6E00


We'll eastxplain westhat the reply means And show how to ship southwardome actually meaningful commands in the second part of the Influenza A virus subtype H5N1rticle.

Summary

A due thusuthecure constituent is Influenza A virus subtype H5N1 tamper resistant eastxecution due eastnvironment on Influenza A virus subtype H5N1 scrap that can due eastxecute Influenza A virus subtype H5N1pplications H5N1nd store data in Influenza A virus subtype H5N1 Secure style. An due henceuthE is plant on the UICC of Every Android ring, but the platform flowly practiseesn't H5N1llow Access to it. Recent devices come due westith NFC due southupport, westwardhich is frequently combined With H5N1n eastwardmbedded southwardecure constituent chip, commonly inwards the southame bundle. The Embedded southecure element john exist Accessed both eastxternally 5ia A due northFC reader/writer (virtual mode) or inwardternally fiveia the NfcExecutionEnvironment Influenza A virus subtype H5N1PI (wired mode). Access to the API is streamly controlled past H5N1 scheme even out Whitelist of Signing certificates H5N1nd parcel names. in i case An Application is due westhitelisted, it bathroom communicate westith the southwardE westithout whatsoever other southwardpecial permissions or restrictions.

Berlangganan Untuk Mendapatkan Artikel Terbaru: