Skip to content

Commit f340c14

Browse files
committed
Supported SSL verification toggle.
1 parent ebb6b45 commit f340c14

File tree

5 files changed

+66
-15
lines changed

5 files changed

+66
-15
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,20 +329,27 @@ Before you get started with creating your PHP application, you need to register
329329
330330
```php
331331
/*
332-
* autoRefreshFields
332+
* autoRefreshFields (default value is false)
333333
* true - all the modules' fields will be auto-refreshed in the background, every hour.
334334
* 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)
335335
*
336-
* pickListValidation
336+
* pickListValidation (default value is true)
337337
* 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.
338338
* true - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error.
339339
* false - the SDK does not validate the input and makes the API request with the user’s input to the pick list
340+
*
341+
* enableSSLVerification (default value is true)
342+
* A boolean field to enable or disable curl certificate verification
343+
* true - the SDK verifies the authenticity of certificate
344+
* false - the SDK skips the verification
340345
*/
341346
$autoRefreshFields = false;
342347
343348
$pickListValidation = false;
344349
345-
$sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->build();
350+
$enableSSLVerification = true;
351+
352+
$sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->setSSLVerification($enableSSLVerification)->build();
346353
```
347354
348355
- Create an instance of RequestProxy containing the proxy properties of the user.

src/com/zoho/api/authenticator/OAuthToken.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ public function getResponseFromServer($request_params)
311311

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

314+
if(!Initializer::getInitializer()->getSDKConfig()->isSSLVerificationEnabled())
315+
{
316+
curl_setopt($curl_pointer, CURLOPT_SSL_VERIFYPEER, false);
317+
}
318+
314319
$result = curl_exec($curl_pointer);
315320

316321
curl_close($curl_pointer);

src/com/zoho/crm/api/SDKConfigBuilder.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ class SDKConfigBuilder
1010

1111
private $pickListValidation;
1212

13+
private $enableSSLVerification;
14+
1315
public function __Construct()
1416
{
1517
$this->autoRefreshFields = false;
1618

1719
$this->pickListValidation = true;
20+
21+
$this->enableSSLVerification = true;
1822
}
1923

2024
/**
2125
* This is a setter method to set autoRefreshFields.
22-
* @param autoRefreshFields
26+
* @param autoRefreshFields
2327
*/
2428
public function setAutoRefreshFields(bool $autoRefreshFields)
2529
{
@@ -39,13 +43,24 @@ public function setPickListValidation(bool $pickListValidation)
3943
return $this;
4044
}
4145

46+
/**
47+
* This is a setter method to set enableSSLVerification.
48+
* @param enableSSLVerification
49+
*/
50+
public function setSSLVerification(bool $enableSSLVerification)
51+
{
52+
$this->enableSSLVerification = $enableSSLVerification;
53+
54+
return $this;
55+
}
56+
4257
/**
4358
* The method to build the SDKConfig instance
4459
* @returns An instance of SDKConfig
4560
*/
4661
public function build()
4762
{
48-
return new \com\zoho\crm\api\sdkconfigbuilder\SDKConfig($this->autoRefreshFields, $this->pickListValidation);
63+
return new \com\zoho\crm\api\sdkconfigbuilder\SDKConfig($this->autoRefreshFields, $this->pickListValidation, $this->enableSSLVerification);
4964
}
5065
}
5166

@@ -60,16 +75,21 @@ class SDKConfig
6075

6176
private $pickListValidation;
6277

78+
private $enableSSLVerification;
79+
6380
/**
6481
* Creates an instance of SDKConfig with the given parameters
6582
* @param autoRefreshFields - A boolean representing autoRefreshFields
6683
* @param pickListValidation - A boolean representing pickListValidation
84+
* @param enableSSLVerification - A boolean representing enableSSLVerification
6785
*/
68-
public function __Construct(bool $autoRefreshFields, bool $pickListValidation)
86+
public function __Construct(bool $autoRefreshFields, bool $pickListValidation, bool $enableSSLVerification)
6987
{
7088
$this->autoRefreshFields = $autoRefreshFields;
7189

7290
$this->pickListValidation = $pickListValidation;
91+
92+
$this->enableSSLVerification = $enableSSLVerification;
7393
}
7494

7595
/**
@@ -89,5 +109,14 @@ public function getPickListValidation()
89109
{
90110
return $this->pickListValidation;
91111
}
112+
113+
/**
114+
* This is a getter method to get enableSSLVerification.
115+
* @return A boolean representing enableSSLVerification
116+
*/
117+
public function isSSLVerificationEnabled()
118+
{
119+
return $this->enableSSLVerification;
120+
}
92121
}
93122
?>

src/com/zoho/crm/api/util/APIHTTPConnector.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,21 @@ public function fireRequest($converterInstance)
193193
}
194194

195195
$this->setQueryHeaders($curl_options);
196-
196+
197+
if(!Initializer::getInitializer()->getSDKConfig()->isSSLVerificationEnabled())
198+
{
199+
$curl_options[CURLOPT_SSL_VERIFYPEER] = false;
200+
}
201+
197202
curl_setopt_array($curl_pointer, $curl_options);
198-
203+
199204
SDKLogger::info($this->toString());
200205

201206
$response = array();
202207

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

205-
if (curl_errno($curl_pointer))
210+
if (curl_errno($curl_pointer))
206211
{
207212
$response[Constants::ERROR] = curl_error($curl_pointer);
208213
}

src/com/zoho/crm/api/util/Downloader.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,19 @@ public function getResponse($response, $pack)
9696
$responseHeaders = $response[Constants::HEADERS];
9797

9898
$responseContent = $response[Constants::CONTENT];
99-
100-
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION];
101-
102-
if ($contentDisposition == null)
99+
100+
$contentDisposition = "";
101+
102+
if(array_key_exists(Constants::CONTENT_DISPOSITION, $responseHeaders))
103103
{
104-
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION1];
105-
}
104+
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION];
106105

106+
if ($contentDisposition == null)
107+
{
108+
$contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION1];
109+
}
110+
}
111+
107112
$fileName = substr($contentDisposition, strrpos($contentDisposition, "'") + 1, strlen($contentDisposition));
108113

109114
if (strpos($fileName, "=") !== false)

0 commit comments

Comments
 (0)