Plugin Directory

Changeset 900385 for duo-wordpress


Ignore:
Timestamp:
04/22/2014 06:27:33 PM (12 years ago)
Author:
duosecurity
Message:

Send user-agent with API requests. Add support for WP 3.9 login page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • duo-wordpress/trunk/duo_wordpress.php

    r881983 r900385  
    3131    $DuoSecAuthCookieName = 'duo_secure_wordpress_auth_cookie';
    3232    $DuoDebug = false;
     33    $DuoPing = '/auth/v2/ping';
    3334
    3435    function duo_sign_request($user, $redirect) {
     
    5859                    echo '<link rel="stylesheet" type="text/css" href="' . admin_url('css/colors-fresh.css') . '" />';
    5960                }
    60                 else {
     61                else if(version_compare($wp_version, "3.8", "<=")){
    6162                    echo '<link rel="stylesheet" type="text/css" href="' . admin_url('css/wp-admin.css') . '" />';
    6263                    echo '<link rel="stylesheet" type="text/css" href="' . admin_url('css/colors.css') . '" />';
    6364                }
     65                else {
     66                    echo '<link rel="stylesheet" type="text/css" href="' . admin_url('css/login.min.css') . '" />';
     67                }
     68
    6469            ?>
    6570
     
    461466    }
    462467
    463     /* Get Duo's system time.
     468    /*
     469    * Returns current plugin version.
     470    *
     471    * @return string Plugin version
     472    */
     473    function duo_get_plugin_version() {
     474        if (!function_exists('get_plugin_data'))
     475            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
     476
     477        $plugin_data = get_plugin_data( __FILE__ );
     478        return $plugin_data['Version'];
     479    }
     480
     481    function duo_get_user_agent() {
     482        global $wp_version;
     483        $duo_wordpress_version = duo_get_plugin_version();
     484        return $_SERVER['SERVER_SOFTWARE'] . " WordPress/$wp_version duo_wordpress/$duo_wordpress_version";
     485    }
     486
     487    /*
     488     * Get Duo's system time.
    464489     * If that fails then use server system time
    465490     */
     
    471496        }
    472497        else {
    473             $duo_url = 'https://' . duo_get_option('duo_host') . '/auth/v2/ping';
     498            global $DuoPing;
     499            $duo_host = duo_get_option('duo_host');
     500            $headers = duo_sign_ping($duo_host);
     501            $duo_url = 'https://' . $duo_host . $DuoPing;
    474502            $cert_file = dirname(__FILE__) . '/duo_web/ca_certs.pem';
    475503            if( ini_get('allow_url_fopen') ) {
    476                 $time =  duo_get_time_fopen($duo_url, $cert_file);
     504                $time =  duo_get_time_fopen($duo_url, $cert_file, $headers);
    477505            }
    478506            else if(in_array('curl', get_loaded_extensions())){
    479                 $time = duo_get_time_curl($duo_url, $cert_file);
     507                $time = duo_get_time_curl($duo_url, $cert_file, $headers);
    480508            }
    481509            else{
    482                 $time = duo_get_time_WP_HTTP($duo_url);
     510                $time = duo_get_time_WP_HTTP($duo_url, $headers);
    483511            }
    484512        }
     
    489517    }
    490518
    491     function duo_get_time_fopen($duo_url, $cert_file){
     519    function duo_get_time_fopen($duo_url, $cert_file, $headers) {
    492520        $settings = array(
    493521                        'http'=>array(
    494                             'method' => 'GET'
     522                            'method' => 'GET',
     523                            'header' => $headers,
     524                            'user_agent'=> duo_get_user_agent(),
    495525                        ),
    496526                        'ssl'=>array(
    497527                            'allow_self_signed'=>false,
    498528                            'verify_peer'=>true,
    499                             'cafile'=>$cert_file
     529                            'cafile'=>$cert_file,
    500530                        )
    501531        );
     
    515545    }
    516546
    517     function duo_get_time_curl($duo_url, $cert_file) {
     547    function duo_get_time_curl($duo_url, $cert_file, $headers) {
    518548        $ch = curl_init();
    519549        curl_setopt($ch, CURLOPT_URL, $duo_url);
     
    523553        curl_setopt($ch, CURLOPT_HEADER, 0);
    524554        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     555        curl_setopt($ch, CURLOPT_USERAGENT, duo_get_user_agent());
     556        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    525557
    526558        if ( defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT')) {
     
    539571    }
    540572
    541     // Uses Worpress HTTP, problem is that we can't specify our SSL cert here.
     573    // Uses Wordpress HTTP. We can't specify our SSL cert here.
    542574    // Servers with out of date root certs may fail.
    543     function duo_get_time_WP_HTTP($duo_url){
     575    function duo_get_time_WP_HTTP($duo_url, $headers) {
    544576        if(!class_exists('WP_Http')){
    545577            include_once(ABSPATH . WPINC . '/class-http.php');
     
    550582            'blocking'    =>    true,
    551583            'sslverify'   =>    true,
     584            'user-agent'  =>    duo_get_user_agent(),
     585            'headers'     =>    $headers,
    552586        );
    553587        $response = wp_remote_get($duo_url, $args);
     
    685719    */
    686720        if (! duo_auth_enabled()){
    687             duo_debug_log('Duo not enabled, skip cookie check.');
     721            $site_info = get_current_site();
     722            duo_debug_log("Duo not enabled on " . $site_info->site_name . ', skip cookie check.');
    688723            return;
    689724        }
     
    725760    }
    726761
     762    function duo_sign_ping($host, $date=NULL) {
     763        global $DuoPing;
     764        if (! $date) {
     765            $date = date('r');
     766        }
     767        $canon = array($date, 'GET', $host, $DuoPing, '');
     768        $canon = implode("\n", $canon);
     769        $sig = hash_hmac('sha1', $canon, duo_get_option('duo_skey'));
     770        return array(
     771                'Authorization: Basic ' . base64_encode(duo_get_option('duo_ikey') . ':' . $sig),
     772                'Date: ' . $date,
     773                'Host: ' . $host,
     774        );
     775    }
     776
    727777    /*-------------XML-RPC Features-----------------*/
    728778   
Note: See TracChangeset for help on using the changeset viewer.