From: Roland Haeder Date: Mon, 11 May 2015 22:47:16 +0000 (+0200) Subject: Get the private key hash from sender's session id and not the local node's hash. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=edca8d501ce1f3740100efcfc6c87bc34d316fe8;p=hub.git Get the private key hash from sender's session id and not the local node's hash. Signed-off-by: Roland Haeder --- diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 75df73577..7fb24f62e 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -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));