Skip to content

Commit

Permalink
Add sensitive parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelias committed Nov 22, 2023
1 parent 1d43e7a commit cfd24ed
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 42 deletions.
8 changes: 4 additions & 4 deletions src/Command/GenerateIndexesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

#[AsCommand(name: 'odb:enc:indexes', description: 'Determine the Blind Index plan for a given field.')]
#[AsCommand(name: 'odb:enc:indexes', description: 'Generates matching indexes')]
class GenerateIndexesCommand extends Command
{
/** @deprecated */
protected static $defaultName = self::CONSOLE_CMD;
/** @deprecated */
protected static $defaultDescription = 'Determine the Blind Index plan for a given field.';
protected static $defaultDescription = 'Generates matching indexes';

protected static string $defaultAlias = 'o:e:i';

Expand Down Expand Up @@ -124,7 +124,7 @@ protected function validateParallelOptions(InputInterface $input): array
*
* @throws MissingPropertyFromReflectionException
*/
protected function initAndRunFiltersGenerationSubProcesses(string $className, array $parallelConfig): void
protected function initAndRunFiltersGenerationSubProcesses(#[\SensitiveParameter] string $className, array $parallelConfig): void
{

$start = time();
Expand Down Expand Up @@ -190,7 +190,7 @@ private function runProcesses(array $pools): void
/**
* @throws MissingPropertyFromReflectionException
*/
protected function regenerateFiltersByFieldnameAndIds(string $className, ?string $fieldnames, ?string $ids, bool $purge = false): void
protected function regenerateFiltersByFieldnameAndIds(#[\SensitiveParameter] string $className, #[\SensitiveParameter] ?string $fieldnames, ?string $ids, bool $purge = false): void
{
$fieldnamesAr = $fieldnames !== null ? explode(',', $fieldnames) : null;
$idsAr = $ids !== null ? explode(',', $ids) : null;
Expand Down
16 changes: 8 additions & 8 deletions src/Encryptors/CiphersweetEncryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(CipherSweet $engine)
* @throws BlindIndexNameCollisionException
* @throws \SodiumException
*/
public function prepareForStorage(object $entity, string $fieldName, string $string, bool $index = true, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): array
public function prepareForStorage(#[\SensitiveParameter] object $entity, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $string, bool $index = true, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): array
{
$entitClassName = \get_class($entity);

Expand Down Expand Up @@ -74,7 +74,7 @@ public function prepareForStorage(object $entity, string $fieldName, string $str
* @throws BlindIndexNameCollisionException
* @throws \SodiumException
*/
protected function doEncrypt(string $entitClassName, string $fieldName, string $string, bool $index = true, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): array
protected function doEncrypt(#[\SensitiveParameter] string $entitClassName, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $string, bool $index = true, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): array
{
$encryptedField = (new EncryptedField($this->engine, $entitClassName, $fieldName));
if ($index) {
Expand Down Expand Up @@ -103,7 +103,7 @@ protected function doEncrypt(string $entitClassName, string $fieldName, string $
* @throws CipherSweetException
* @throws CryptoOperationException
*/
public function decrypt(string $entityClassName, string $fieldName, string $string, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string
public function decrypt(#[\SensitiveParameter] string $entityClassName, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $string, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string
{
// If $string is not encrypted, we return it as is.
if (!$this->isValueEncrypted($string)) {
Expand All @@ -121,7 +121,7 @@ public function decrypt(string $entityClassName, string $fieldName, string $stri
* @throws CipherSweetException
* @throws CryptoOperationException
*/
protected function doDecrypt(string $entityClassName, string $fieldName, string $string): string
protected function doDecrypt(#[\SensitiveParameter] string $entityClassName, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $string): string
{
$decryptedValue = (new EncryptedField($this->engine, $entityClassName, $fieldName))
->decryptValue($string);
Expand All @@ -141,7 +141,7 @@ protected function doDecrypt(string $entityClassName, string $fieldName, string
* @throws BlindIndexNameCollisionException
* @throws \SodiumException
*/
public function getBlindIndex(string $entityName, string $fieldName, string $value, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string
public function getBlindIndex(#[\SensitiveParameter] string $entityName, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $value, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string
{
if (isset($this->biCache[$entityName][$fieldName][$value])) {
return $this->biCache[$entityName][$fieldName][$value];
Expand All @@ -157,7 +157,7 @@ public function getBlindIndex(string $entityName, string $fieldName, string $val
* @throws BlindIndexNameCollisionException
* @throws \SodiumException
*/
protected function doGetBlindIndex(string $entityName, string $fieldName, string $value, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string
protected function doGetBlindIndex(#[\SensitiveParameter] string $entityName, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $value, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string
{
$index = (new EncryptedField($this->engine, $entityName, $fieldName))
->addBlindIndex(
Expand All @@ -178,9 +178,9 @@ public function getPrefix(): string
return $this->engine->getBackend()->getPrefix();
}

public function isValueEncrypted(?string $value): bool
public function isValueEncrypted(#[\SensitiveParameter] ?string $value): bool
{
return $value !== null && strpos($value, $this->getPrefix()) === 0;
return $value !== null && str_starts_with($value, $this->getPrefix());
}

public function reset(): void
Expand Down
8 changes: 4 additions & 4 deletions src/Encryptors/EncryptorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ public function __construct(CipherSweet $engine);
*
* @return array{0:string, 1: array<string, string>}
*/
public function prepareForStorage(object $entity, string $fieldName, string $string, bool $index = true, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): array;
public function prepareForStorage(#[\SensitiveParameter] object $entity, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $string, bool $index = true, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): array;

/**
* Decrypt a value
*/
public function decrypt(string $entityClassName, string $fieldName, string $string, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string;
public function decrypt(#[\SensitiveParameter] string $entityClassName, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $string, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string;

/**
* Get the blind index of the field
*/
public function getBlindIndex(string $entityName, string $fieldName, string $value, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string;
public function getBlindIndex(#[\SensitiveParameter] string $entityName, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] string $value, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): string;

/**
* Get the prefix of the encryptor
*/
public function getPrefix(): string;

public function isValueEncrypted(?string $value): bool;
public function isValueEncrypted(#[\SensitiveParameter] ?string $value): bool;
}
6 changes: 3 additions & 3 deletions src/Entity/IndexedEntityAttributeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getFieldname(): string
return $this->fieldname;
}

public function setFieldname(string $fieldname): self
public function setFieldname(#[\SensitiveParameter] string $fieldname): self
{
$this->fieldname = $fieldname;
return $this;
Expand All @@ -46,7 +46,7 @@ public function getTargetEntity(): object
return $this->targetEntity;
}

public function setTargetEntity(?object $targetEntity): self
public function setTargetEntity(#[\SensitiveParameter] ?object $targetEntity): self
{
$this->targetEntity = $targetEntity;
return $this;
Expand All @@ -57,7 +57,7 @@ public function getIndexBi(): string
return $this->indexBi;
}

public function setIndexBi(string $indexBi): self
public function setIndexBi(#[\SensitiveParameter] string $indexBi): self
{
$this->indexBi = $indexBi;
return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/IndexedEntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getFieldname(): string
return $this->fieldname;
}

public function setFieldname(string $fieldname): self
public function setFieldname(#[\SensitiveParameter] string $fieldname): self
{
$this->fieldname = $fieldname;
return $this;
Expand All @@ -53,7 +53,7 @@ public function getTargetEntity(): object
return $this->targetEntity;
}

public function setTargetEntity(?object $targetEntity): self
public function setTargetEntity(#[\SensitiveParameter] ?object $targetEntity): self
{
$this->targetEntity = $targetEntity;
return $this;
Expand All @@ -64,7 +64,7 @@ public function getIndexBi(): string
return $this->indexBi;
}

public function setIndexBi(string $indexBi): self
public function setIndexBi(#[\SensitiveParameter] string $indexBi): self
{
$this->indexBi = $indexBi;
return $this;
Expand Down
10 changes: 5 additions & 5 deletions src/Services/IndexableFieldsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(?Reader $annReader, EntityManagerInterface $em, Inde
/**
* Chunks all data ID of the entity
*/
public function getChunksForMultiThread(string $className, int $chuncksLength): array
public function getChunksForMultiThread(#[\SensitiveParameter] string $className, int $chuncksLength): array
{
$repo = $this->em->getRepository($className);
$result = $repo->createQueryBuilder('c')
Expand All @@ -51,7 +51,7 @@ public function getChunksForMultiThread(string $className, int $chuncksLength):
*
* @throws MissingPropertyFromReflectionException
*/
public function buildContext(string $className, ?array $fieldNames): array
public function buildContext(#[\SensitiveParameter] string $className, #[\SensitiveParameter] ?array $fieldNames): array
{
$contexts = [];

Expand Down Expand Up @@ -125,7 +125,7 @@ public function purgeFiltersForContextAndIds(array $fieldsContexts, ?array $ids)
* @param null|array<int, string> $ids
* @param array<int, array{refProperty: \ReflectionProperty, indexableConfig: IndexableField}> $fieldsContexts
*/
public function handleFilterableFieldsForChunck(string $className, ?array $ids, array $fieldsContexts, bool $runtimeMode = false): void
public function handleFilterableFieldsForChunck(#[\SensitiveParameter] string $className, ?array $ids, array $fieldsContexts, bool $runtimeMode = false): void
{
$chunck = $this->em->getRepository($className)->findBy(!empty($ids) ? ['id' => $ids] : []);
foreach ($chunck as $entity) {
Expand All @@ -141,7 +141,7 @@ public function handleFilterableFieldsForChunck(string $className, ?array $ids,
*
* @throws UndefinedGeneratorException|\ReflectionException
*/
public function handleIndexableFieldsForEntity(object $entity, array $fieldsContexts, bool $runtimeMode = false): void
public function handleIndexableFieldsForEntity(#[\SensitiveParameter] object $entity, array $fieldsContexts, bool $runtimeMode = false): void
{
$className = get_class($entity);
$searchIndexes = $this->generateIndexableValuesForEntity($entity, $fieldsContexts);
Expand Down Expand Up @@ -198,7 +198,7 @@ public function handleIndexableFieldsForEntity(object $entity, array $fieldsCont
*
* @throws UndefinedGeneratorException
*/
public function generateIndexableValuesForEntity(object $entity, array $fieldsContexts): array
public function generateIndexableValuesForEntity(#[\SensitiveParameter] object $entity, array $fieldsContexts): array
{
$searchIndexes = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Services/IndexesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(ServiceLocator $container, EncryptorInterface $encry
*
* @throws UndefinedGeneratorException
*/
public function generateAndEncryptFilters(string $value, array $methods): array
public function generateAndEncryptFilters(#[\SensitiveParameter] string $value, array $methods): array
{
$possibleValuesAr = [$value];

Expand Down Expand Up @@ -59,7 +59,7 @@ public function generateAndEncryptFilters(string $value, array $methods): array
*
* @return array<int, string>
*/
public function generateBlindIndexesFromPossibleValues(string $entityName, string $fieldName, array $possibleValues, bool $fastIndexing): array
public function generateBlindIndexesFromPossibleValues(#[\SensitiveParameter] string $entityName, #[\SensitiveParameter] string $fieldName, #[\SensitiveParameter] array $possibleValues, bool $fastIndexing): array
{
$possibleValues = array_unique($possibleValues);

Expand Down
4 changes: 2 additions & 2 deletions src/Services/PropertyHydratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(PropertyInfoExtractorInterface $propertyInfoExtracto
/**
* @param mixed $value
*/
public function getMappedFieldValueAsString(object $entity, ?string $propertyName, $value): string
public function getMappedFieldValueAsString(#[\SensitiveParameter] object $entity, #[\SensitiveParameter] ?string $propertyName, #[\SensitiveParameter] $value): string
{
if ($propertyName !== null) {
$value = $this->propertyAccessor->getValue($entity, $propertyName);
Expand All @@ -34,7 +34,7 @@ public function getMappedFieldValueAsString(object $entity, ?string $propertyNam
return (string) $value;
}

public function setValueToMappedField(object $entity, string $value, ?string $propertyName): void
public function setValueToMappedField(#[\SensitiveParameter] object $entity, #[\SensitiveParameter] string $value, #[\SensitiveParameter] ?string $propertyName): void
{
if ($propertyName === null) {
return;
Expand Down
Loading

0 comments on commit cfd24ed

Please sign in to comment.