Repository navigation
Expand file tree
/
Copy pathBlindIndexInterface.php
More file actions
78 lines (73 loc) · 3.74 KB
/
Copy pathBlindIndexInterface.php
File metadata and controls
78 lines (73 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\KeyManagement;
use Symfony\Component\KeyManagement\Exception\LogicException;
/**
* Computes a keyed digest of a value, to find the rows where an encrypted column has that value.
*
* Encryption is randomized, by design and without a way around it, so two encryptions of the same
* value differ and `WHERE email = ?` never matches. The usual answer is to keep a blind index in a
* sibling column: a keyed digest of the value, equal for equal values, and matched exactly.
*
* $user->setEmail($email);
* $user->setEmailIndex($index->of($email)); // on the way in
*
* $repository->findOneBy(['emailIndex' => $index->of($email)]); // and on the way out
*
* The first of those two lines is the one that gets forgotten, and a row whose tag was not written
* is a row no search returns. On a Doctrine entity, the `BlindIndexed` attribute of
* `symfony/doctrine-orm-key-management` says on the index column where its value comes from and has
* a listener fill it on every flush.
*
* What of the value is indexed is a {@see BlindIndex\ProjectionInterface}. Where the index key
* comes from is the implementation: {@see BlindIndex} unwraps a wrapped key through the KMS, and
* {@see StoredKeyBlindIndex} names one a store holds.
*
* The tags are derived under a subkey of that data key, named by the index, so one key serves as
* many indexes as an application has without any two of them tagging a value alike. The key itself
* **never rotates**: every index already written was derived under it, and a new key matches none
* of them. Rotating it means reindexing, which means reading every row.
*
* **What this leaks.** Equal values give equal tags, so anyone reading the column learns which rows
* share a value, and how often each occurs. On a column with few distinct values, or one whose
* distribution is known, that is enough to recover the values themselves by frequency analysis: a
* country, a status, a birth year. Index what is high-entropy and looked up by equality, an address
* or an account number, and leave the rest to a decrypted scan.
*
* Prefix, substring and range searches are this same construction over several tags per row, held
* in a column the database can intersect, `text[]` with a GIN index on PostgreSQL. What those tags
* are, and how much more they leak, is a decision that belongs to the application.
*
* @author Florent Morselli <florent.morselli@spomky-labs.com>
*
* @experimental
*/
interface BlindIndexInterface
{
/**
* The tag of a value, which an equality search needs.
*
* @return string 64 lowercase hexadecimal characters, whatever the algorithm and the length of the value
*
* @throws LogicException If the projection of this index is a {@see BlindIndex\CoveringProjectionInterface},
* whose forms {@see allOf()} returns, or if the algorithm returns a tag of any other width
*/
public function of(#[\SensitiveParameter] string $value): string;
/**
* A tag per form a {@see BlindIndex\CoveringProjectionInterface} covers, for a column holding
* them all: a `text[]` with a GIN index on PostgreSQL, which the application writes and
* intersects itself. The one tag of {@see of()} for any other projection.
*
* @return list<string> one tag per form, each 64 lowercase hexadecimal characters
*
* @throws LogicException If the algorithm returns a tag of any other width
*/
public function allOf(#[\SensitiveParameter] string $value): array;
}