/**
* Determines private key hash from given session id
*
- * @param $sessionId Session id
- * @return $hash Private key's hash
+ * @param $decodedData Array with decoded data
+ * @return $hash Private key's hash
*/
- private function determineSenderPrivateKeyHash ($sessionId) {
+ private function determineSenderPrivateKeyHash (array $decodedData) {
// Get DHT instance
$dhtInstance = DhtObjectFactory::createDhtInstance('node');
// Ask DHT for session id
- $senderData = $dhtInstance->findNodeLocalBySessionId($sessionId);
+ $senderData = $dhtInstance->findNodeLocalBySessionId($decodedData[self::]);
// Is an entry found?
if (count($senderData) > 0) {
// Return it
return $senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH];
} // END - if
+
+ // Make sure the requested element is there
+ assert(isset($decodedData[self::INDEX_PACKAGE_HASH]));
+
+ // There is no DHT entry so, accept the hash from decoded data
+ return $decodedData[self::INDEX_PACKAGE_HASH];
}
/**
* @return $hash Hash as hex-encoded string
*/
private function generatePackageHash ($content, $senderId) {
+ // Fake array
+ $data = array(
+ self::INDEX_PACKAGE_SENDER => $senderId,
+ self::INDEX_PACKAGE_CONTENT => $content,
+ self::INDEX_PACKAGE_HASH => ''
+ );
+
// Hash content and sender id together, use scrypt
- $hash = Scrypt::hashScrypt($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($senderId));
+ $hash = Scrypt::hashScrypt($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data));
// 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->determineSenderPrivateKeyHash($decodedArray[self::INDEX_PACKAGE_SENDER]), $decodedArray[self::INDEX_PACKAGE_HASH]);
+ $isHashValid = Scrypt::checkScrypt($decodedArray[self::INDEX_PACKAGE_SENDER] . ':' . $decodedArray[self::INDEX_PACKAGE_CONTENT] . ':' . $this->determineSenderPrivateKeyHash($decodedArray);
// Return it
//* DEBUG-DIE: */ die(__METHOD__ . ': isHashValid=' . intval($isHashValid) . chr(10) . ',decodedArray=' . print_r($decodedArray, TRUE));