8000 Validate Twitter SSL certificate for oauth2/token method · codezninja/codebird-php@753d457 · GitHub
[go: up one dir, main page]

Skip to content

Commit 753d457

Browse files
committed
Validate Twitter SSL certificate for oauth2/token method
1 parent 53d7b60 commit 753d457

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ codebird-php - changelog
33

44
2.4.1 (not yet released)
55
+ #26 Stringify null and boolean parameters
6+
+ Validate Twitter SSL certificate for oauth2/token method
67

78
2.4.0 (2013-06-15)
89
+ Add contributing guidelines

src/codebird.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,32 @@ public function oauth2_token()
363363
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
364364
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
365365
curl_setopt($ch, CURLOPT_HEADER, 1);
366-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
367-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
366+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
367+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
368+
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');
369+
368370
curl_setopt($ch, CURLOPT_USERPWD, self::$_oauth_consumer_key . ':' . self::$_oauth_consumer_secret);
369371
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
370372
'Expect:'
371373
));
372-
$reply = curl_exec($ch);
374+
$reply = curl_exec($ch);
375+
376+
// certificate validation results
377+
$validation_result = curl_errno($ch);
378+
if (in_array(
379+
$validation_result,
380+
array(
381+
CURLE_SSL_CERTPROBLEM,
382+
CURLE_SSL_CACERT,
383+
CURLE_SSL_CACERT_BADFILE,
384+
CURLE_SSL_CRL_BADFILE,
385+
CURLE_SSL_ISSUER_ERROR
386+
)
387+
)
388+
) {
389+
throw new \Exception('Error ' . $validation_result . ' while validating the Twitter API certificate.');
390+
}
391+
373392
$httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
374393
$reply = $this->_parseApiReply('oauth2/token', $reply);
375394
switch ($this->_return_format) {

0 commit comments

Comments
 (0)
0