Midbar (RTL8720DN + Arduino Uno Version)

by Northstrix in Circuits > Microcontrollers

708 Views, 2 Favorites, 0 Comments

Midbar (RTL8720DN + Arduino Uno Version)

IMG_20230821_174708.jpg

As I've mentioned before, advancements in cryptanalysis and hacking techniques are continuing to reduce the cost of unauthorized access to your data, making it easier and more attractive for different parties to get it.

I won't get into details about the motivation of each party and the goals they're trying to achieve by obtaining your data. Instead, I would like to focus on the solution to that problem.

In my opinion, the only way to keep your data private is to raise the cost of unauthorized access to it as high as possible. The best-case scenario is to raise the costs of unauthorized access to your data so high that it would significantly outweigh any potential reward for any party.

To raise the cost of unauthorized access to your data - I've developed Midbar (which later on "evolved" into a multi-user Cipherbox, and then it kinda turned back into Midbar because I realized that a "multi-user Midbar" is superfluous and not as stable as a single-user one).

As for why this project is called Midbar - Midbar (מדבר) is a Hebrew word that means "pasture," "uninhabited land," "wilderness," "large tracts of wilderness (around cities)," and "desert." I had two reasons for choosing the word Midbar as the name of this project. First - while working on my previous projects, I noticed that the so-called "device that keeps your personal data secure in an encrypted form" market is pretty much a "desert around the oasis of the password manager market." Second - I couldn't find a better word to describe this project. At first, I wanted to call it a "Password Vault," but it's more than that. So, I decided to call it Midbar.

You can also read this tutorial on Medium and Hackster.

Supplies

IMG_20230822_153812.jpg
  • RTL8720DN x1
  • 2.4 Inch TFT LCD with ILI9341 x1
  • Arduino Uno x1
  • Mifare RC522 RFID Reader x1
  • RFID cards x4
  • EC11 Rotary Encoder x1
  • 100nf capacitors x2
  • 4.7k resistors x7
  • 580 ohm resistors x4
  • Buttons x2
  • PS/2 Keyboard x1 *optional
  • PS/2 Port x1 *optional
  • Nintendo 64 Controller x1 *optional

How It Came to Be

A while ago, I got my hands on the RTL8720DN development board.

I spent some time testing the board's capabilities, paired it with the Arduino, and made Midbar (RTL8720DN Version).

At that time, I thought that Midbar (RTL8720DN Version) would be enough for that branch of Midbar (at least for the time being), but then I received the Nintendo 64 controller, and upon looking at it, I immediately got struck by an idea, to take the Midbar (RTL8720DN Version) and add the support for the Nintendo 64 controller to it. During the development process, I also decided to make it RFID-lockable.

In addition to that, I added two more lock screens to that version of Midbar and replaced some of the existing ones.

Anyway, enjoy the result.

AES + Blowfish Encryption Algorithm in CBC Mode

AES+Blowfish Encryption Algorithm in CBC Mode.png

I took the encryption algorithm from the Midbar (RTL8720DN Version).

Initially, I wanted to use the "3DES + AES + Blowfish + Serpent" encryption algorithm to encrypt and decrypt the user data. Unfortunately, the RTL8720DN refused to work with the implementation of the Serpent that I'm familiar with. Therefore I've changed the encryption algorithm for that branch of Midbar.

The "AES + Blowfish" encryption algorithm in cipher block chaining mode encrypts the data in 128-bit blocks. To reduce the size of the record stored in the RTL8720DN's flash, I've allotted a single IV for a record.


Flash Partitioning

Flash Partitioning Table.png

I obtained the flash partitioning scheme for the Midbar (RTL8720DN Version) in the same manner as the encryption algorithm. I simply took it from the Midbar (RTL8720DN Version).

EEPROM Integrity Check

EEPROM Integrity Check.png

Since there's not much space available in the RTL8720DN's flash, I've decided not just to allot a single IV for a record but also to verify the integrity of the whole flash area utilized by the Midbar instead of individually verifying the integrity of each record.

