Skip to content

Disable SSL verification #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/MessageBird/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ public function __construct($accessKey = null)
$this->voicemessages = new Resources\VoiceMessage($this->HttpClient);
}

/**
* Gets the value of the SSL verification flag.
*
* @return bool Returns true when SSL verification is enabled; false otherwise.
*/
public function getSSLVerificationEnabled()
{
return $this->HttpClient->getSSLVerificationEnabled();
}

/**
* Sets the SSL verification flag to either true or false.
*
* @param bool $sslVerificationEnabled A value to enable or disable the setting.
*/
public function setSSLVerificationEnabled($sslVerificationEnabled)
{
$this->HttpClient->setSSLVerificationEnabled($sslVerificationEnabled);
}

/**
* @param $accessKey
*/
Expand Down
34 changes: 34 additions & 0 deletions src/MessageBird/Common/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ class HttpClient
*/
protected $Authentication;

/**
* A flag that indicates whether or not SSL verification should take place.
* Always set this flag to true for production environments.
*
* @var bool
*/
protected $sslVerificationEnabled;

/**
* @param $endpoint
*/
public function __construct($endpoint)
{
$this->endpoint = $endpoint;
$this->sslVerificationEnabled = true;
}

/**
Expand All @@ -57,6 +66,26 @@ public function setAuthentication(Common\Authentication $Authentication)
$this->Authentication = $Authentication;
}

/**
* Gets the value of the SSL verification flag.
*
* @return bool Returns true when SSL verification is enabled; false otherwise.
*/
public function getSSLVerificationEnabled()
{
return $this->sslVerificationEnabled;
}

/**
* Sets the SSL verification flag to either true or false.
*
* @param bool $sslVerificationEnabled A value to enable or disable the setting.
*/
public function setSSLVerificationEnabled($sslVerificationEnabled)
{
$this->sslVerificationEnabled = $sslVerificationEnabled;
}

/**
* @param $resourceName
* @param $query
Expand Down Expand Up @@ -104,6 +133,11 @@ public function performHttpRequest($method, $resourceName, $query = null, $body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);

if (!$this->getSSLVerificationEnabled()) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
}

if ($method === self::REQUEST_GET) {
curl_setopt($curl, CURLOPT_HTTPGET, true);
} elseif ($method === self::REQUEST_POST) {
Expand Down