), $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
*
*/
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;
*/
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));