Made message signing in Cryptography use SHA512 as the message content for... #1

Closed
netkas wants to merge 421 commits from master into dev
3 changed files with 27 additions and 34 deletions
Showing only changes of commit 7ac1bead49 - Show all commits

View file

@ -360,14 +360,14 @@
} }
} }
// Handle Mock Servers environment variables (SB_INSTANCE_MOCK_SERVER_*) // Handle Mock Servers environment variables (SB_INSTANCE_DNS_MOCK_*)
$mockServers = []; $mockServers = [];
foreach(self::getMockServerValues() as $mockServer) foreach(self::getMockServerValues() as $mockServer)
{ {
$mockServer = explode(' ', $mockServer); $mockServer = explode(' ', $mockServer);
if(count($mockServer) !== 2) if(count($mockServer) !== 2)
{ {
Logger::getLogger()->warning(sprintf('Invalid Mock Server format: %s', implode(' ', $mockServer))); Logger::getLogger()->warning(sprintf('Invalid DNS Mock Server format: %s', implode(' ', $mockServer)));
continue; continue;
} }
@ -399,7 +399,7 @@
} }
/** /**
* Retrieves all environment variable values that start with the prefix 'SB_INSTANCE_MOCK_SERVER_'. * Retrieves all environment variable values that start with the prefix 'SB_INSTANCE_DNS_MOCK_'.
* *
* @return array An array of environment variable values filtered by the specified prefix. * @return array An array of environment variable values filtered by the specified prefix.
*/ */
@ -411,7 +411,7 @@
// Filter variables that start with the specified prefix // Filter variables that start with the specified prefix
$filtered = array_filter($envVars, function ($key) $filtered = array_filter($envVars, function ($key)
{ {
return str_starts_with($key, 'SB_INSTANCE_MOCK_SERVER_'); return str_starts_with($key, 'SB_INSTANCE_DNS_MOCK_');
}, ARRAY_FILTER_USE_KEY); }, ARRAY_FILTER_USE_KEY);
// Return only the values as an array // Return only the values as an array
@ -453,7 +453,7 @@
" SB_CACHE_USERNAME - The cache username (default: null)\n" . " SB_CACHE_USERNAME - The cache username (default: null)\n" .
" SB_CACHE_PASSWORD - The cache password (default: null)\n" . " SB_CACHE_PASSWORD - The cache password (default: null)\n" .
" SB_CACHE_DATABASE - The cache database (default: 0)\n" . " SB_CACHE_DATABASE - The cache database (default: 0)\n" .
" SB_INSTANCE_MOCK_SERVER_* - Mock server environment variables, format: (<domain> <txt>), eg; SB_INSTANCE_MOCK_SERVER_N64: teapot.com <txt>\n"; " SB_INSTANCE_DNS_MOCK_* - Mock server environment variables, format: (<domain> <txt>), eg; SB_INSTANCE_DNS_MOCK_N64: teapot.com <txt>\n";
} }
/** /**

View file

@ -8,6 +8,7 @@
private string $name; private string $name;
private ?string $domain; private ?string $domain;
private ?string $rpcEndpoint; private ?string $rpcEndpoint;
private array $dnsMocks;
/** /**
* Constructor that initializes object properties with the provided data. * Constructor that initializes object properties with the provided data.
@ -21,6 +22,7 @@
$this->name = $data['name']; $this->name = $data['name'];
$this->domain = $data['domain']; $this->domain = $data['domain'];
$this->rpcEndpoint = $data['rpc_endpoint']; $this->rpcEndpoint = $data['rpc_endpoint'];
$this->dnsMocks = $data['dns_mocks'];
} }
/** /**
@ -55,4 +57,12 @@
{ {
return $this->rpcEndpoint; return $this->rpcEndpoint;
} }
/**
* @return array
*/
public function getDnsMocks(): array
{
return $this->dnsMocks;
}
} }

View file

@ -10,7 +10,6 @@
class ServerResolver class ServerResolver
{ {
private static bool $mockingEnabled = false;
private static array $mockedRecords = []; private static array $mockedRecords = [];
/** /**
@ -25,18 +24,23 @@
*/ */
public static function resolveDomain(string $domain, bool $useDatabase=true): DnsRecord public static function resolveDomain(string $domain, bool $useDatabase=true): DnsRecord
{ {
// Return the mocked record if mocking is enabled // Return the mocked record if the mocking record is set
if(self::$mockingEnabled) if(isset(self::$mockedRecords[$domain]))
{ {
if(isset(self::$mockedRecords[$domain])) return self::$mockedRecords[$domain];
{ }
return self::$mockedRecords[$domain];
} // Return the mocked record from the configuration if one is set
if(isset(Configuration::getInstanceConfiguration()->getDnsMocks()[$domain]))
{
return DnsHelper::parseTxt(Configuration::getInstanceConfiguration()->getDnsMocks()[$domain]);
} }
// Check the database if enabled // Check the database if enabled
if ($useDatabase) if ($useDatabase)
{ {
// Return from the database cache if one exists
// TODO: Implement renewal here
$resolvedServer = ResolvedDnsRecordsManager::getDnsRecord($domain); $resolvedServer = ResolvedDnsRecordsManager::getDnsRecord($domain);
if ($resolvedServer !== null) if ($resolvedServer !== null)
{ {
@ -44,12 +48,12 @@
} }
} }
// Resolve DNS & Records
$txtRecords = self::dnsGetTxtRecords($domain); $txtRecords = self::dnsGetTxtRecords($domain);
if ($txtRecords === false) if ($txtRecords === false)
{ {
throw new ResolutionException(sprintf("Failed to resolve DNS TXT records for %s", $domain)); throw new ResolutionException(sprintf("Failed to resolve DNS TXT records for %s", $domain));
} }
$fullRecord = self::concatenateTxtRecords($txtRecords); $fullRecord = self::concatenateTxtRecords($txtRecords);
try try
@ -106,27 +110,6 @@
return $fullRecordBuilder; return $fullRecordBuilder;
} }
/**
* Determines if mocking is enabled.
*
* @return bool True if mocking is enabled, false otherwise.
*/
public static function isMockingEnabled(): bool
{
return self::$mockingEnabled;
}
/**
* Enables or disables mocking functionality.
*
* @param bool $enabled Indicates whether mocking should be enabled (true) or disabled (false).
* @return void
*/
public static function setMockingEnabled(bool $enabled): void
{
self::$mockingEnabled = $enabled;
}
/** /**
* Retrieves the mocked records. * Retrieves the mocked records.
* *