function __construct() { for ($i = 0; $i < mt_rand(32, 48); $i++) { $this->sample['api']['unique_id'] .= chr(mt_rand(97, 122)); } $this->sample['api']['signature'] = hash('sha1', $this->sample['api']['unique_id'] . \Genesis\Config::getPassword()); for ($i = 0; $i < mt_rand(32, 48); $i++) { $this->sample['wpf']['wpf_unique_id'] .= chr(mt_rand(97, 122)); } $this->sample['wpf']['signature'] = hash('sha1', $this->sample['wpf']['wpf_unique_id'] . \Genesis\Config::getPassword()); }
function send_remote_connection($remote_url) { $faker = \Faker\Factory::create(); $faker->addProvider(new \Faker\Provider\UserAgent($faker)); $options = array('body' => '', 'type' => 'GET', 'url' => $remote_url, 'timeout' => Config::getNetworkTimeout(), 'ca_bundle' => Config::getCertificateBundle(), 'user_login' => Config::getUsername() . ':' . Config::getPassword(), 'user_agent' => $faker->userAgent); $this->prepareRequestBody($options); $this->shouldNotThrow()->during('execute'); $this->getResponseBody()->shouldNotBeEmpty(); // Check only the gate for time as its the only endpoint that provides server-time if (strpos($remote_url, 'gate.')) { $this->getResponseBody()->shouldNotBeOlder(); } $this->getStatus()->shouldBe(200); }
/** * Verify the signature on the parsed Notification * * @return bool * @throws \Genesis\Exceptions\InvalidArgument */ public function isAuthentic() { if (!isset($this->unique_id) || !isset($this->notificationObj->signature)) { throw new \Genesis\Exceptions\InvalidArgument('Missing field(s), required for validation!'); } $messageSig = trim($this->notificationObj->signature); $customerPwd = trim(\Genesis\Config::getPassword()); switch (strlen($messageSig)) { default: case 40: $hashType = 'sha1'; break; case 128: $hashType = 'sha512'; break; } if ($messageSig === hash($hashType, $this->unique_id . $customerPwd)) { return true; } return false; }
/** * Set Header/Body of the HTTP request * * @param \Genesis\API\Request $apiContext */ public function setApiCtxData($apiContext) { $this->context->prepareRequestBody(array('body' => $apiContext->getDocument(), 'url' => $apiContext->getApiConfig('url'), 'type' => $apiContext->getApiConfig('type'), 'port' => $apiContext->getApiConfig('port'), 'protocol' => $apiContext->getApiConfig('protocol'), 'timeout' => \Genesis\Config::getNetworkTimeout(), 'ca_bundle' => \Genesis\Config::getCertificateBundle(), 'user_agent' => sprintf('Genesis PHP Client v%s', \Genesis\Config::getVersion()), 'user_login' => sprintf('%s:%s', \Genesis\Config::getUsername(), \Genesis\Config::getPassword()))); }