Route account lookups through the blind index and keep it fresh on write
These are the paths that must stop depending on deterministic encryption before storage can move to AES-GCM. Each keeps its original ciphertext comparison in the same statement, so behaviour is unchanged today and no account becomes unreachable during the transition. Lookups: - auth/login.php — passenger sign-in matched the raw value against the encrypted column, which only works because encryptData() is CBC with a fixed IV. - auth/passenger/register.php and auth/driver/register.php — duplicate detection. Without the index these would stop detecting existing accounts under GCM and allow the same phone to register twice. Writes now populate the index in the same statement as the value: - both registration paths write phone/email/name indexes with the row; driver indexes are computed before the encryption pass, since the raw values are unavailable afterwards. - passenger profile update and admin driver update refresh the index when the underlying field changes. For the composite name index the untouched half is read back from the row. Adds --audit to the backfill script: recomputes every index from its encrypted value and reports missing or stale entries. Drift here is silent by nature — it surfaces only when a real search fails. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
15f55ff3e4
commit
c9b4d14da6
@@ -103,8 +103,17 @@ try {
|
||||
// Step 6: التحقق من وجود المستخدم (Database Check)
|
||||
// ======================================================
|
||||
$step = 6;
|
||||
$checkStmt = $con->prepare("SELECT id FROM passengers WHERE phone = ?");
|
||||
$checkStmt->execute([$phoneNumber_encrypted]);
|
||||
// كشف التكرار عبر الفهرس الأعمى + المقارنة القديمة: بدون الفهرس يفشل
|
||||
// الكشف بعد الانتقال إلى GCM فيُسمح بتسجيل نفس الرقم مرتين.
|
||||
global $blindIndex;
|
||||
$phoneBidx = $blindIndex ? $blindIndex->index('passengers.phone', $phoneNumber) : null;
|
||||
$emailBidx = $blindIndex ? $blindIndex->index('passengers.email', $email) : null;
|
||||
$nameBidx = $blindIndex ? $blindIndex->index('passengers.name', trim("$firstName $lastName")) : null;
|
||||
|
||||
$checkStmt = $con->prepare(
|
||||
"SELECT id FROM passengers WHERE phone = ? OR (? IS NOT NULL AND phone_bidx = ?)"
|
||||
);
|
||||
$checkStmt->execute([$phoneNumber_encrypted, $phoneBidx, $phoneBidx]);
|
||||
|
||||
if ($checkStmt->rowCount() > 0) {
|
||||
error_log("$logTag Step 6 Error: User already exists.");
|
||||
@@ -119,8 +128,8 @@ try {
|
||||
error_log("$logTag Step 7: Inserting into passengers table...");
|
||||
|
||||
$insertStmt = $con->prepare("
|
||||
INSERT INTO passengers (id, first_name, last_name, email, phone, password, gender, birthdate, site, sosPhone, education, employmentType, maritalStatus, status, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', NOW(), NOW())
|
||||
INSERT INTO passengers (id, first_name, last_name, email, phone, password, gender, birthdate, site, sosPhone, education, employmentType, maritalStatus, status, created_at, updated_at, phone_bidx, email_bidx, name_bidx)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', NOW(), NOW(), ?, ?, ?)
|
||||
");
|
||||
$success = $insertStmt->execute([
|
||||
$uniqueId,
|
||||
@@ -135,7 +144,11 @@ try {
|
||||
$unknown_encrypted,
|
||||
$unknown_encrypted,
|
||||
$unknown_encrypted,
|
||||
$unknown_encrypted
|
||||
$unknown_encrypted,
|
||||
// فهارس البحث: تُكتب مع السجل حتى يكون قابلاً للبحث فوراً
|
||||
$phoneBidx,
|
||||
$emailBidx,
|
||||
$nameBidx
|
||||
]);
|
||||
|
||||
if (!$success) {
|
||||
|
||||
Reference in New Issue
Block a user