Git Product home page Git Product logo

pcsc-android-emulator's Introduction

Smartcard Android Emulator Extension

Download and run the emulator

  • create an avd in Android Studio with system image sdk21 x86 named "smartcard"

  • download and run the emulator :

mkdir pcsc-emulator && cd pcsc-emulator
wget https://github.com/bertrandmartel/pcsc-android-emulator/releases/download/v1.0/emulator.tar.gz
tar -xvzf emulator.tar.gz && rm emulator.tar.gz
export ANDROID_SDK_ROOT=~/Android/Sdk #change this
export LD_LIBRARY_PATH=$PWD/pcsc-lite:$LD_LIBRARY_PATH
./emulator/emulator @smartcard -verbose -system system.img -pcsc

Build instructions

Instructions for building and using the emulator extension for smartcard from seek-for-android instructions

Init

AOSP_DIR=seek-for-android
PCSC_DIR=~/pcsc-lite

Build AOSP

building & patching AOSP

mkdir $AOSP_DIR && cd $AOSP_DIR
repo init -u https://github.com/seek-for-android/platform_manifest.git -b scapi-4.0.0
repo sync
. build/envsetup.sh 
lunch aosp_x86-eng
make update-api
make -j32

Build pcsc

mkdir -p $PCSC_DIR && cd $PCSC_DIR
wget https://alioth.debian.org/frs/download.php/file/4225/pcsc-lite-1.8.22.tar.bz2
current=$(pwd)
mkdir -p 32lib
tar -C 32lib -xvjf pcsc-lite-1.8.22.tar.bz2
cd 32lib/pcsc-lite-1.8.22
sudo apt-get install libudev-dev:i386
CFLAGS="-m32" LDFLAGS="-m32" ./configure; make

cd $current
mkdir -p 64lib
tar -C 64lib -xvjf pcsc-lite-1.8.22.tar.bz2
cd 64lib/pcsc-lite-1.8.22
CFLAGS="-m64" LDFLAGS="-m64" ./configure; make

Build emulator

build emulator with pcsc support

cd $AOSP_DIR
cd external/qemu
export PCSC_INCPATH=$PCSC_DIR/32lib/pcsc-lite-1.8.22/src/PCSC
export PCSC32_LIBPATH=$PCSC_DIR/32lib/pcsc-lite-1.8.22/src/.libs/
export PCSC64_LIBPATH=$PCSC_DIR/64lib/pcsc-lite-1.8.22/src/.libs/
./android-configure.sh
make -j32

run emulator

Prior to the following step, assure to create an avd in Android Studio with system-images 21 x86

In my case the avd is named "smartcard" :

cd $AOSP_DIR
export ANDROID_SDK_ROOT=/path/to/Sdk
./external/qemu/objs/emulator @smartcard -verbose -pcsc -system out/target/product/generic_x86/system.img

If you have to name the reader :

./external/qemu/objs/emulator @smartcard -verbose -pcsc "Gemalto Prox Dual USB PC Link Reader [Prox-DU Contact_10800061] 01 00" -system out/target/product/generic_x86/system.img

Disable SIM pin code check

I had some troubles with the SIM pin code keyguard that won't return successfull pincode. Instead it will return "SIM operation failed" and exhaust the pin code retry.

To disable the pin code check (but still have the keyguard view), apply the patch :

cd $AOSP_DIR
cd frameworks/base
git apply /path/to/0001-disable-sim-pin-code-check-in-keyguard.patch

Troubleshoot

no APDU access allowed

  • Error encountered :
09-10 00:48:49.396 2116-2116/fr.bmartel.smartcardapi E/MainActivity: Error occured:
     java.lang.SecurityException: Access Control Enforcer: no APDU access allowed!
         at org.simalliance.openmobileapi.service.SmartcardError.throwException(SmartcardError.java:134)
         at org.simalliance.openmobileapi.Session.openLogicalChannel(Session.java:339)
         at org.simalliance.openmobileapi.Session.openLogicalChannel(Session.java:378)
  • Reason

This error occurs because the Access control enforcer refuses to send apdu for your app. You have to add an access rule to authorize your app to send apdu to a specific applet. A rule defines :

  • an applet ID
  • a certificate sha1 hash
  • a rule (0x01 for always, 0x00 for never, for more sophisticated rule see access rule spec)

To list, add and delete rules, clone this fork of GlobalPlatformPro on the access-control branch :

git [email protected]:bertrandmartel/GlobalPlatformPro.git
cd GlobalPlatformPro
git checkout access-control
ant -f build.xml
  • list rules :
java -jar gp.jar -acr-list
  • add a rule to authorize apdu for Android app signed with hash 1FA8CC6CE448894C7011E23BCF56DB9BD9097432 (debug keystore), with applet id D2760001180002FF49502589C0019B01 with the rule ALWAYS (0x01) :
java -jar gp.jar -acr-add -app D2760001180002FF49502589C0019B01 -hash 1FA8CC6CE448894C7011E23BCF56DB9BD9097432 -rule 01

Note that this will issue an install for personalization which requires authentication (eg setting the right keys)

Note that you will have to restart the emulator to apply those rule (emulator will retrieve all rules at boot)

iccOpenLogicalChannel failed

  • Error encountered :
09-10 01:01:57.837 2121-2121/fr.bmartel.smartcardapi E/MainActivity: Error occured:
     java.io.IOException: iccOpenLogicalChannel failed
  • Reason

smartcard has been disconnected

Secure Element is not presented

  • Error encountered :
09-10 01:05:31.855 2098-2098/fr.bmartel.smartcardapi E/MainActivity: Error occured:
	java.io.IOException: Secure Element is not presented.
  • Reason

No SIM inserted

pcsc-android-emulator's People

Contributors

bertrandmartel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pcsc-android-emulator's Issues

Does emulator-extension work with Smartcafe expert 3.2 72k?

Hello,
I am trying to use my Smartcafe expert 3.2 72k smartcard with your patched emulator, but I am encountering some difficulties.
When I start the emulator I get the message:
"sim_card.c: failed to open card"

And then, when I try to access the Secure Element I get:
"java.io.IOException: Secure Element is not presented."
(Reader.isSecureElementPresent() return "false" for every reader detected)

From what I have understood, Android emulator ignore my smartcard because it is not recognised as a valid sim card.
Is there any way to use a "regular" javacard without sim capabilities?

Thanks,
Cava

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.