Encrypted E-01 backup and a local recovery drill

Encryption before transport, independent checksums, 27 files and a lock-based build. A manual recovery drill without live activation.

A sealed capsule between a server and a laptop; a key rests on the desk beside the laptop.
A sealed capsule between a server and a laptop; a key rests on the desk beside the laptop.

A copy needs a restore test

For the educational E-01, I prepared a narrow encrypted copy of source files and configuration, then restored it into an isolated local directory. This tests a specific set from which the private Symfony skeleton can be built again. A disk image, database, firewall and complete server recovery are outside this set.

The copy contains 27 files: 22 source files from the official Symfony commit, totalling 111279 bytes, runtime .env.local and four HTTPS file roles — the Nginx fragment, certificate, private key and htpasswd. Private values and key content are not published here. Before reading, I checked the exact references to the private application and HTTPS adoption journals.

Two complete readings

For each file, I checked SHA256, permissions, numeric group, root ownership and extended attributes. Two complete readings allowed the set to be compared before capture finished. This is not an atomic snapshot: checking selected files does not freeze every process or the filesystem.

On E-01, this pass made no durable writes, performed no service actions and installed no packages. Encryption happened on the server before data was transferred to the laptop. It used a pinned open OpenSSL file descriptor and fixed configuration; the public recipient certificate was passed through an anonymous memfd. The recipient private key was not sent to the server.

Encryption before transfer

The cryptographic layer is standard OpenSSL 3.5.7 CMS: AES-256-GCM for content and RSA-OAEP with SHA256 for the key. The locally generated RSA recipient has 3072 bits. The plaintext package is 163939 bytes; ciphertext is 164562 bytes.

The example below shows only the cryptographic layer: the Bash command reads an approved prepared stream from stdin and creates a new encrypted file. It neither creates a plaintext file on E-01 nor collects data itself. Path selection, metadata checks, size bounds and exact reconstruction of the set happen separately. The example does not reproduce certificate transport or descriptor retention from the actual run.

# Crypto layer only: supply the reviewed prepared stream on stdin.
# This does not select or collect files. The recipient certificate is public.
# The private recipient key stays on the local restore machine.
set -euo pipefail
set -o noclobber
umask 077
: "${RECIPIENT_CERT:?Set the public recipient certificate path}"
: "${CIPHER_FILE:?Set a new encrypted output path}"
openssl cms -encrypt -binary -aes-256-gcm -outform DER \
  -recip "$RECIPIENT_CERT" \
  -keyopt rsa_padding_mode:oaep \
  -keyopt rsa_oaep_md:sha256 -keyopt rsa_mgf1_md:sha256 \
  > "$CIPHER_FILE"

The local example below uses standard Python subprocess with OpenSSL CMS. The placeholder EXPECTED_CIPHER_SHA256 and EXPECTED_PLAIN_SHA256 values must come from trusted, already accepted pins. It checks ciphertext first, then the OpenSSL return code and plaintext checksum. Plaintext remains in memory; it is neither passed to restoration nor written to a file or terminal until both checks succeed.

# Local Python example: plaintext stays in memory and is never printed.
import hashlib, os, pathlib, subprocess
ciphertext = pathlib.Path(os.environ["CIPHER_FILE"]).read_bytes()
if hashlib.sha256(ciphertext).hexdigest() != os.environ["EXPECTED_CIPHER_SHA256"]:
    raise SystemExit("Ciphertext checksum mismatch")
result = subprocess.run(
    ["openssl", "cms", "-decrypt", "-binary", "-inform", "DER",
     "-recip", os.environ["RECIPIENT_CERT"], "-inkey", os.environ["RECIPIENT_KEY"]],
    input=ciphertext, capture_output=True, check=False)
if result.returncode != 0:
    raise SystemExit("Decryption refused")
plaintext = result.stdout
if hashlib.sha256(plaintext).hexdigest() != os.environ["EXPECTED_PLAIN_SHA256"]:
    raise SystemExit("Plaintext checksum mismatch")
# Only now may the verified plaintext bytes be used by the local restore step.

Encryption does not identify the backup author

Anyone with the recipient’s public certificate can encrypt data to it. Successful decryption alone does not prove that the intended server created the copy. Accepted SHA256 values for both ciphertext and plaintext were pinned before local decryption; the recovered result was checked against them. GCM protects encrypted message integrity but does not replace this provenance binding.

Restoring into a local directory

The destination and its dedicated parent directories have mode 0700; files were created exclusively as new files. All 27 matched in bytes, modes and ACL representations. Original numeric uid/gid values are retained only as metadata: the local files belong to the user running the test. Reusing those numbers locally would not establish equivalent access through NSS.

Using the recovered lock file, Composer installed 32 packages without development dependencies. No ready-made vendor directory was copied. Production cache warmup succeeded. The standard commands below cover this part of the test and run only inside the dedicated restored application.

# In the isolated restored application directory, with the recovered lock.
composer install --no-dev --prefer-dist --no-interaction --no-progress \
  --no-scripts --optimize-autoloader
APP_ENV=prod APP_DEBUG=0 php bin/console cache:warmup

The restored TLS key matched the certificate’s public key. Verification against the pinned CA also confirmed the hostname and server purpose. All 27 original files remained unchanged after Composer and its plugins.

What needs separate storage

The recipient key is in the private local packet for this drill. A separate offline copy or copy outside the same account has not yet been established, so that protection is not claimed. Automatic backup, a timer and a dedicated CLI operation remain next steps. This result establishes local restoration of selected files and an application build, rather than whole-machine recovery or equivalent access semantics.

After verification, I removed only the new private local restore tree: all 27 plaintext files, vendor, cache and the separate Composer home. The encrypted backup is retained. Cleanup made no server changes.

  1. Observability Why a VPS snapshot is not enough for recovery
  2. Operations & Security HTTPS and a password for E-01: Nginx, Origin CA and Symfony
  3. PHP Composer on E-01: a separate Symfony build budget
  4. Operations & Security Adopting protected HTTPS with the CLI without a restart
  5. Operations & Security CLI backup and recovery: from 27 files to a working build

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article