Skip to content

Commit

Permalink
Use proxy to get cacert.pem file (#13)
Browse files Browse the repository at this point in the history
* If Wordpress installation is behind a proxy. Adding proxy context to get CA certs from Mozilla.
  • Loading branch information
dchambelant authored and figureone committed Aug 25, 2016
1 parent e2bf978 commit f72b2c3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,20 @@ private function custom_authenticate_cas( $auth_settings ) {
$time_90_days = 90 * 24 * 60 * 60; // days * hours * minutes * seconds
$time_90_days_ago = time() - $time_90_days;
if ( ! file_exists( $cacert_path ) || filemtime( $cacert_path ) < $time_90_days_ago ) {
$cacert_contents = file_get_contents( 'http://curl.haxx.se/ca/cacert.pem' );
$caUrl = 'https://curl.haxx.se/ca/cacert.pem';
if ( ! defined( 'WP_PROXY_HOST' ) ) {
$cacert_contents = file_get_contents( $caUrl );
} else {
$proxyurl = "tcp://" . WP_PROXY_HOST . ":" . WP_PROXY_PORT;
$domain = parse_url( $caUrl, PHP_URL_HOST );
$opts = array(
'http' => array( 'proxy' => $proxyurl ),
'ssl' => array( 'SNI_enabled' => true, 'SNI_server_name' => $domain )
);
$context = stream_context_create($opts);
$cacert_contents = file_get_contents( $caUrl, false, $context );
}

if ( $cacert_contents !== false ) {
file_put_contents( $cacert_path, $cacert_contents );
} else {
Expand Down

0 comments on commit f72b2c3

Please sign in to comment.