That feature came from Midbar (Teensy 4.1 Version) V2.0.

Prepare the Software

You need to set up the Arduino IDE before flashing the RTL8720DN. You can read about it here: 

https://www.amebaiot.com/en/amebad-bw16-arduino-getting-started/

Download Firmware

You can download the firmware for Midbar from one of these sources.

SourceForge: https://sourceforge.net/projects/midbar/

GitHub: https://github.com/Northstrix/Midbar

If you just need the firmware for the device alongside the RNG, then I would advise you to download the archive that weighs less than 2 MB from SourceForge.

But if you need the firmware for all versions of Midbar alongside the extra code, photos, and diagrams, in that case, I would advise you to download the 241 MB archive from GitHub.

Download and Install the Libraries

EncButton: https://github.com/GyverLibs/EncButton

rfid: https://github.com/miguelbalboa/rfid

PS2KeyAdvanced: https://github.com/techpaul/PS2KeyAdvanced

PS2KeyMap: https://github.com/techpaul/PS2KeyMap

arduino-n64-controller-library: https://github.com/pothos/arduino-n64-controller-library

The process of unpacking libraries is typical. You can unpack the content of the archive into the folder: ...\Arduino\libraries. Or open the Arduino IDE, click to the Sketch -> Include Library -> Add .ZIP Library... and select every archive with libraries.

Other required libraries are already present in one way or another.

Generate Keys

gen_keys.png

To make the unauthorized deciphering of your data computationally infeasible - It is crucial to generate your own keys and never reuse them

It's entirely up to you how to generate the keys. I can only offer you an option to do so.

I've modified one of my previous projects to work as a random number generator, the generated output seems "random enough" for me, but I haven't run any tests. So, I can't guarantee that it's random.

Use it at your own risk!

To generate the keys - launch gen.exe from the "RTL8720DN_and_Arduino_Uno_Version\V1.0\Untested RNG" folder and click the "Generate keys for Midbar" button. The background turns from dark gray to light gray when you press that button.

Modify Firmware

mod_firmw.png

Open the "Firmware_for_RTL8720DN.ino" file from the "RTL8720DN_and_Arduino_Uno_Version\V1.0\Firmware_for_RTL8720DN" folder, and then replace my keys with those you've generated.

Upload the Modified Firmware Into RTL8720DN

flash rtl.png

Upload the modified firmware from the "RTL8720DN_and_Arduino_Uno_Version\V1.0\Firmware_for_RTL8720DN" folder into RTL8720DN.

Flash Arduino Uno

flash ard.png

Choose the firmware for the Arduino Uno from the "RTL8720DN_and_Arduino_Uno_Version\V1.0\Firmware_for_Arduino_UNO_PS2_Keyboard" and "RTL8720DN_and_Arduino_Uno_Version\V1.0\Firmware_for_Arduino_UNO_N64_controller" folders.

One of them is designed to handle the PS/2 keyboard, while the other one is designed to handle the Nintendo 64 controller.

When you've chosen the firmware, upload it to the Arduino UNO.

Assemble Midbar

Midbar Circuit Diagram.png

Assembling the Midbar shouldn't be hard. In my opinion, the most tangled part of the process is to connect the encoder with its periphery the right way.

When it comes to the "BL" pin of the ILI9341 display, different versions of the display have different requirements on what to do with it. Some versions specify that it must be connected to the +3.3V, some require it to be grounded, and others allow you to leave it unconnected.

As for the possible component replacements:

  • You can replace 4.7k resistors with 2.2k - 10k resistors;
  • And you can replace the capacitors with 22nf - 100nf capacitors.


Do not connect the PS/2 keyboard and the Nintendo 64 controller at the same time.

Power the Midbar Up

