Changeset 900385 for duo-wordpress
- Timestamp:
- 04/22/2014 06:27:33 PM (12 years ago)
- File:
-
- 1 edited
-
duo-wordpress/trunk/duo_wordpress.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
duo-wordpress/trunk/duo_wordpress.php
r881983 r900385 31 31 $DuoSecAuthCookieName = 'duo_secure_wordpress_auth_cookie'; 32 32 $DuoDebug = false; 33 $DuoPing = '/auth/v2/ping'; 33 34 34 35 function duo_sign_request($user, $redirect) { … … 58 59 echo '<link rel="stylesheet" type="text/css" href="' . admin_url('css/colors-fresh.css') . '" />'; 59 60 } 60 else {61 else if(version_compare($wp_version, "3.8", "<=")){ 61 62 echo '<link rel="stylesheet" type="text/css" href="' . admin_url('css/wp-admin.css') . '" />'; 62 63 echo '<link rel="stylesheet" type="text/css" href="' . admin_url('css/colors.css') . '" />'; 63 64 } 65 else { 66 echo '<link rel="stylesheet" type="text/css" href="' . admin_url('css/login.min.css') . '" />'; 67 } 68 64 69 ?> 65 70 … … 461 466 } 462 467 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. 464 489 * If that fails then use server system time 465 490 */ … … 471 496 } 472 497 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; 474 502 $cert_file = dirname(__FILE__) . '/duo_web/ca_certs.pem'; 475 503 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); 477 505 } 478 506 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); 480 508 } 481 509 else{ 482 $time = duo_get_time_WP_HTTP($duo_url );510 $time = duo_get_time_WP_HTTP($duo_url, $headers); 483 511 } 484 512 } … … 489 517 } 490 518 491 function duo_get_time_fopen($duo_url, $cert_file ){519 function duo_get_time_fopen($duo_url, $cert_file, $headers) { 492 520 $settings = array( 493 521 'http'=>array( 494 'method' => 'GET' 522 'method' => 'GET', 523 'header' => $headers, 524 'user_agent'=> duo_get_user_agent(), 495 525 ), 496 526 'ssl'=>array( 497 527 'allow_self_signed'=>false, 498 528 'verify_peer'=>true, 499 'cafile'=>$cert_file 529 'cafile'=>$cert_file, 500 530 ) 501 531 ); … … 515 545 } 516 546 517 function duo_get_time_curl($duo_url, $cert_file ) {547 function duo_get_time_curl($duo_url, $cert_file, $headers) { 518 548 $ch = curl_init(); 519 549 curl_setopt($ch, CURLOPT_URL, $duo_url); … … 523 553 curl_setopt($ch, CURLOPT_HEADER, 0); 524 554 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 555 curl_setopt($ch, CURLOPT_USERAGENT, duo_get_user_agent()); 556 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 525 557 526 558 if ( defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT')) { … … 539 571 } 540 572 541 // Uses Wor press HTTP, problem is that we can't specify our SSL cert here.573 // Uses Wordpress HTTP. We can't specify our SSL cert here. 542 574 // 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) { 544 576 if(!class_exists('WP_Http')){ 545 577 include_once(ABSPATH . WPINC . '/class-http.php'); … … 550 582 'blocking' => true, 551 583 'sslverify' => true, 584 'user-agent' => duo_get_user_agent(), 585 'headers' => $headers, 552 586 ); 553 587 $response = wp_remote_get($duo_url, $args); … … 685 719 */ 686 720 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.'); 688 723 return; 689 724 } … … 725 760 } 726 761 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 727 777 /*-------------XML-RPC Features-----------------*/ 728 778
Note: See TracChangeset
for help on using the changeset viewer.