From: Roland Haeder Date: Mon, 11 May 2015 23:36:32 +0000 (+0200) Subject: Checking package hash can only be done when the message has been decoded and decompre... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b0201686764e9c02c2f55c7f1fee888abb9a7fdf;p=hub.git Checking package hash can only be done when the message has been decoded and decompressed. Signed-off-by: Roland Haeder --- diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index fe3ebe81e..82b413315 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -346,7 +346,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $dhtInstance = DhtObjectFactory::createDhtInstance('node'); // Ask DHT for session id - $senderData = $dhtInstance->findNodeLocalBySessionId($decodedData[self::INDEX_PACKAGE_SENDER]); + $senderData = $dhtInstance->findNodeLocalBySessionId($decodedData[self::PACKAGE_CONTENT_SENDER]); // Is an entry found? if (count($senderData) > 0) { @@ -361,10 +361,10 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Make sure the requested element is there // @TODO Wrong hash!!!! /* DEBUG-DIE */ die('decodedData=' . print_r($decodedData, TRUE)); - assert(isset($decodedData[self::INDEX_PACKAGE_HASH])); + assert(isset($decodedData[self::PACKAGE_CONTENT_HASH])); // There is no DHT entry so, accept the hash from decoded data - return $decodedData[self::INDEX_PACKAGE_HASH]; + return $decodedData[self::PACKAGE_CONTENT_HASH]; } /** @@ -676,7 +676,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R private function isPackageHashValid (array $decodedArray) { // Check validity //* DEBUG-DIE: */ die(__METHOD__ . ': decodedArray=' . print_r($decodedArray, TRUE)); - $isHashValid = Scrypt::checkScrypt($decodedArray[self::INDEX_PACKAGE_SENDER] . ':' . $decodedArray[self::INDEX_PACKAGE_CONTENT] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::INDEX_PACKAGE_HASH]); + $isHashValid = Scrypt::checkScrypt($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_CONTENT] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH]); // Return it //* DEBUG-DIE: */ die(__METHOD__ . ': isHashValid=' . intval($isHashValid) . ',decodedArray=' . print_r($decodedArray, TRUE)); @@ -1237,12 +1237,6 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Assert on count (should be always 3) assert(count($decodedArray) == self::DECODED_DATA_ARRAY_SIZE); - // Generate the hash of comparing it - if (!$this->isPackageHashValid($decodedArray)) { - // Is not valid, so throw an exception here - exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . chr(10)); - } // END - if - /* * Create 'decodedData' array with all assoziative array elements. */ @@ -1335,6 +1329,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Get it from the stacker, it is the full array with the decoded message $decodedContent = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE); + // Generate the hash of comparing it + if (!$this->isPackageHashValid($decodedContent)) { + // Is not valid, so throw an exception here + exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . chr(10)); + } // END - if + // Now get a filter chain back from factory with given tags array $chainInstance = PackageFilterChainFactory::createChainByTagsArray($decodedContent[self::PACKAGE_CONTENT_TAGS]);