_getCertificateFromCertifcatePath($certificatePath); $certKey = openssl_get_publickey($cert); if ($certKey === False) { throw new OffAmazonPaymentsNotifications_InvalidMessageException( "Unable to extract public key from cert " . $cert); } $result = -1; try { $result = openssl_verify($data, $signature, $certKey, OPENSSL_ALGO_SHA1); } catch (Exception $ex) { throw new OffAmazonPaymentsNotifications_InvalidMessageException( "Unable to verify signature - error with the verification algorithm", null, $ex ); } return ($result > 0); } /** * Request the signing certificate from the given path, in order to * get the public key * * @param string $certificatePath certificate path to retreive * * @throws OffAmazonPaymentsNotifications_InvalidMessageException * * @return void */ private function _getCertificateFromCertifcatePath($certificatePath) { try { $cert = file_get_contents($certificatePath); } catch (Exception $ex) { throw new OffAmazonPaymentsNotifications_InvalidMessageException( "Error with signature validation - unable to request signing ". "certificate at " . $certificatePath, null, $ex ); } if ($cert === false) { throw new OffAmazonPaymentsNotifications_InvalidMessageException( "Error with signature validation - unable to request signing ". "certificate at " . $certificatePath ); } return $cert; } } ?>