Skip to content

Commit

Permalink
Supported SSL verification toggle.
Browse files Browse the repository at this point in the history
  • Loading branch information
raja-7453 committed Jan 6, 2021
1 parent ebb6b45 commit f340c14
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,27 @@ Before you get started with creating your PHP application, you need to register
```php
/*
* autoRefreshFields
* autoRefreshFields (default value is false)
* true - all the modules' fields will be auto-refreshed in the background, every hour.
* false - the fields will not be auto-refreshed in the background. The user can manually delete the file(s) or refresh the fields using methods from ModuleFieldsHandler(com\zoho\crm\api\util\ModuleFieldsHandler)
*
* pickListValidation
* pickListValidation (default value is true)
* A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list.
* true - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
* false - the SDK does not validate the input and makes the API request with the user’s input to the pick list
*
* enableSSLVerification (default value is true)
* A boolean field to enable or disable curl certificate verification
* true - the SDK verifies the authenticity of certificate
* false - the SDK skips the verification
*/
$autoRefreshFields = false;
$pickListValidation = false;
$sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->build();
$enableSSLVerification = true;
$sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->setSSLVerification($enableSSLVerification)->build();
```
- Create an instance of RequestProxy containing the proxy properties of the user.
Expand Down
5 changes: 5 additions & 0 deletions src/com/zoho/api/authenticator/OAuthToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ public function getResponseFromServer($request_params)

curl_setopt($curl_pointer, CURLOPT_CUSTOMREQUEST, Constants::REQUEST_METHOD_POST);

if(!Initializer::getInitializer()->getSDKConfig()->isSSLVerificationEnabled())
{
curl_setopt($curl_pointer, CURLOPT_SSL_VERIFYPEER, false);
}

$result = curl_exec($curl_pointer);

curl_close($curl_pointer);
Expand Down
35 changes: 32 additions & 3 deletions src/com/zoho/crm/api/SDKConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ class SDKConfigBuilder

private $pickListValidation;

private $enableSSLVerification;

public function __Construct()
{
$this->autoRefreshFields = false;

$this->pickListValidation = true;

$this->enableSSLVerification = true;
}

/**
* This is a setter method to set autoRefreshFields.
* @param autoRefreshFields
* @param autoRefreshFields
*/
public function setAutoRefreshFields(bool $autoRefreshFields)
{
Expand All @@ -39,13 +43,24 @@ public function setPickListValidation(bool $pickListValidation)
return $this;
}

/**
* This is a setter method to set enableSSLVerification.
* @param enableSSLVerification
*/
public function setSSLVerification(bool $enableSSLVerification)
{
$this->enableSSLVerification = $enableSSLVerification;

return $this;
}

/**
* The method to build the SDKConfig instance
* @returns An instance of SDKConfig
*/
public function build()
{
return new \com\zoho\crm\api\sdkconfigbuilder\SDKConfig($this->autoRefreshFields, $this->pickListValidation);
return new \com\zoho\crm\api\sdkconfigbuilder\SDKConfig($this->autoRefreshFields, $this->pickListValidation, $this->enableSSLVerification);
}
}

Expand All @@ -60,16 +75,21 @@ class SDKConfig

private $pickListValidation;

private $enableSSLVerification;

/**
* Creates an instance of SDKConfig with the given parameters
* @param autoRefreshFields - A boolean representing autoRefreshFields
* @param pickListValidation - A boolean representing pickListValidation
* @param enableSSLVerification - A boolean representing enableSSLVerification
*/
public function __Construct(bool $autoRefreshFields, bool $pickListValidation)
public function __Construct(bool $autoRefreshFields, bool $pickListValidation, bool $enableSSLVerification)
{
$this->autoRefreshFields = $autoRefreshFields;

$this->pickListValidation = $pickListValidation;

$this->enableSSLVerification = $enableSSLVerification;
}

/**
Expand All @@ -89,5 +109,14 @@ public function getPickListValidation()
{
return $this->pickListValidation;
}

/**
* This is a getter method to get enableSSLVerification.
* @return A boolean representing enableSSLVerification
*/
public function isSSLVerificationEnabled()
{
return $this->enableSSLVerification;
}
}
?>
11 changes: 8 additions & 3 deletions src/com/zoho/crm/api/util/APIHTTPConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,21 @@ public function fireRequest($converterInstance)
}

$this->setQueryHeaders($curl_options);


if(!Initializer::getInitializer()->getSDKConfig()->isSSLVerificationEnabled())
{
$curl_options[CURLOPT_SSL_VERIFYPEER] = false;
}

curl_setopt_array($curl_pointer, $curl_options);

SDKLogger::info($this->toString());

$response = array();

$response[Constants::RESPONSE] = curl_exec($curl_pointer);

if (curl_errno($curl_pointer))
if (curl_errno($curl_pointer))
{
$response[Constants::ERROR] = curl_error($curl_pointer);
}
Expand Down
17 changes: 11 additions & 6 deletions src/com/zoho/crm/api/util/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,19 @@ public function getResponse($response, $pack)
$responseHeaders = $response[Constants::HEADERS];

$responseContent = $response[Constants::CONTENT];
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION];
if ($contentDisposition == null)

$contentDisposition = "";

if(array_key_exists(Constants::CONTENT_DISPOSITION, $responseHeaders))
{
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION1];
}
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION];

if ($contentDisposition == null)
{
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION1];
}
}

$fileName = substr($contentDisposition, strrpos($contentDisposition, "'") + 1, strlen($contentDisposition));

if (strpos($fileName, "=") !== false)
Expand Down

0 comments on commit f340c14

Please sign in to comment.