/**
  * method to calculate fingerprint from given fields.
  *
  * @return string - fingerprint hash
  */
 protected function _calculateFingerprint()
 {
     $oFingerprintOrder = $this->_fingerprintOrder;
     if ($this->_fingerprintOrderType == self::$FINGERPRINT_TYPE_DYNAMIC) {
         // we have to add REQUESTFINGERPRINTORDER to local fingerprintOrder to add correct value to param list
         $oFingerprintOrder[] = self::REQUEST_FINGERPRINT_ORDER;
         $this->_requestData[self::REQUEST_FINGERPRINT_ORDER] = (string) $oFingerprintOrder;
     }
     // fingerprintFields == requestFields + secret - secret MUST NOT be send as param
     $fingerprintFields = $this->_requestData;
     $fingerprintFields[self::SECRET] = $this->_secret;
     return WirecardCEE_Stdlib_Fingerprint::generate($fingerprintFields, $oFingerprintOrder);
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     ini_set('magic_quotes_gpc', 0);
     WirecardCEE_Stdlib_Fingerprint::setHashAlgorithm(WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_MD5);
     $this->object = new WirecardCEE_QPay_Return_Success($this->_returnData, $this->_secret);
 }
 /**
  * Sets the hash algorithm
  *
  * @param string $hashAlgorithm
  */
 public static function setHashAlgorithm($sHashAlgorithm)
 {
     self::$_HASH_ALGORITHM = (string) $sHashAlgorithm;
 }
Esempio n. 4
0
 /**
  * Is validator check valid?
  * @see Zend_Validate_Interface::isValid()
  */
 public function isValid($value, $context = null)
 {
     $context = array_change_key_case($context, CASE_LOWER);
     switch ($this->hashAlgorithm) {
         case WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_HMAC_SHA512:
         case WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_SHA512:
             $stringLength = 128;
             break;
         case WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_MD5:
             $stringLength = 32;
             break;
         default:
             throw new WirecardCEE_Stdlib_Exception_UnexpectedValueException(sprintf("Used hash algorithm '%s' is not supported. MD5, SHA512, or HMAC_SHA512 are currently supported.", $this->hashAlgorithm));
             break;
     }
     if (strlen($value) != $stringLength) {
         return false;
     }
     if ($this->fingerprintOrderType == self::TYPE_FIXED) {
         $fingerprintOrder = $this->fingerprintOrder;
     } else {
         if (array_key_exists($this->fingerprintOrderField, $context)) {
             $fingerprintOrder = new WirecardCEE_Stdlib_FingerprintOrder(strtolower($context[$this->fingerprintOrderField]));
         } else {
             $this->_error(self::FINGERPRINTORDER_MISSING);
             return false;
         }
     }
     $fingerprintOrder->setOrder(array_map('strtolower', $this->fingerprintOrder->__toArray()));
     $fingerprintFields = array();
     foreach ($fingerprintOrder as $fingerprintFieldKey) {
         if ($fingerprintFieldKey == 'secret') {
             $fingerprintFields[$fingerprintFieldKey] = $this->secret;
         } else {
             $fingerprintFields[$fingerprintFieldKey] = isset($context[$fingerprintFieldKey]) ? $context[$fingerprintFieldKey] : '';
         }
     }
     if (!WirecardCEE_Stdlib_Fingerprint::compare($fingerprintFields, $fingerprintOrder, $value)) {
         $this->_error(self::INVALID);
         return false;
     }
     return true;
 }
 /**
  * @dataProvider fingerprintProvider
  */
 public function testFalseCompare($values, $fingerprintOrder, $hash)
 {
     $hash = md5($hash);
     $this->assertFalse(WirecardCEE_Stdlib_Fingerprint::compare($values, new WirecardCEE_Stdlib_FingerprintOrder($fingerprintOrder), $hash));
 }
 /**
  * Constructor
  *
  * @param mixed $aConfig
  *
  * @throws WirecardCEE_QPay_Exception_InvalidParamLengthException
  * @throws WirecardCEE_QPay_Exception_InvalidArgumentException
  * @formatter:off
  */
 public function __construct($aConfig = null)
 {
     $this->_fingerprintOrder = new WirecardCEE_Stdlib_FingerprintOrder();
     //if no config was sent fallback to default config file
     if (is_null($aConfig)) {
         $aConfig = WirecardCEE_QPay_Module::getConfig();
     }
     if (isset($aConfig['WirecardCEEQPayConfig'])) {
         //we only need the WirecardCEEQPayConfig here
         $aConfig = $aConfig['WirecardCEEQPayConfig'];
     }
     //let's store configuration details in internal objects
     $this->oUserConfig = new WirecardCEE_Stdlib_Config($aConfig);
     $this->oClientConfig = new WirecardCEE_Stdlib_Config(WirecardCEE_QPay_Module::getClientConfig());
     //now let's check if the CUSTOMER_ID, SHOP_ID, LANGUAGE and SECRET exist in $this->oUserConfig object that we created from config array
     $sCustomerId = isset($this->oUserConfig->CUSTOMER_ID) ? trim($this->oUserConfig->CUSTOMER_ID) : null;
     $sShopId = isset($this->oUserConfig->SHOP_ID) ? trim($this->oUserConfig->SHOP_ID) : null;
     $sLanguage = isset($this->oUserConfig->LANGUAGE) ? trim($this->oUserConfig->LANGUAGE) : null;
     $sSecret = isset($this->oUserConfig->SECRET) ? trim($this->oUserConfig->SECRET) : null;
     //If not throw the InvalidArgumentException exception!
     if (empty($sCustomerId) || is_null($sCustomerId)) {
         throw new WirecardCEE_QPay_Exception_InvalidArgumentException(sprintf('CUSTOMER_ID passed to %s is invalid.', __METHOD__));
     }
     if (empty($sLanguage) || is_null($sLanguage)) {
         throw new WirecardCEE_QPay_Exception_InvalidArgumentException(sprintf('LANGUAGE passed to %s is invalid.', __METHOD__));
     }
     if (empty($sSecret) || is_null($sSecret)) {
         throw new WirecardCEE_QPay_Exception_InvalidArgumentException(sprintf('SECRET passed to %s is invalid.', __METHOD__));
     }
     // we're using hmac sha512 for hash-ing
     WirecardCEE_Stdlib_Fingerprint::setHashAlgorithm(WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_HMAC_SHA512);
     //everything ok! let's set the fields
     $this->_setField(self::CUSTOMER_ID, $sCustomerId);
     $this->_setField(self::SHOP_ID, $sShopId);
     $this->_setField(self::LANGUAGE, $sLanguage);
     $this->_setSecret($sSecret);
 }