Checking package hash can only be done when the message has been decoded and decompre...
authorRoland Haeder <roland@mxchange.org>
Mon, 11 May 2015 23:36:32 +0000 (01:36 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 11 May 2015 23:36:32 +0000 (01:36 +0200)
Signed-off-by: Roland Haeder <roland@mxchange.org>
application/hub/main/package/class_NetworkPackage.php

index fe3ebe81e46f4fa58f34585e7e92027ba670f6e1..82b413315841d79c24ffe87a634d16f8841aaec9 100644 (file)
@@ -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]);