Access system implementation with Raspi and RFID (ISO-14443) cards. Makes uncloneable cards possible with cryptography (unlike many commercial systems). With status reporting over IRC and SFTP.
Find a file
2018-04-29 22:54:03 +02:00
.gitignore CLion files to gitignore 2017-10-25 18:16:22 +02:00
apdu-desfire-wrapped.sh Two sample scripts for testing NDEF reading with Desfire commands and also ISO 7816 APDUs 2018-04-11 00:47:40 +02:00
apdu-forum4-ndef.sh Two sample scripts for testing NDEF reading with Desfire commands and also ISO 7816 APDUs 2018-04-11 00:47:40 +02:00
brmdoor_adduser.py Authentication with NDEF message on Desfire containing signed UID via Ed25519 2017-10-22 22:39:55 +02:00
brmdoor_authenticator.py Make the signature wrapped in JSON object to be able to extend structure later 2017-10-27 19:56:43 +02:00
brmdoor_nfc.config.sample Configuration comment on using a simple switch with internal pullup on Raspberry for the OPEN/CLOSED status 2018-04-29 19:48:05 +02:00
brmdoor_nfc_daemon.py Rejoin channels after reconnect 2018-04-24 20:45:54 +02:00
brmdoor_start.sh Execute permission on startup script 2018-04-29 20:06:30 +02:00
create_authenticator_db.py Import cards from JendaSAP list (nick UID list) 2018-04-15 19:38:06 +02:00
Doxyfile Doxygen documentation generation 2014-07-19 17:13:29 +02:00
generate_ed25519_keypair.py Authentication with NDEF message on Desfire containing signed UID via Ed25519 2017-10-22 22:39:55 +02:00
gpio_vs_wiringpi_numbering_scheme.png Link to wiringpi<->BCM GPIO numbering scheme 2018-04-29 19:40:22 +02:00
import_jendasap_cards.py Import cards from JendaSAP list (nick UID list) 2018-04-15 19:38:06 +02:00
Makefile Reverting to SWIG 2 as SWIG 3 seems to cause random segfaults 2017-10-22 23:20:06 +02:00
nfc_smartcard.cpp Comment about GIL while polling with NFC reader 2017-10-29 22:28:30 +01:00
nfc_smartcard.h Reading NDEF from Desfire 2017-10-22 19:44:43 +02:00
nfc_smartcard.i Renamed module and files to nfc_smartcard 2015-12-06 17:06:53 +01:00
README.md Sample systemd service description for automated startup 2018-04-29 22:54:03 +02:00
sign_uid.py Authentication with NDEF message on Desfire containing signed UID via Ed25519 2017-10-22 22:39:55 +02:00
test_nfc.py Note about conflicts with pn533 kernel modules and pcscd. Change default test to Desfire NDEF read 2018-04-21 21:38:36 +02:00
test_uids_db.sqlite Added another desfire to test DB 2017-10-27 20:04:32 +02:00
unlocker.py Link to wiringpi<->BCM GPIO numbering scheme 2018-04-29 19:40:22 +02:00
write_signed_ndef_on_desfire.py Fix typos 2017-10-31 23:20:37 +01:00

Brmdoor via libnfc

This is an access-control system implementation via contactless ISO 14443A cards and a PN53x-based reader. So you basically swipe your card, and if it's in database, the door unlocks.

Info about authorized users and their cards and keys is stored in sqlite database.

This was originally designed for Raspberry (Raspbian), but it also runs on desktop PC if you have the PN532 USB reader.

The daemon is implemented in brmdoor_nfc_daemon.py.

NFC smartcard API

This project shows how to use libnfc from python to send APDUs to NFC smartcards. Have a look at test_nfc.py for some examples, currently it shows four interactions with NFC smartcards:

  • read NDEF message from token (Mifare Desfire, Yubikey Neo)
  • do HMAC-SHA1 authenthication (Yubikey Neo)
  • read Track 2 Equivalent Data from Visa
  • execute signature for payment on Mastercard

