Advancements in cryptanalysis and hacking techniques are continuously reducing the cost of accessing your data without your authorization, making it easier and more attractive for different sides to get it.
And while itβs good to have a tool like Midbar that can significantly increase the cost of unauthorized access to your data, itβs even better to have a convenient tool, that can do so. One of the inconveniences present in Midbar is that only one version of Midbar (Midbar (Teensy 4.1 Version) V2.0) can type your credentials as if it were a USB keyboard. Donβt get me wrong, the Midbar (Teensy 4.1 Version) V2.0 is not fundamentally flawed or anything like that. It just so happened that the Teensy 4.1 board costs roughly $40. So, my solution to the βcost issueβ is to replace a $40 board with two boards that you can buy for under $5 each.
As for the description of the Midbar project itself:
Midbar is a hardware data vault. Unlike hardware authentication devices, it can store your login credentials, credit card information, notes, and phone numbers. Midbar encrypts your data and requires a master password and, in some cases, four additional RFID cards to access it. With Midbar, you donβt have to worry about memorizing the login credentials and credit card information for the services you use. It does that for you.
Compared to software vaults, Midbar provides more security because it does not have thousands of other processes running alongside it, significantly contributing to making it almost invulnerable to side-channel attacks. Additionally, Midbar utilizes sophisticated integrity verification and superencryption features.
The integrity verification feature ensures that any corruption or unauthorized modification of your data will not go unnoticed. Superencryption is a safeguard that would be useful in case a highly improbable black swan event renders one of the major encryption algorithms (AES or Serpent) insecure. Even after such an event, your data would still be encrypted with one secure and two βsomewhat semi-secureβ encryption algorithms, providing an extra layer of protection.
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 Instructables and Medium.
Supplies
Supplies for the vault:
- ESP32 x1
- 2.4 Inch TFT LCD with ILI9341 x1
- PS/2 Keyboard x1
- PS/2 Port x1
- STM32F103C8T6 x1
Supplies for the receiver:
- ESP32 x1
- 1.77 Inch TFT LCD with ST7735 x1
- 4x4 Keypad x1
10Β΅F capacitor x1 *optional
3DES + AES + Blowfish + Serpent in CBC Mode
The β3DES + AES + Blowfish + Serpentβ encryption algorithm in cipher block chaining mode first appeared in the Midbar V2.5. And since then has been utilized by the Midbar (Raspberry Pi Pico Version),Midbar V3.0,Midbar V4.0,KhadashPay V2.0,Midbar (Raspberry Pi Pico Version) V2.0,KhadashPay V2.0 (Raspberry Pi Pico Version),Midbar V5.0,Midbar (STM32F401CCU6 Version),KhadashPay V3.0 (STM32F401CCU6 Version),KhadashPay V3.0,Midbar (STM32F401CCU6 + Arduino Uno Version),KhadashPay V3.5,Black Swan V2.0,Midbar (Teensy 4.1 Version),Hash Latch,Midbar (Teensy 4.1 Version) V2.0,Midbar (ESP8266 Version) V2.0,Midbar (STM32F407VET6 Version),Midbar (STM32F407VET6 + Arduino Uno Version),DIY IoT Data Vault With Google Firebase (Midbar Firebase Edition V1.0),DIY IoT Payment System With Google Firebase (KhadashPay Firebase Edition V1.0), and Midbar (STM32F407VET6 Version) V2.0.
Although the β3DES + AES + Blowfish + Serpentβ encryption algorithm ainβt exactly what I would call βa cryptographically weak encryption algorithm, β operating it in a weird derivation of the ECB mode, the way it was done by the Midbar V2.0 wasnβt the best idea that I had. Even though that wouldnβtβve allowed the attacker to produce the legitimate ciphertext by swapping the blocks within the ciphertext, an attacker could still make a legitimate ciphertext by replacing the nth block of the ciphertext N1 with the nth block of the ciphertext N2. To fix that vulnerability (instead of just notifying the user that the decrypted ciphertext mightβve been forged), I made the β3DES + AES + Blowfish + Serpentβ encryption algorithm work in CBC mode. So, if an attacker replaces a block of ciphertext, they spoil not just that block but also the subsequent one.
Iβll be honest with you, the bit-flipping attack βkinda works, β but I doubt that it would ever go unnoticed because of the βHMAC-SHA256β-based integrity verification feature
And letβs not forget that this encryption algorithm performs the operation called superencryption.
As defined by NIST, superencryption is an encryption operation for which the plaintext input to be transformed is the ciphertext output of a previous encryption operation.
Such organization of the encryption algorithms makes a combined encryption algorithm that is at least as strong as the strongest one in the cascade, has a longer key, might be more resistant to some attacks, and might produce a ciphertext with higher entropy. Anyway. It wonβt hurt to have an additional layer of security (or several of them).
Integrity Verification
The Midbar V6.0 is the seventeenth version of Midbar that verifies the integrity of the whole record. So, the legitimate ciphertexts moved between the cells arenβt much of a threat to it.
The integrity verification feature of Midbar is based on βHMAC-SHA256.β When you enter data into Midbar, it consolidates all the data into a single string, computes a tag for that string, and saves the newly computed tag in encrypted form. When you decrypt your data, Midbar also decrypts the previously saved tag and computes a new one for the decrypted data. It then compares both tags. If they donβt matchβββMidbar notifies you that the integrity verification failed.
Download FirmwareYou 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 roughly 9 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 310 MB archive from GitHub.
Step 4: Download and Install the LibrariesTFT_eSPI: https://github.com/Bodmer/TFT_eSPI
PS2KeyAdvanced: https://github.com/techpaul/PS2KeyAdvanced
PS2KeyMap: https://github.com/techpaul/PS2KeyMap
Adafruit-GFX-Library: https://github.com/adafruit/Adafruit-GFX-Library
Adafruit_BusIO: https://github.com/adafruit/Adafruit_BusIO
Adafruit-ST7735-Library: https://github.com/adafruit/Adafruit-ST7735-Library
Keypad: https://github.com/Chris--A/Keypad
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.
Replace the Preset File for the TFT_eSPI LibraryTFT_eSPI Library requires the config to be adjusted depending on the display and the board that drives that display. Initially, I wanted to write the mini-guide on adjusting the config for the ILI9341 display to be properly used on the ESP32βs HSPI. But then I realized that it would be more convenient to attach the adjusted config to the firmware and tell you where to place it.
Take the βUser_Setup.hβ file from the βESP32_Version\V6.0β folder and place it in the βC:\Program Files (x86)\Arduino\libraries\TFT_eSPI-masterβ folder.
Install ESP32 Filesystem UploaderThe primary purpose of the ESP32 Filesystem Uploader is to let you upload files into ESPβs filesystem. In this tutorial, the purpose of this tool is to upload an empty SPIFFS image into ESP.
Download the file called ESP32FS-1.0.zip from https://github.com/me-no-dev/arduino-esp32fs-plugin/releases/
And then extract the content of the archive into the ββ¦\Arduino\Tools\β folder.
After that, restart the Arduino IDE.
Switch the Partition Scheme to the βHuge APP (3MB No OTA/1MB SPIFFS)βYou have to switch the partition scheme to the βHuge APP (3MB No OTA/1MB SPIFFS)β before you continue working with ESP32 because the firmware for the vault is too big for the default partition.
Format VaultβS Built-In Flash MemoryConnect the ESP32 that youβre going to use a core of the vault to the computer. Click Tools -> ESP32 Sketch Data Upload. Then click Yes in the pop-up window. The program is going to format the built-in flash memory.
Some boards will flash without any problems.
Unfortunately, thatβs not the case for all boards. If you configured IDE correctly, installed drivers, selected the corresponding port, and still keep getting this error: A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header. Connect a 10Β΅F capacitor to the board while flashing.
Connect the positive lead of the capacitor to the EN pin of the ESP32;
Connect the negative lead of the capacitor (usually indicated by the gray stripe) to the GND pin of the ESP32.
Donβt forget to disconnect the capacitor after the board flashes.
Generate KeysTo 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 βESP32_Version\V6.0\Untested RNGβ folder and click the βGenerate keys for Midbar V6.0β button. The background turns from dark gray to light gray when you press that button.
Get the Receiverβs MAC AddressTo get the receiverβs MAC address, upload this code into the receiver board.
#include <WiFi.h>
void setup(){
Serial.begin(115200);
Serial.println();
Serial.println(WiFi.macAddress());
}
void loop(){
}Then open the Serial Terminal, and reboot the board.
If done correctly, you should see the MAC address in the console.
The MAC address of this board is 94:E6:86:37:FF:D8
Modify the FirmwareFirst, open the βFirmware_for_ESP32.inoβ file from the βESP32_Version\V6.0\Firmware_for_vault\Firmware_for_ESP32β folder and replace my keys with those youβve generated as well as the receiver MAC address in the following line:
uint8_t broadcastAddress[] = {0x94, 0xE6, 0x86, 0x37, 0xFF, 0xD8}; // Receiverβs MAC address
You can also tweak some parameters in the following lines:
#define MAX_NUM_OF_RECS 500
uint16_t colors[5] = { // Purple, Yellow, Green, Shade of Blue N1, Shade of Blue N2
0xb81c, 0xfde0, 0x87a0, 0x041c, 0x051b
};
const uint16_t current_inact_clr = colors[1];
const uint16_t five_six_five_red_color = 0xf940;
bool display_moving_background = true;
bool display_pattern_while_adding_and_printing_record = true;
When youβre done modifying firmware for the vault, open the βFirmware_for_receiver.inoβ file from the βESP32_Version\V6.0\Firmware_for_receiverβ and replace the values of hmackey_for_session_key, projection_key, proj_serp_key with the ones youβve generated.
Flash ESPsUpload the modified firmware from the βESP32_Version\V6.0\Firmware_for_vault\Firmware_for_ESP32β and βESP32_Version\V6.0\Firmware_for_receiverβ folders into both ESPs.
Flash STM32If you want Midbar to emulate the USB keyboard, youβll need to upload the firmware from the βESP32_Version\V6.0\Firmware_for_vault\Firmware_for_STM32F103C8T6β folder into STM32F103C8T6.
The process of setting up the Arduino IDE and flashing the STM32F103C8T6 is quite complex and relatively time-consuming.
Hereβs the link to the Google Translate version of the helpful tutorial that explains how to properly flash STM32F103C8T6: https://habr-com.translate.goog/ru/articles/395577/?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en-US&_x_tr_pto=wapp&_x_tr_hist=true
You can find the original version of the tutorial at https://habr.com/ru/articles/395577/
Assemble the Vault
Assembling the circuit shouldnβt be hard, simply connect all required components to the ESP32 that youβve decided to use as a core of the vault. 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.
Assemble the Receiver
That should be even easier than the vault assembly. Simply connect the display and keypad to the ESP32 that youβve chosen as a core of the receiver
Power the Midbar UpMidbar V6.0 has fifteen lock screens. It randomly chooses one at startup. Once the lock screen is chosen, the word βΧΧΧΧ¨β with the shifting background is displayed alongside the βMidbar ESP32 V6.0β and βPress Any Keyβ inscriptions.
If you want the Midbar to emulate a USB keyboard, connect a data cable to the STM32.
*Credit for the photos:
Photo by Francesco Ungaro from Pexels
Photo by Visit Qatar on Unsplash
Image by Volker GlΓ€tsch from Pixabay
Photo by Afif Ramdhasuma from Pexels
Image by krystianwin from Pixabay
Photo by Mike Stezycki on Unsplash
Image by herdzmedia from Pixabay
Photo by Alejandro Luengo on Unsplash
Photo by Samuel Agbetunsin on Unsplash
Image by apriltan18 from Pixabay
Set Master PasswordTo 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, press either the βEnterβ or the βESCβ key on the PS/2 keyboard.
After youβve unlocked the vault and got to the main menu:
- Press the βββ (DOWNWARDS ARROW) key on the PS/2 keyboard to go down the menu.
- Press the βββ (UPWARDS ARROW) key on the PS/2 keyboard to go up the menu.
- Press either the βEnterβ key on the PS/2 keyboard to open the selected menu.
- While in the submenu, press either the βEscβ or the βBackspaceβ key on the PS/2 keyboard to return to the main menu.
While entering a text in a tab:
- Press βEnterβ on the PS/2 keyboard to continue.
- Press the βEscβ button on the PS/2 keyboard to cancel the current operation.
Midbar V6.0, just like several other versions that came before it, utilizes the 3DES + AES + Blowfish + Serpent encryption algorithm in CBC mode with an integrity verification feature to encrypt your data. Encrypted data is stored in the ESP32βs built-in flash memory.
To add a login:
- Select the βLoginsβ line in the main menu;
- Press the βEnterβ key on the PS/2 keyboard;
- Select the βAddβ line;
- Press the βEnterβ key on the PS/2 keyboard;
- Choose the slot you want to put the login to by pressing the βββ (Leftwards Arrow) and βββ (Rightwards Arrow) keys on the PS/2 keyboard;
- Press the βEnterβ key on the PS/2 keyboard;
- Enter the title;
- Press βEnterβ on the PS/2 keyboard;
- Enter the username;
- Press βEnterβ on the PS/2 keyboard;
- Enter the password;
- Press βEnterβ on the PS/2 keyboard;
- Enter the website;
- Press βEnterβ on the PS/2 keyboard.
*All credentials demonstrated here are entirely fictitious. Any similarity to actual credentials is purely coincidental.
View Login
To view a login:
- Select the βLoginsβ line in the main menu;
- Press the βEnterβ key on the PS/2 keyboard;
- Select the βViewβ line;
- Press the βEnterβ key on the PS/2 keyboard;
- Choose the slot from which you want to view the login by pressing the βββ (Leftwards Arrow) and βββ (Rightwards Arrow) keys on the PS/2 keyboard;
- Press the βEnterβ key on the PS/2 keyboard.
*All credentials demonstrated here are entirely fictitious. Any similarity to actual credentials is purely coincidental.
Edit Login
To edit a login:
- Select the βLoginsβ line in the main menu;
- Press the βEnterβ key on the PS/2 keyboard;
- Select the βEditβ line;
- Press the βEnterβ key on the PS/2 keyboard;
- Select the login you would like to edit by pressing the βββ (Leftwards Arrow) and βββ (Rightwards Arrow) keys on the PS/2 keyboard;
- Press the βEnterβ key on the PS/2 keyboard;
- Enter the new password;
- Press βEnterβ on the PS/2 keyboard.
*All credentials demonstrated here are entirely fictitious. Any similarity to actual credentials is purely coincidental.
Type Login
To type a login:
- Select the βLoginsβ line in the main menu;
- Press the βEnterβ key on the PS/2 keyboard;
- Select the βTypeβ line;
- Press the βEnterβ key on the PS/2 keyboard;
- Choose the slot you want to type login from by pressing the βββ (Leftwards Arrow) and βββ (Rightwards Arrow) keys on the PS/2 keyboard;
- Press the βEnterβ key on the PS/2 keyboard;
- Press either the βββ (Upwards Arrow) key on the PS/2 keyboard to type the website;
- Press either the βββ (Upwards Arrow) key on the PS/2 keyboard to type the username;
- Press either the βββ (Upwards Arrow) key on the PS/2 keyboard to type the password.
*All credentials demonstrated here are entirely fictitious. Any similarity to actual credentials is purely coincidental.
*As for the origin of the patterns:
I made 80x80px patterns myself, the full-height flower pattern was generated by Bing Image Creator on December 5th, 2023.
You can view each pattern individually if you want.
- https://wokwi.com/projects/382246140542986241
- https://wokwi.com/projects/382260067255254017
- https://wokwi.com/projects/382260181271144449
- https://wokwi.com/projects/384520365948379137
To delete a login:
- Select the βLoginsβ line;
- Press the βEnterβ key on the PS/2 keyboard;
- Select the βDeleteβ line;
- Press the βEnterβ key on the PS/2 keyboard;
- Select the login you would like to delete either by pressing the βββ (Leftwards Arrow) and βββ (Rightwards Arrow) keys on the PS/2 keyboard;
- Press the βEnterβ key on the PS/2 keyboard.
The process of working with records of other types is very similar to the process of working with logins.
Send Password to the Receiver
While reading the Espressif documentation on random number generation, Iβve learned that RNG only works under one of the three conditions, one such condition is that the βRF subsystem is enabled.β
Since I didnβt want to simply enable the Wi-Fi or Bluetooth on ESP32 without doing anything with it, I made a feature that enables you to securely send a password to a distance of up to 650 feet (200 meters).
To protect the receiver from the replay attack (ensure that the receiver wonβt correctly decrypt any package that is resent to it)βββIβve combined the key incrementation with the session key. The session key consists of 20 characters generated by the vault. The session key is valid until you either reboot the vault or power it off. After the key derivation process is completed, both devices present you with the three verification numbers. These numbers must match on both the vault and the receiver! If these numbers donβt match, I would advise you to reboot the receiver board and enter the session key again. If that wonβt work, open the firmware and check if the keys are the same.
To send the password to the receiver:
- Select the βOther Optionsβ line in the main menu;
- Press the βEnterβ key on the PS/2 keyboard;
- Select the βSend Passwordβ line;
- Press the βEnterβ key on the PS/2 keyboard;
- Enter the key on the receiverβs keypad;
- Compare the verification numbers on both displays. They must match;
- Press the βEnterβ key on the PS/2 keyboard;
- Enter the password (string) youβd like to send on the PS/2 keyboard;
- Press the βEnterβ key on the PS/2 keyboard to send the password to the receiver.
The receiver also prints the received text to the Serial Terminal.
According to the quick tests Iβve conducted, the Midbar V6.0 can transfer a 200-character long string over the air without any problems.
Final ThoughtsMidbar V6.0 is the first ESP32-based version of Midbar that can act as if it were a USB keyboard. This feature isnβt new for the Midbar project itself, but itβs new for that particular branch. Quite frankly, the only advantage that this version of Midbar has over the Midbar (Teensy 4.1 Version) V2.0 is the lower cost of components. So, if you can afford to buy a Teensy 4.1, I suggest you make a Midbar (Teensy 4.1 Version) V2.0 instead.
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.









Comments