IMG_20230822_135929_hdr.jpg
IMG_20230822_135949_hdr.jpg
IMG_20230822_140419_hdr.jpg
IMG_20230822_140440_hdr.jpg
IMG_20230822_140701_hdr.jpg
IMG_20230822_140904_hdr.jpg
IMG_20230822_141128.jpg
IMG_20230822_141354.jpg
IMG_20230822_141655_hdr.jpg
IMG_20230822_142219_hdr.jpg
IMG_20230822_142702_hdr.jpg
IMG_20230822_142902_hdr.jpg
IMG_20230822_143122_hdr.jpg
IMG_20230822_143341_hdr.jpg

Midbar (RTL8720DN + Arduino Uno Version) has fourteen lock screens - it randomly chooses four of them at startup.

After the Midbar has chosen the lock screens, it displays the word "מדבר" alongside the "Tap RFID card N1" inscription.


*Credit for photos:

Dallas:

Photo by Talena Reese on Pexels

Denver:

Photo by Jakob Rosen on Unsplash

Downtown Dallas:

Photo by Erin Hervey on Unsplash

Downtown Tel Aviv:

Photo by Shai Pal on Unsplash

London:

Photo by Robert Bye on Unsplash

Miami:

Image by JORGE TAPIA from Pixabay

Milan:

Photo by Samuel Agbetunsin on Unsplash

Minneapolis:

Photo by Daniel McCullough on Unsplash

New Orleans:

Photo by Morgan Petroski on Unsplash

Paris:

Photo by Anthony Tan on Unsplash

Pittsburgh:

Photo by Yuhan Du on Unsplash

Tel Aviv:

Photo by Micah Camper on Unsplash

Vancouver:

Photo by Albert Stoynov on Unsplash

Zurich:

Photo by Claudio Schwarz on Unsplash

Tap Four RFID Cards on the RFID Reader

IMG_20230822_143606_hdr.jpg
IMG_20230822_143647_hdr.jpg
IMG_20230822_143902_hdr.jpg
IMG_20230822_143933_hdr.jpg

After you've powered the Midbar up, tap four RFID cards on the RFID reader one after another. The most important thing here is to tap the cards in the same order every time you unlock Midbar. Otherwise, it just won't unlock.

If you don't have four cards, you can tap one card four times.

Set Master Password

IMG_20230822_144249.jpg
IMG_20230822_144329.jpg
IMG_20230822_144343.jpg

To use the Midbar, you first need to set the master password.

You can't change your master password without performing the factory reset first!

Midbar won't be able to decrypt your data without your master password because the keys for the encryption algorithms are partially derived from it. Perhaps, it won't even unlock without the correct master password.

When you're done entering your master password, either quad-click the encoder button or press the "Enter" on the PS/2 keyboard.


After you've unlocked the vault and got to the main menu:

  • Either turn the rotary encoder to the right or press the "" (DOWNWARDS ARROW) key on the PS/2 keyboard to go down the menu.
  • Either turn the rotary encoder to the left or press the "" (UPWARDS ARROW) key on the PS/2 keyboard to go up the menu.
  • Press either the "A" button or the "Enter" key on the PS/2 keyboard to open the selected menu.
  • While in the submenu, press either the "B" button or the "Esc" key on the PS/2 keyboard to return to the main menu.


While entering a text in a tab:

  • Either quad-click the encoder button four or press "Enter" on the PS/2 keyboard to continue;
  • Either quintuple-click the encoder button (click it five times in quick succession) or press the "Esc" button on the PS/2 keyboard to cancel the current operation.


As for the Nintendo 64 controller:

  • The "Start" button acts as the "Enter" key on the PS/2 keyboard;
  • The "Z" button acts as the "Esc" key on the PS/2 keyboard;
  • The "A" button act as the "A" button connected to the Arduino Uno;
  • The "B" button acts as the "Backspace" key on the PS/2 keyboard;
  • The "D-pad," "C-pad," "L" button, "R" button and stick function as arrows on the PS/2 keyboard.


*If the hex value decreases when you rotate the encoder to the right, I would advise you to swap the wires connected to the Arduino's "5" and "6" pins.

Add Login

