{"id":19156966,"url":"https://github.com/bertrandmartel/pcsc-android-emulator","last_synced_at":"2025-05-07T07:46:50.352Z","repository":{"id":94808679,"uuid":"102994753","full_name":"bertrandmartel/pcsc-android-emulator","owner":"bertrandmartel","description":"SmartCard Android Emulator binaries \u0026 build instructions","archived":false,"fork":false,"pushed_at":"2017-09-25T18:08:31.000Z","size":8715,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T20:17:40.675Z","etag":null,"topics":["android","emulator","pcsc","smartcard"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bertrandmartel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-10T01:13:11.000Z","updated_at":"2024-11-11T14:03:46.000Z","dependencies_parsed_at":"2023-03-13T16:56:45.212Z","dependency_job_id":null,"html_url":"https://github.com/bertrandmartel/pcsc-android-emulator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fpcsc-android-emulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fpcsc-android-emulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fpcsc-android-emulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fpcsc-android-emulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bertrandmartel","download_url":"https://codeload.github.com/bertrandmartel/pcsc-android-emulator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252838788,"owners_count":21812082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","emulator","pcsc","smartcard"],"created_at":"2024-11-09T08:36:45.572Z","updated_at":"2025-05-07T07:46:50.344Z","avatar_url":"https://github.com/bertrandmartel.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smartcard Android Emulator Extension\n\n## Download and run the emulator\n\n* create an avd in Android Studio with system image sdk21 x86 named \"smartcard\"\n\n* download and run the emulator : \n\n```bash\nmkdir pcsc-emulator \u0026\u0026 cd pcsc-emulator\nwget https://github.com/bertrandmartel/pcsc-android-emulator/releases/download/v1.0/emulator.tar.gz\ntar -xvzf emulator.tar.gz \u0026\u0026 rm emulator.tar.gz\nexport ANDROID_SDK_ROOT=~/Android/Sdk #change this\nexport LD_LIBRARY_PATH=$PWD/pcsc-lite:$LD_LIBRARY_PATH\n./emulator/emulator @smartcard -verbose -system system.img -pcsc\n```\n\n## Build instructions\n\nInstructions for building and using the emulator extension for smartcard from [seek-for-android instructions](https://github.com/seek-for-android/pool/wiki/EmulatorExtension)\n\n### Init\n\n```bash\nAOSP_DIR=seek-for-android\nPCSC_DIR=~/pcsc-lite\n```\n\n### Build AOSP\n\nbuilding \u0026 patching AOSP\n\n```bash\nmkdir $AOSP_DIR \u0026\u0026 cd $AOSP_DIR\nrepo init -u https://github.com/seek-for-android/platform_manifest.git -b scapi-4.0.0\nrepo sync\n. build/envsetup.sh \nlunch aosp_x86-eng\nmake update-api\nmake -j32\n```\n\n### Build pcsc\n\n```bash\nmkdir -p $PCSC_DIR \u0026\u0026 cd $PCSC_DIR\nwget https://alioth.debian.org/frs/download.php/file/4225/pcsc-lite-1.8.22.tar.bz2\ncurrent=$(pwd)\nmkdir -p 32lib\ntar -C 32lib -xvjf pcsc-lite-1.8.22.tar.bz2\ncd 32lib/pcsc-lite-1.8.22\nsudo apt-get install libudev-dev:i386\nCFLAGS=\"-m32\" LDFLAGS=\"-m32\" ./configure; make\n\ncd $current\nmkdir -p 64lib\ntar -C 64lib -xvjf pcsc-lite-1.8.22.tar.bz2\ncd 64lib/pcsc-lite-1.8.22\nCFLAGS=\"-m64\" LDFLAGS=\"-m64\" ./configure; make\n```\n\n### Build emulator\n\nbuild emulator with pcsc support\n\n```bash\ncd $AOSP_DIR\ncd external/qemu\nexport PCSC_INCPATH=$PCSC_DIR/32lib/pcsc-lite-1.8.22/src/PCSC\nexport PCSC32_LIBPATH=$PCSC_DIR/32lib/pcsc-lite-1.8.22/src/.libs/\nexport PCSC64_LIBPATH=$PCSC_DIR/64lib/pcsc-lite-1.8.22/src/.libs/\n./android-configure.sh\nmake -j32\n```\n\n### run emulator \n\nPrior to the following step, assure to create an avd in Android Studio with system-images 21 x86\n\nIn my case the avd is named \"smartcard\" : \n\n```bash\ncd $AOSP_DIR\nexport ANDROID_SDK_ROOT=/path/to/Sdk\n./external/qemu/objs/emulator @smartcard -verbose -pcsc -system out/target/product/generic_x86/system.img\n```\n\nIf you have to name the reader : \n\n```bash\n./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\n```\n\n### Disable SIM pin code check\n\nI 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.\n\nTo disable the pin code check (but still have the keyguard view), apply the patch :\n\n```bash\ncd $AOSP_DIR\ncd frameworks/base\ngit apply /path/to/0001-disable-sim-pin-code-check-in-keyguard.patch\n```\n\n### Troubleshoot\n\n#### no APDU access allowed\n\n* Error encountered : \n\n```bash\n09-10 00:48:49.396 2116-2116/fr.bmartel.smartcardapi E/MainActivity: Error occured:\n     java.lang.SecurityException: Access Control Enforcer: no APDU access allowed!\n         at org.simalliance.openmobileapi.service.SmartcardError.throwException(SmartcardError.java:134)\n         at org.simalliance.openmobileapi.Session.openLogicalChannel(Session.java:339)\n         at org.simalliance.openmobileapi.Session.openLogicalChannel(Session.java:378)\n```\n\n* Reason\n\nThis 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 : \n* an applet ID\n* a certificate sha1 hash\n* a rule (0x01 for always, 0x00 for never, for more sophisticated rule see access rule spec)\n\nTo list, add and delete rules, clone [this fork of GlobalPlatformPro](https://github.com/bertrandmartel/GlobalPlatformPro/tree/access-control) on the `access-control` branch :\n\n```bash\ngit git@github.com:bertrandmartel/GlobalPlatformPro.git\ncd GlobalPlatformPro\ngit checkout access-control\nant -f build.xml\n```\n\n* list rules :\n\n```bash\njava -jar gp.jar -acr-list\n```\n\n* add a rule to authorize apdu for Android app signed with hash `1FA8CC6CE448894C7011E23BCF56DB9BD9097432` (debug keystore), with applet id `D2760001180002FF49502589C0019B01` with the rule `ALWAYS` (0x01) :\n\n```bash\njava -jar gp.jar -acr-add -app D2760001180002FF49502589C0019B01 -hash 1FA8CC6CE448894C7011E23BCF56DB9BD9097432 -rule 01\n```\n\nNote that this will issue an install for personalization which requires authentication (eg setting the right keys)\n\nNote that you will have to restart the emulator to apply those rule (emulator will retrieve all rules at boot)\n\n#### iccOpenLogicalChannel failed\n\n* Error encountered : \n\n```bash\n09-10 01:01:57.837 2121-2121/fr.bmartel.smartcardapi E/MainActivity: Error occured:\n     java.io.IOException: iccOpenLogicalChannel failed\n```\n\n* Reason\n\nsmartcard has been disconnected\n\n#### Secure Element is not presented\n\n* Error encountered : \n\n```bash\n09-10 01:05:31.855 2098-2098/fr.bmartel.smartcardapi E/MainActivity: Error occured:\n\tjava.io.IOException: Secure Element is not presented.\n```\n\n* Reason\n\nNo SIM inserted\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbertrandmartel%2Fpcsc-android-emulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbertrandmartel%2Fpcsc-android-emulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbertrandmartel%2Fpcsc-android-emulator/lists"}