public function testVerifyMd5Hash_inifile()
 {
     $prefix = null;
     $sharedKey = "zaqxswcdevfrbgtnhymjukiloZAQCDEFRBGTNHYMJUKILOPlkjhgfdsapoiuytrewqmnbvcx";
     $expectedPlaceInqueue = 7810;
     $expectedQueueId = "fe070f51-5548-403c-9f0a-2626c15cb81b";
     $placeInQueueEncrypted = "3d20e598-0304-474f-87e8-371a34073d3b";
     $unixTimestamp = 1360241766;
     $expectedTimeStamp = new \DateTime("2013-02-07 12:56:06", new \DateTimeZone("UTC"));
     $expectedCustomerId = "somecust";
     $expectedEventId = "someevent";
     $expectedOriginalUrl = "http://www.example.com/test.aspx?prop=value";
     $urlNoHash = $expectedOriginalUrl . "?" . $prefix . "c=somecust&" . $prefix . "e=someevent&" . $prefix . "q=" . $expectedQueueId . "&" . $prefix . "p=" . $placeInQueueEncrypted . "&" . $prefix . "ts=" . $unixTimestamp . "&" . $prefix . "h=";
     $expectedHash = md5(utf8_encode($urlNoHash . $sharedKey));
     $url = $urlNoHash . $expectedHash;
     $urlProvider = new MockUrlProvider($url, $expectedOriginalUrl, $expectedQueueId, $placeInQueueEncrypted, (string) $unixTimestamp, $expectedCustomerId, $expectedEventId);
     KnownUserFactory::reset(true);
     $knownUser = KnownUserFactory::verifyMd5Hash($sharedKey, $urlProvider, null);
     $this->assertNotNull($knownUser);
     $this->assertEquals($expectedQueueId, $knownUser->getQueueId());
     $this->assertEquals($expectedPlaceInqueue, $knownUser->getPlaceInQueue());
     $this->assertEquals($expectedTimeStamp, $knownUser->getTimeStamp());
     $this->assertEquals($expectedCustomerId, $knownUser->getCustomerId());
     $this->assertEquals($expectedEventId, $knownUser->getEventId());
     $this->assertEquals($expectedOriginalUrl, $knownUser->getOriginalUrl());
 }
Beispiel #2
0
        $encryptedPlaceInQueue[26] = $paddedPlaceInQueue[5];
        $encryptedPlaceInQueue[7] = $paddedPlaceInQueue[4];
        $encryptedPlaceInQueue[20] = $paddedPlaceInQueue[3];
        $encryptedPlaceInQueue[11] = $paddedPlaceInQueue[2];
        $encryptedPlaceInQueue[3] = $paddedPlaceInQueue[1];
        $encryptedPlaceInQueue[30] = $paddedPlaceInQueue[0];
        return $encryptedPlaceInQueue;
    }
    /**
     * Verify URL
     *
     * @param string $url
     * @param [type] $sharedEventKey
     *
     * @throws Opifer\QueueIt\Exception\InvalidKnownUserHashException when hash could not be verified
     *
     * @return void
     */
    private static function verifyUrl($url, $sharedEventKey)
    {
        $expectedHash = substr($url, -32);
        $urlNoHash = substr($url, 0, -32) . $sharedEventKey;
        //Remove hash value and add SharedEventKey
        $actualhash = md5(utf8_encode($urlNoHash));
        if (strcmp($actualhash, $expectedHash) != 0) {
            throw new InvalidKnownUserHashException('The hash of the request is invalid');
        }
    }
}
KnownUserFactory::reset(true);