mclear / OMNI-Ring

Quick setup tutorial on how to set up toolchain & build Javacard applets.
MIT License
35 stars 5 forks source link

Reader for OMNI RING #9

Open laurabilius opened 3 years ago

laurabilius commented 3 years ago

Hello,

I have the OMNI ring I want to ask if it is possible to delete the applet and loading applets using the reader from an android smartphone? For example, my smartphone recognizes the ring (Type B). Exist an .apk that works with OMNI?

If it's not possible, I want to ask why ACR122U can brick the ring, and what reader you recommend? Is ACR1251U ok? Thank you!

benbenbenbenbenben commented 3 years ago

There is a app called "Smart Card Reader" on F-Droid that supposedly let's you use your phone a reader over IP to your computer. I could never get it to work but it is worth exploring.

Also, there is a code sample that builds a cordova app with smartcard access that might be a starting point: https://github.com/dcdc-io/node-gp-phonegap - it doesn't do app installs but that's only because it doesn't have the commands to do it written in there yet.

On other reader hardware, I'll check when I'm back in the office what models I have used.

laurabilius commented 3 years ago

Thank you. I tried the Smart card reader, but I did 't find yet an available vpcd software for host. I' ll keep searching.

But thank you!

benbenbenbenbenben commented 3 years ago

So my reader on my desk is a HID OMNIKEY 5422 and it hasn't had any issues with any rings. I've abused them quite a lot and not bricked one yet, so I'd recommend it.

I'm still planning to make a working example using node-gp to write a ring via a smartphone but unfortuanately I have a lot of other projects to clear first.

Tha said, I wrote node-gp so if you do want to start working on something smartphone enabled with node-gp I'll happily answer technical questions about it in the meantime.

benbenbenbenbenben commented 3 years ago

Okay, update.

Here is a barely tested version of code that will write an applet from a phone:

https://github.com/dcdc-io/node-gp-phonegap/tree/dev-auto-install-ndef-tag

To build this on a new Windows 10 machine last night, I had to:

And finally to run it:

As ever with Cordova, you can debug in Chrome at chrome://inspect on a USB connected desktop.

In this example, when a device is presented it will automatically install the famed NDEF tag applet, turning your ring into an writable NDEF tag.

note: If you already have an NDEF tag installed, you will get a 6985 response.


edit: linked is the section of code that installs the applet

https://github.com/dcdc-io/node-gp-phonegap/blob/aa1b6e62b4a041bb51a222d551440d008d3e21d9/src/index.js#L47

JohnMcLear commented 3 years ago

Worth noting I think Cordova is dead so you might wanna migrate

benbenbenbenbenben commented 3 years ago

Worth noting I think Cordova is dead so you might wanna migrate

I thought bad things happened to PhoneGap but Cordova lives on? Source?

https://chrisgriffith.wordpress.com/2020/08/14/phonegap-is-dead-long-live-cordova/

laurabilius commented 3 years ago

Yes, Cordova was updated in August 2020, according to https://cordova.apache.org/announcements/2020/08/04/cordova-cli-release-10.0.0.html

laurabilius commented 3 years ago

Okay, update.

Here is a barely tested version of code that will write an applet from a phone:

https://github.com/dcdc-io/node-gp-phonegap/tree/dev-auto-install-ndef-tag

