Encryption without changes in the application

You have the program, but not its source code. Or the developer does not change it. Version v2027R1 encrypts its database anyway: the program files stay the same.

  • 0 changes in the application
  • 1 small library, or 1 line of configuration
  • Firebird 5.0 · 4.0 · 3.0
  • Network and embedded connections
  1. 1The application connectsas usual; it knows nothing about encryption
  2. 2The server asks for the keythe database header has the key name
  3. 3fbclient loads KeyHolderone line in firebird.conf near the client library
  4. 4KeyHolder calls MakeKeysone function in your KeySource.dll
  5. 5The key goes to the serverin encrypted form, at each connection
  6. 6✓ The database is openthe application works as before

4 ways to encrypt the database of an application without source code changes

Encrypt database for closed-source applications

You put the library KeySource.dll on the workstation near fbclient.dll, usually in the folder of the application. The client plugin KeyHolder finds it and calls one function, MakeKeys. The function returns the key as text. That is all.

What the function does is your decision. The example has four ready libraries with source code, and templates for C++, Delphi and Lazarus. On Linux the library is libKeySource.so. You do not put the library on the server: the server keeps no key.

Four ready variants of the KeySource library: the key in the library code, in a file, in the memory of a tray program, at a key service A · in the library codethe simplest: one file to copy B · in a filefor example on a removable disk C · in the memory of a tray programa person types the key or pass phrase D · at a key serviceREST request in your network KeySource.dllone function: MakeKeysreturns the key as textnear fbclient.dll KeyHolderclient plugin sendsthe key to the server
the keySource code of all four libraries is in the example. Take one as a base and write your own.

What you add to the workstation

MyApp.exe               the application, not changed
fbclient.dll            client library from the plugin package or HQbird
firebird.conf           KeyHolderPlugin = KeyHolder
KeySource.dll           your library with the function MakeKeys
plugins\keyholder.dll   client plugin

The server needs the plugins, the license file and the same line KeyHolderPlugin = KeyHolder. It needs no file with keys.

The example application. The table is open, the status line shows database: encrypted. The application code has no line about encryption.

Built-in dialog

No library at all: the plugin asks for the key

Add one line to plugins\KeyHolder.conf on the workstation. When the application connects, the plugin shows its own window, and the user types the key or the pass phrase.

Prompt = Enter key %k for database %d

%k is the key name and %d is the database name. The user can type a key in hexadecimal form or any other text: the plugin takes other text as a pass phrase.

After a wrong key, the window shows the error and waits 5 seconds before the next try. This slows down an attack by key guessing. On Linux, the plugin asks in the terminal.

The dialog is for network connections of desktop programs. A service or a scheduled job has no person to type the key: use KeySource.dll for them.

Enter key RED for database crypt_employee
••••••••••••••••••••••••
ConfirmCancel
Show password

Pass phrase

A pass phrase instead of a key

A key is 32 random bytes. A person cannot remember it. A pass phrase is easy to remember, and it is not written on any disk. The plugin calculates the key from the phrase each time.

A phrase works in the built-in dialog, in the tray program of the example, and in the configuration line Password=. The key is only as strong as the phrase, so use a long phrase.

The plugin calculates a key of 32 bytes from the pass phrase with the PBKDF2 function A PERSON REMEMBERSmy long pass phrase 2026 PBKDF2in the plugin KEY OF 32 BYTES · AES-256 the same phrase always gives the same key

Encrypt with a phrase: one command of the example

PS> .\run-all.ps1 -Version 5 -AskPassphrase
Pass phrase of the database: ************************

The script checks the phrase before it encrypts the database. It refuses the characters that the configuration reader changes: ", #, {, } and $(.

The tray program asks for the phrase at the first connection. After that, it gives the key from memory, and the window does not appear again.

Verified

Tested in 42 combinations

We ran the example application in each combination: Firebird 3.0, 4.0 and 5.0; network and embedded connection; four key sources; a key and a pass phrase. The application connects, changes a row, connects again and reads it.

24 + 18

42 combinations pass

24 with a key, 18 with pass phrases, including phrases with spaces and national letters.

1000

Connections in sequence

And 8 threads with 125 connections each, for each key source. No errors.

3 versions

Encrypted backup and test restore

gbak backup with the same key source, check of the file, restore into an encrypted database.

Ready example

Try it in 10 minutes

The example on GitHub

The example installs a separate test server and does not touch your Firebird. It downloads the official Firebird and the plugin package with a trial license.

PS> git clone https://github.com/IBSurgeon/FirebirdEncryptionGuide
PS> cd FirebirdEncryptionGuide\examples\closed-gui\deploy
PS> .\05-download-example.ps1          # ready programs of the example
PS> .\run-all.ps1 -Version 5           # server, encrypted database, workstation folder
PS> ..\work\fb5\remote\EmployeeRemote.exe
PS> .\50-backup.ps1 -Version 5         # encrypted backup and a test restore
  1. 1DownloadFirebird, the plugin package, the example programs
  2. 2Installa separate server on its own port
  3. 3Encrypta copy of the employee database
  4. 4Deploythe workstation folder with KeySource.dll
  5. 5✓ Connectthe application opens the encrypted database

Deployment

Five rules for your own application

  • The same bitnessClient files and KeySource.dll have the bitness of the application, not of Windows.
  • The client library from the packageReplace the fbclient.dll or gds32.dll of the application with the library from the plugin package or from HQbird.
  • No KeySource.dll on the serverThe server plugin calls it too, and then the key is on the server.
  • No FIREBIRD variable on the workstationWith this variable the client looks for its files in another folder.
  • One package for clients and serverClient and server libraries from different packages cannot exchange the key.
  • Everybody needs the keyReports, services and backup jobs connect too. Give each of them a key source.

If you have HQbird, you do not download or copy the plugin: the server plugins are in the Firebird folder, and the client files are in the folder ClientLibs.