It is much more general in use than to use it as authenthicator to open door.

Building and dependencies

You need just to run make. Additional dependencies:

All dependencies can be installed on Ubuntu or Debian/Raspbian via:

apt install libnfc-dev libfreefare-bin libfreefare-dev python-axolotl-curve25519 swig2.0 python-dev
pip install irc wiringpi2

To build, just run make:

make

Howto

  1. Create the database

     python create_authenticator_db.py authenthicator_db.sqlite
    
  2. Copy sample config file, edit your pins, DB file location, timeouts

     cp brmdoor_nfc.config.sample brmdoor_nfc.config
    
  3. Add some users

  • either authentication by UID, e.g.:

    ./brmdoor_adduser.py -c brmdoor_nfc.config -a uid 34795FCC SomeUserName
    
  • authentication by Yubikey's HMAC-SHA1 programmed on slot 2

    ./brmdoor_adduser.py -c brmdoor_nfc.config -a hmac 40795FCCAB0701 SomeUserName 000102030405060708090a0b0c0d0e0f31323334
    
  • to program Yubikey slot 2 to use HMAC with given key (requires package yubikey-personalization), use:

    ykpersonalize -2 -ochal-resp -ohmac-sha1 -ohmac-lt64 -oserial-api-visible
    
  • authentication using signed UID as NDEF message on Desfire:

    ./brmdoor_adduser.py -c brmdoor_nfc.config -a ndef 04631982cc2280 SomeUserName
    
  • you need to generate Ed25519 keypair, store the private key somewhere safe and put the public in config file

    ./generate_ed25519_keypair.py
    
  • you need to program the Desfire card to have the signature

    ./write_signed_ndef_on_desfire.py private_key_in_hex
    

Finally, run the daemon:

    sudo python brmdoor_nfc_daemon.py brmdoor_nfc.config

Configuring libnfc devices

If you have PN532 device on other bus than USB (e.g. SPI), first search for it using:

sudo nfc-scan-device -i

After that, create file /etc/nfc/libnfc.conf with line describing your device from nfc-scan-device above, e.g. for SPI device:

device.connstring = "pn532_spi:/dev/spidev0.0"

This daemon expects the library to be already configured to find the PN532 device.

If you installed libnfc from source, the default directory might be /usr/local/etc/nfc instead of /etc/nfc.

Conflicts with other running software - pcscd, pn533 kernel modules

If you have pcscd running, it will take over the reader and you can't use it. Kill/stop pcscd service/process if running.

Similarly, you have to blacklist pn533 and pn533_usb kernel modules (usually in a file like /etc/modprobe.d/blacklist.conf).

Startup with systemd and GNU screen

Example of startup unit for systemd, put in /etc/systemd/system/brmdoor.service and this repo cloned in /root/brmdoor_libnfc:

[Unit]
Description=brmdoor
 
[Service]
Type=forking
User=root
ExecStart=/usr/bin/screen -L -d -m -S brmdoor
WorkingDirectory= /root/brmdoor_libnfc/
 
[Install]
WantedBy=multi-user.target

After adding the service file, run systemctl daemon-reload to notify systemd that unit was added. To enable automatic startup, use systemctl enable brmdoor.service.

A /root/.screenrc file that will run the daemon in detached screen:

autodetach on
startup_message off 

screen -t brmdoor 0 /root/brmdoor_libnfc/brmdoor_start.sh

Known bugs (TODO)

  • IRC disconnect is sometimes detected late, e.g. when trying to send message that door was open. This causes the message to be lost, but the reconnect will kick in

Notes

You could use Android Host Card Emulation to emulate a Desfire - it actually just expects one application, D2760000850101.

See an example of HCE NDEF emulation.

You could just modify write_signed_ndef_on_desfire.py to write out the JSON into a file and then put the generated NDEF file into application so it will respond with it when