yong24s / CS3235-AY1718S1-RetrofitSecureNFC

Retrofitting NTAG203/213 with security enhancements!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RetrofitSecureNFC

rsn logo

Retrofitting cheap and low storage NTAG203/213 with Elliptic Curve Digital Signature Algorithm (ECDSA)!

How to use

  1. Generate an ECC private key and a self-signed ECC public certificate

Read: How to generate ECC keys/certificates

  1. Run EcdsaSigner.java in KeyGenerator Project to sign an URL with your ECC private key
  2. [OPTIONAL] Run EcdsaVerifier.java in KeyGenerator Project to verify the signed URL with your ECC public certificate
  3. Write the signed URL to a NFC tag
  4. Update AndroidManifest.xml to include new signed domain
  5. Rename your ECC public certificate to your fully qualified domain name i.e. isteps.comp.nus.edu.sg
  6. Copy the renamed ECC public certificate the asserts/certs folder

AndroidApp/app/src/main/assets/certs/

  1. Deploy the Android application to a Android phone with NFC
  2. Test it out and have fun!

How to generate ECC keys/certificates

First, pick a named curve that fits your security requirements and NFC storage space.

openssl ecparam -list_curves
The following command assumes that prime256v1 is chosen.

openssl ecparam -genkey -name prime256v1 -noout -out tmp.pem

Discard this later as we need a PKCS#8 padded private key Read: Known Issues

openssl pkcs8 -topk8 -nocrypt -in tmp.pem -out key.pem

Keep this as the ECC private key

openssl req -new -sha256 -key key.pem -out csr.csr

Create a certificate signing request (CSR)

openssl req -x509 -sha256 -days 365 -key key.pem -in csr.csr -out certificate.pem

Keep this as the ECC public certifcate

The following commands can be used to print the content of key and certifcate. openssl x509 -in certificate.pem -text -noout
openssl x509 -in key.pem -text -noout

Known issues

EcdsaSigner.java uses BouncyCastle crypto library for ECDSA.
In line 42, it uses a PKCS8EncodedKeySpec wrap a PemObject instance.
As for now, the conversion to PKCS#8 is needed as I have not figured out another way to inflate ECC private key yet.

In our school project, we assume that the companies can create their own signer (and not bound to any programming languages) as ECDSA is an open and well-defined. The only thing we have to agree on is which secure hash to use and we are using SHA384.

Link to line 42 of EcdsaSigner.java

return KeyFactory.getInstance("EC", "BC").generatePrivate(new PKCS8EncodedKeySpec(pem.getContent()));

Link to StackOverflow solution: https://stackoverflow.com/questions/22963581/reading-elliptic-curve-private-key-from-file-with-bouncycastle#comment71074675_23369629

Credits

Ralf Wondratschek for his awesome guide on Android NFC Programming

Link https://code.tutsplus.com/tutorials/reading-nfc-tags-with-android--mobile-17278

About

Retrofitting NTAG203/213 with security enhancements!

License:MIT License


Languages

Language:Java 100.0%