Early 2018 I decided that my hackerspace AfRA needed an electronic door lock. Until then, we used physical keys with all their constraints. Physical keys are hard to revoke (if somebody loses their key, you have to switch the lock and re-distribute keys), expensive (issuing costs) and hard to manage. Most hackerspaces I know of already have electronic door locks.

You can find the current project documentation (in German) on the AfRA Wiki. The entire project code is on Github.

First attempt

To kick off the topic, I bought a equiva BLUETOOTH® Smart Türschlossantrieb, since it was the cheapest electronic door lock available from Amazon. It costs about 45€ from Amazon Marketplace and uses BLE to communicate with a proprietary app. I planned to crack the lock open and only use the mechanics to open the door. To control the motor, I bought a circuit board with four relays and Raspberry PI Zero W.

This idea worked out pretty well until I realized that it is rather important to know the motor position throughout the locking process. Instead of adding hall-sensors or similar to track the position, I trashed the project and we arranged with using physical keys for another year.

Second attempt

In early 2019, I went for another try. In the meantime, somebody on Github had reverse-engineered the BLE communication protocol and build a nodejs library. Since the Raspberry PI already ships with Bluetooth, it was rather easy to connect the lock with some nodejs code. To open the door, I decided to implement two methods:

  1. Login via ssh to open@door lock via the AfRA Wi-Fi. Instead of spawning a shell, the login triggers a Python script that addresses the local nodejs server, which controls the door via the keyble library. Through an ssh login to close@door lock, the door can also be closed.
  2. An EM4100-compatible RFID reader. Since such tokens work on 125kHz, they can easily be used through the glass-door at AfRA. Every token has an individual 10-key number and the reader acts as a simple (keyboard like) USB HID device. A Python script reads the RFID token and opens the door in case of a known/correct token.

To lock the door, users can press the button on the side of the case, which triggers a 5-second timeout. After 5 seconds, the door closes automatically.

The system is in use since mid-February 2019 and currently works like a charm. Since the BLE connection is permanently held, the door lock tended to consume its batteries rather fast (<1 month), so I added a permanent 4.5V power supply.

Bonus: Security considerations

The communication between the door lock and Raspberry PI is encrypted with AES256, and the implementation made a proper impression on first sight. The PSK is shared on a QR code. SSH works for millions of servers and can be considered secure to today’s standards.

EM4100 RFID tokens are relatively easy to read and copy. Therefore, they should usually not be used for access control. However, somebody that would have the technical interest to copy RFID tokens is invited to AfRA anyway. EM4100 tokens are very cheap and individual numbers can be revoked from the system. For the near future, I plan to add the option for a second factor. This second factor could be a keypad that uses optical sensors through the AfRA glass-door.