IMG_20230801_131030.jpg
IMG_20230801_131109.jpg
IMG_20230801_131117.jpg
IMG_20230801_131141.jpg
IMG_20230801_131226.jpg
IMG_20230801_131322.jpg
IMG_20230801_131328.jpg
IMG_20230801_131333.jpg

As I've mentioned earlier in this tutorial, this version of Midbar has the ability to store up to 16 login credentials.

To add a login:

  1. Select the "Logins" line in the main menu;
  2. Press either the "A" button or the "Enter" key on the PS/2 keyboard;
  3. Select the "Add" line;
  4. Press either the "A" button or the "Enter" key on the PS/2 keyboard;
  5. Choose the slot you want to put the login to either by rotating the encoder or by pressing the "←" (Leftwards Arrow) and "→" (Rightwards Arrow) keys on the PS/2 keyboard;
  6. Press either the "A" button or the "Enter" key on the PS/2 keyboard;
  7. Enter the username;
  8. Either quad-click the encoder button or press "Enter" on the PS/2 keyboard;
  9. Enter the password;
  10. Either quad-click the encoder button or press "Enter" on the PS/2 keyboard;
  11. Enter the website;
  12. Either quad-click the encoder button or press "Enter" on the PS/2 keyboard.


*All credentials demonstrated here are entirely fictitious. Any similarity to actual credentials is purely coincidental.

View Login

IMG_20230801_131346.jpg
IMG_20230801_131352.jpg
IMG_20230801_131400.jpg
IMG_20230801_131420.jpg
Login printed to the Serial Terminal.png

To view a login:

  1. Select the "Logins" line in the main menu;
  2. Press either the "A" button or the "Enter" key on the PS/2 keyboard;
  3. Select the "View" line;
  4. Press either the "A" button or the "Enter" key on the PS/2 keyboard;
  5. Choose the slot you want to view login from either by rotating the encoder or by pressing the "←" (Leftwards Arrow) and "→" (Rightwards Arrow) keys on the PS/2 keyboard;
  6. Press either the "A" button or the "Enter" key on the PS/2 keyboard;
  7. Press either the "A" key on the PS/2 keyboard or the "A" button to print the record to the serial terminal.


*All credentials demonstrated here are entirely fictitious. Any similarity to actual credentials is purely coincidental.

Delete Login

IMG_20230801_131442.jpg
IMG_20230801_131449.jpg
IMG_20230801_131455.jpg

To delete a login:

  1. Select the "Logins" line;
  2. Press either the "A" button or the "Enter" key on the PS/2 keyboard;
  3. Select the "Delete" line;
  4. Press either the "A" button or the "Enter" key on the PS/2 keyboard;
  5. Select the login you would like to delete either by rotating the encoder or by pressing the "←" (Leftwards Arrow) and "→" (Rightwards Arrow) keys on the PS/2 keyboard;
  6. Press either the "A" button or the "Enter" key on the PS/2 keyboard.


The process of working with credit cards is very similar to the process of working with logins.

*As you might've noticed, I borrowed some photos from the tutorial for Midbar (RTL8720DN Version) because the GUI is basically the same.

Find a Good Use for Midbar

IMG_20230801_132206.jpg
IMG_20230801_132222.jpg

Well, Midbar (RTL8720DN + Arduino Uno Version) definitely isn't perfect, and it has some limitations, but nevertheless, it's a fully functional tool for storing your login credentials and credit cards in an encrypted form. And in addition to that, this is the first version of Midbar that can handle the Nintendo 64 controller.

And while Midbar is no guarantee of world peace or social harmony, I do believe that it's an important contribution to the protection of your data from unauthorized access.

I think it's also worth mentioning that Midbar's source code is distributed under the MIT license. That grants you the freedom to customize, adapt and modify Midbar according to your needs and preferences. In other words, you can create your own version of Midbar or use it as a starting point for building new projects without the need for external permission.

If you found this tutorial to be useful, please consider sharing it.

Thank you for reading this tutorial.