To build this on a new Windows 10 machine last night, I had to:

  • install Cordova
  • install Android Studio
  • install Gradle
  • run cordova platform add android
  • run cordova plugin add phonegap-nfc
  • delete line 39~ of /plugins/phongap-nfc/plugin.xml (as per chariotsolutions/phonegap-nfc#371)
  • run cordova plugin add phonegap-nfc (again)
  • run cordova build

And finally to run it:

  • run cordova run android --device

As ever with Cordova, you can debug in Chrome at chrome://inspect on a USB connected desktop.

In this example, when a device is presented it will automatically install the famed NDEF tag applet, turning your ring into an writable NDEF tag.

note: If you already have an NDEF tag installed, you will get a 6985 response.

edit: linked is the section of code that installs the applet

https://github.com/dcdc-io/node-gp-phonegap/blob/aa1b6e62b4a041bb51a222d551440d008d3e21d9/src/index.js#L47

I will follow the recommendations you offered. I'll let you know how it goes.

Thank you very much for your effort!

laurabilius commented 3 years ago

There is a app called "Smart Card Reader" on F-Droid that supposedly let's you use your phone a reader over IP to your computer. I could never get it to work but it is worth exploring.

Also, there is a code sample that builds a cordova app with smartcard access that might be a starting point: https://github.com/dcdc-io/node-gp-phonegap - it doesn't do app installs but that's only because it doesn't have the commands to do it written in there yet.

On other reader hardware, I'll check when I'm back in the office what models I have used.

I tried the Smart card reader, but I had troubles concerning vpcd.exe, such as missing .dll files from sys. So I didn't get too far, but it remains an open "gate".

JohnMcLear commented 3 years ago

It lives on but it seems like it's days are numbered. Sadly ;(.

Please convince me otherwise!!

laurabilius commented 3 years ago

Hello,

I m coming with an error on cordova build android --device.

'Using Android SDK: C:\adt-bundle-windows-x86_64-20131030\sdk Subproject Path: CordovaLib Subproject Path: app

FAILURE: Build failed with an exception.

BUILD FAILED in 1s Command failed with exit code 1: C:\cordovaprj\node-gp-phonegap\platforms\android\gradlew cdvBuildDebug -b C:\cordovaprj\node-gp-phonegap\platforms\android\build.gradle'

Can you give an advice to solve this problem. Thank you very much!

benbenbenbenbenben commented 3 years ago

I'm not at the computer but a guess is going to that my Android SDK was API version 30 when I pushed that.

Did you the the SDK Manager feature of Android Studio to install SDKs?

laurabilius commented 3 years ago

Hello, I succeed in installing HelloCordova.apk on my smartphone (Android 10). I uninstalled and installed again the packages from the SDK manager (not from ANDROID STUDIO) and confirmed the licenses. It worked from the first run.

The question is what should I do next, to delete the applet from the Omni ring? Maybe I should do something extra.

Sorry for bothering you so much. Thanks!

laurabilius commented 3 years ago

Update: Maybe I'm doing something wrong, i ran GP and I get the error The Smart card resource manager is not running.

benbenbenbenbenben commented 3 years ago

Where are you seeing that error?

I don't remember if I tested deleting with node-gp before now, but it's reasonable to expect it to work as it's just another command. I know it can install applets and list them.

laurabilius commented 3 years ago

I ran gp.exe on cmd. But like I said, maybe I didn't understand something properly

C:\cordovaprj\node-gp-phonegap>gp.exe --list
Exception in thread "main" jnasmartcardio.Smartcardio$EstablishContextException: jnasmartcardio.Smartcardio$JnaPCSCException: SCardEstablishContext got response 0x8010001d (SCARD_E_NO_SERVICE: The Smart card resource manager is not running.)
        at jnasmartcardio.Smartcardio$JnaTerminalFactorySpi.engineTerminals(Smartcardio.java:81)
        at javax.smartcardio.TerminalFactory.terminals(Unknown Source)
        at pro.javacard.gp.GPTool.main(GPTool.java:123)
Caused by: jnasmartcardio.Smartcardio$JnaPCSCException: SCardEstablishContext got response 0x8010001d (SCARD_E_NO_SERVICE: The Smart card resource manager is not running.)
        at jnasmartcardio.Smartcardio.check(Smartcardio.java:961)
        at jnasmartcardio.Smartcardio.check(Smartcardio.java:952)
        at jnasmartcardio.Smartcardio.access$000(Smartcardio.java:34)
        at jnasmartcardio.Smartcardio$JnaTerminalFactorySpi.engineTerminals(Smartcardio.java:79)
        ... 2 more
benbenbenbenbenben commented 3 years ago

That gp.exe is Martin Paljak's original work and it won't communicate with a your ring unless you have a "traditional" reader attached. For gp.exe to work in a scenario where you can use you phone as a reader will require more work. Specifically creating a OS SC driver that connects over IP/HTTP.

What you should do instead is use node-gp to list/delete/install directly from your cordova app. Using the demo code I linked previously, the API's you'll use are:

gpcard.getApplets, gpcard.getPackages gpcard.deletePackage gpcard.installAuto

Look at this link so see how all but deletePackage are already used. See lines 52, 98, and 99:

https://github.com/dcdc-io/node-gp-phonegap/blob/aa1b6e62b4a041bb51a222d551440d008d3e21d9/src/index.js

edit: a practical pattern to use would be to:

  1. Ask the user to "touch" the ring to list the installed contents (the handleConnected method is fired when they touch)
  2. Ask the user to select a package from the above results for deletion (as in remember what selection they made)
  3. Ask the user to "touch" to delete (by calling deletePackage(userSelection) within handleConnected
laurabilius commented 3 years ago

I am at my first app concerning smart rings and NFC. I am trying to understand how it works, but now I've clarified a lot of things and it doesn't seem that hard.

I understood why GP isn't working for me. Makes sense. I'll study more about GlobalPlatform.

I have a question: doTestInstall which is called in handleConnected makes the important work, delete and install a new applet. According to https://github.com/dcdc-io/node-gp-phonegap/blob/aa1b6e62b4a041bb51a222d551440d008d3e21d9/src/index.js it loads a .cap file. I tried to open it, but I couldn't see what's in there. Suppose this file is generated by the app? (I searched on the internet about .cap files).

I downloaded the .cap file (to see what is happening/ curiosity) and run it and it gives me the error on the app: Tag was lost.

So, what's the .cap file exactly in this situation?

Thank you!

benbenbenbenbenben commented 3 years ago

cap files are compiled applets that are produced when compiling java applets for smartcard targets. To create applets you need something like JCIDE and a JavaCard SDK.

There are some quirks with the version of the SDK your ring supports that I plan to write about in the future. I'm currently snowed under with other client work so I can't tell you all the details right now.

Of the top of my head you want to get JCIDE and use the JavaCard SDK 3.05 or 3.04

laurabilius commented 3 years ago

Ok. I'll try to create a "hello world" applet, hope I will face no problems.

Thank you for the guidelines. I appreciate.

laurabilius commented 3 years ago

Hello again. Thank you very much for giving me the information. I finally succeeded to delete the applet and to convert the ring into writable.

Is there any possibility to increase the memory over shortrange? Thank you!

benbenbenbenbenben commented 3 years ago

Hello again. Thank you very much for giving me the information. I finally succeeded to delete the applet and to convert the ring into writable.

Is there any possibility to increase the memory over shortrange? Thank you!

Yes but you'd have to experiment with the applet source code to find out what the largest practical/reliable payload size is for OMNI ring.

I believe the NDEF limit is 4GB~ which is well beyond what you'll do with OMNI ring.