]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/package/class_NetworkPackage.php
Get the private key hash from sender's session id and not the local node's hash.
[hub.git] / application / hub / main / package / class_NetworkPackage.php
index 75df73577e979f9c17b16a1ba03be8ac571b3697..7fb24f62eb9eb04f3a6490f1260a0af4dcf4b81e 100644 (file)
@@ -335,6 +335,27 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                ), $forceReInit);
        }
 
+       /**
+        * Determines private key hash from given session id
+        *
+        * @param       $sessionId      Session id
+        * @return      $hash           Private key's hash
+        */
+       private function determineSenderPrivateKeyHash ($sessionId) {
+               // Get DHT instance
+               $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+               // Ask DHT for session id
+               $senderData = $dhtInstance->findNodeLocalBySessionId($sessionId);
+
+               // Make sure the element 'private_key_hash' is there
+               assert(isset($senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH]));
+
+               // Return it
+               //* DEBUG-DIE */ die('senderData=' . print_r($senderData, TRUE));
+               return $senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH];
+       }
+
        /**
         * "Getter" for hash from given content
         *
@@ -620,7 +641,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        private function generatePackageHash ($content, $senderId) {
                // Hash content and sender id together, use scrypt
-               $hash = Scrypt::hashScrypt($senderId . ':' . $content . ':' . $this->getPrivateKeyHash());
+               $hash = Scrypt::hashScrypt($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($senderId));
 
                // Return it
                return $hash;
@@ -636,7 +657,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        private function isPackageHashValid (array $decodedArray) {
                // Check validity
-               $isHashValid = Scrypt::checkScrypt($decodedArray[self::INDEX_PACKAGE_SENDER] . ':' . $decodedArray[self::INDEX_PACKAGE_CONTENT] . ':' . $this->getPrivateKeyHash(), $decodedArray[self::INDEX_PACKAGE_HASH]);
+               $isHashValid = Scrypt::checkScrypt($decodedArray[self::INDEX_PACKAGE_SENDER] . ':' . $decodedArray[self::INDEX_PACKAGE_CONTENT] . ':' . $this->determineSenderPrivateKeyHash($decodedArray[self::INDEX_PACKAGE_SENDER]), $decodedArray[self::INDEX_PACKAGE_HASH]);
 
                // Return it
                //* DEBUG-DIE: */ die(__METHOD__ . ': isHashValid=' . intval($isHashValid) . chr(10) . ',decodedArray=' . print_r($decodedArray, TRUE));