Esempio n. 1
0
 public function run($testrun)
 {
     $this->crawler->reset();
     $this->crawler2->reset();
     // Get authentication request
     $this->log($testrun, 'Getting an authentication request');
     $result1 = $this->crawler->getURLraw($this->initurl);
     $this->expectAuthenticationRequest($result1);
     $request = $result1['Request'];
     $requestRaw = $result1['RequestRaw'];
     $relaystate = $result1['RelayState'];
     // Create Response
     $this->log($testrun, 'Creating a Response');
     $samlResponse = $this->createResponse($testrun, $request, $relaystate);
     $this->responsePrepared($samlResponse);
     // Sent response and get web page as result
     $result2 = $this->crawler->sendResponse($samlResponse['url'], $samlResponse['Response'], $samlResponse['RelayState']);
     $result2b = $this->crawler->getURLraw($this->attributeurl);
     // error_log('Getting an authentication request');
     // $result2b = $this->crawler->getURLraw($this->initurl);
     // Check output
     $this->log($testrun, 'Verifying that the user is logged in');
     $this->requireLoginOK($testrun, $result2b['body']);
     // IdP Initiated Logout...
     // Create logout request
     $this->log($testrun, 'Creating a LogoutRequest');
     $lr = $this->createLogoutRequest($testrun, $samlResponse);
     $this->logoutrequestPrepared($lr);
     $binding = new SAML2_HTTPRedirect();
     $binding->setDestination($lr['url']);
     $redirURL = $binding->getRedirectURL($lr['RequestObj']);
     $this->log($testrun, 'Sending a LogoutRequest');
     $result4 = $this->crawler2->getURLraw($redirURL);
     $logoutResponse = $result4['Request'];
     $logoutResponseRaw = $result4['RequestRaw'];
     $this->expectLogoutResponse($logoutResponseRaw);
     $this->log($testrun, 'Do a new GET to the first page to check if the user is logged in.');
     $result5 = $this->crawler->getURLraw($this->attributeurl);
     # getDebugOutput($testrun, $body, $request, $relaystate, $response, $logoutRequest, $logoutRelayState, $LogoutResponse, $result2) {
     // error_log($testrun);
     // error_log($result5['body']);
     // error_log($requestRaw);
     // error_log($samlResponse['RelayState']);
     // error_log($samlResponse['Response']);
     // error_log($lr['Request']);
     // error_log($result4['RelayState']);
     // error_log('logout response' . var_export($logoutResponseRaw, TRUE));
     // $debugoutput = $this->getDebugOutputExtended($testrun, $result5['body'], $requestRaw,
     // 	isset($samlResponse['RelayState']) ? $samlResponse['RelayState'] : NULL,
     // 	isset($samlResponse['Response']) ? $samlResponse['Response'] : NULL,
     // 	isset($lr['Request']) ? $lr['Request'] : NULL,
     // 	isset($result4['RelayState']) ? $result4['RelayState'] : NULL,
     // 	isset($logoutResponseRaw) ? $logoutResponseRaw : NULL,
     // 	$result5['body']);
     $this->log($testrun, 'Check output if user is logged in.');
     $this->expectedResult($testrun, $result5['body'], $debugoutput);
     #		error_log('url to logout: ' . $this->initslo);
     #		echo '<pre>'; print_r($this->flushResults()); exit;
     return $this->flushResults();
 }
Esempio n. 2
0
 public function run($testrun)
 {
     $this->crawler->reset();
     // Get authentication request
     $result1 = $this->crawler->getURLraw($this->initurl);
     // Fail if no authentication request was made
     $this->expectAuthenticationRequest($result1);
     $request = $result1['Request'];
     $requestRaw = $result1['RequestRaw'];
     $relaystate = $result1['RelayState'];
     // Create Response
     $samlResponse = $this->createResponse($testrun, $request, $relaystate);
     $this->responsePrepared($samlResponse);
     // Sent response and get web page as result
     $result2 = $this->crawler->sendResponse($samlResponse['url'], $samlResponse['Response'], $samlResponse['RelayState']);
     // Check output
     $this->requireLoginOK($testrun, $result2['body']);
     // SP Initiated Logout...
     $result3 = $this->crawler->getURLraw($this->initslo);
     if (!isset($result3['Request'])) {
         error_log('Logout URL did not return a logout request');
         throw new Exception('Logout URL did not return a logout request');
     }
     $logoutRequest = $result3['Request'];
     $logoutRequestRaw = $result3['RequestRaw'];
     $logoutRelayState = $result3['RelayState'];
     // Create logout response
     $this->log($testrun, 'Creating LogoutResponse');
     $logoutResponse = $this->createLogoutResponse($testrun, $logoutRequest, $logoutRelayState);
     $binding = new SAML2_HTTPRedirect();
     $binding->setDestination($logoutResponse['url']);
     $redirURL = $binding->getRedirectURL($logoutResponse['ResponseObj']);
     $this->log($testrun, 'Sending LogoutResponse');
     $result4 = $this->crawler->getURLraw($redirURL);
     // Get authentication request
     $this->log($testrun, 'Sending a new request to the initURL endpoint, to verify if user is logged in or not');
     $result5 = $this->crawler->getURLraw($this->attributeurl);
     # getDebugOutput($testrun, $body, $request, $relaystate, $response, $logoutRequest, $logoutRelayState, $LogoutResponse, $result2) {
     $debugoutput = $this->getDebugOutputExtended($testrun, $result4['body'], $requestRaw, $samlResponse['RelayState'], $samlResponse['Response'], $logoutRequestRaw, $logoutResponse['RelayState'], $logoutResponse['Response'], $result5['body']);
     $this->expectedResult($testrun, $result5['body'], $debugoutput);
     #		error_log('url to logout: ' . $this->initslo);
     #		echo '<pre>'; print_r($this->flushResults()); exit;
     return $this->flushResults();
 }
Esempio n. 3
0
 /**
  * Retrieve a logout URL for a given logout association.
  *
  * @param SimpleSAML_IdP $idp  The IdP we are sending a logout request from.
  * @param array $association  The association that should be terminated.
  * @param string|NULL $relayState  An id that should be carried across the logout.
  */
 public static function getLogoutURL(SimpleSAML_IdP $idp, array $association, $relayState)
 {
     assert('is_string($relayState) || is_null($relayState)');
     SimpleSAML_Logger::info('Sending SAML 2.0 LogoutRequest to: ' . var_export($association['saml:entityID'], TRUE));
     $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
     $idpMetadata = $idp->getConfig();
     $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
     $bindings = array(SAML2_Const::BINDING_HTTP_REDIRECT, SAML2_Const::BINDING_HTTP_POST);
     $dst = $spMetadata->getEndpointPrioritizedByBinding('SingleLogoutService', $bindings);
     if ($dst['Binding'] === SAML2_Const::BINDING_HTTP_POST) {
         $params = array('association' => $association['id'], 'idp' => $idp->getId());
         if ($relayState !== NULL) {
             $params['RelayState'] = $relayState;
         }
         return SimpleSAML_Module::getModuleURL('core/idp/logout-iframe-post.php', $params);
     }
     $lr = self::buildLogoutRequest($idpMetadata, $spMetadata, $association, $relayState);
     $lr->setDestination($dst['Location']);
     $binding = new SAML2_HTTPRedirect();
     return $binding->getRedirectURL($lr);
 }
Esempio n. 4
0
 /**
  * Retrieve a logout URL for a given logout association.
  *
  * @param SimpleSAML_IdP $idp  The IdP we are sending a logout request from.
  * @param array $association  The association that should be terminated.
  * @param string|NULL $relayState  An id that should be carried across the logout.
  */
 public static function getLogoutURL(SimpleSAML_IdP $idp, array $association, $relayState)
 {
     assert('is_string($relayState) || is_null($relayState)');
     SimpleSAML_Logger::info('Sending SAML 2.0 LogoutRequest to: ' . var_export($association['saml:entityID'], TRUE));
     $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
     $idpMetadata = $idp->getConfig();
     $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
     $lr = sspmod_saml_Message::buildLogoutRequest($idpMetadata, $spMetadata);
     $lr->setRelayState($relayState);
     $lr->setSessionIndex($association['saml:SessionIndex']);
     $lr->setNameId($association['saml:NameID']);
     $assertionLifetime = $spMetadata->getInteger('assertion.lifetime', NULL);
     if ($assertionLifetime === NULL) {
         $assertionLifetime = $idpMetadata->getInteger('assertion.lifetime', 300);
     }
     $lr->setNotOnOrAfter(time() + $assertionLifetime);
     $encryptNameId = $spMetadata->getBoolean('nameid.encryption', NULL);
     if ($encryptNameId === NULL) {
         $encryptNameId = $idpMetadata->getBoolean('nameid.encryption', FALSE);
     }
     if ($encryptNameId) {
         $lr->encryptNameId(sspmod_saml_Message::getEncryptionKey($spMetadata));
     }
     SimpleSAML_Stats::log('saml:idp:LogoutRequest:sent', array('spEntityID' => $association['saml:entityID'], 'idpEntityID' => $idpMetadata->getString('entityid')));
     $binding = new SAML2_HTTPRedirect();
     return $binding->getRedirectURL($lr);
 }
Esempio n. 5
0
 /**
  * Retrieve a logout URL for a given logout association.
  *
  * @param SimpleSAML_IdP $idp  The IdP we are sending a logout request from.
  * @param array $association  The association that should be terminated.
  * @param string|NULL $relayState  An id that should be carried across the logout.
  */
 public static function getLogoutURL(SimpleSAML_IdP $idp, array $association, $relayState)
 {
     assert('is_string($relayState) || is_null($relayState)');
     SimpleSAML_Logger::info('Sending SAML 2.0 LogoutRequest to: ' . var_export($association['saml:entityID'], TRUE));
     $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
     $idpMetadata = $idp->getConfig();
     $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
     $lr = sspmod_saml_Message::buildLogoutRequest($idpMetadata, $spMetadata);
     $lr->setRelayState($relayState);
     $lr->setSessionIndex($association['saml:SessionIndex']);
     $lr->setNameId($association['saml:NameID']);
     $binding = new SAML2_HTTPRedirect();
     return $binding->getRedirectURL($lr);
 }
 /**
  * launchkey_form - login form for wp-login.php
  *
  * @since 1.1.0
  *
  * @param string $class A space separated list of classes to set on the "class" attribute of a containing DIV for the login button
  * @param string $id The value to set on the "id" attribute of a containing DIV for the login button
  * @param string $style A string of HTML style code tto set on the "style" attribute of a containing DIV for the login button
  */
 public function launchkey_form($class = '', $id = '', $style = '')
 {
     if (isset($_GET['launchkey_error'])) {
         $this->wp_facade->_echo($this->template->render_template('error', array('error' => 'Error!', 'message' => 'The LaunchKey request was denied or an issue was detected during authentication. Please try again.')));
     } elseif (isset($_GET['launchkey_ssl_error'])) {
         $this->wp_facade->_echo($this->template->render_template('error', array('error' => 'Error!', 'message' => 'There was an error trying to request the LaunchKey servers. If this persists you may need to disable SSL verification.')));
     } elseif (isset($_GET['launchkey_security'])) {
         $this->wp_facade->_echo($this->template->render_template('error', array('error' => 'Error!', 'message' => 'There was a security issue detected and you have been logged out for your safety. Log back in to ensure a secure session.')));
     }
     $container = SAML2_Utils::getContainer();
     $request = new SAML2_AuthnRequest();
     $request->setId($container->generateId());
     //$request->setProviderName( parse_url( $this->wp_facade->home_url( '/' ), PHP_URL_HOST ) );
     $request->setDestination($this->login_url);
     $request->setIssuer($this->entity_id);
     $request->setRelayState($this->wp_facade->admin_url());
     $request->setAssertionConsumerServiceURL($this->wp_facade->wp_login_url());
     $request->setProtocolBinding(SAML2_Const::BINDING_HTTP_POST);
     $request->setIsPassive(false);
     $request->setNameIdPolicy(array('Format' => SAML2_Const::NAMEID_PERSISTENT, 'AllowCreate' => true));
     // Send it off using the HTTP-Redirect binding
     $binding = new SAML2_HTTPRedirect();
     $binding->setDestination($this->login_url);
     $this->wp_facade->_echo($this->template->render_template('launchkey-form', array('class' => $class, 'id' => $id, 'style' => $style, 'login_url' => $binding->getRedirectURL($request), 'login_text' => 'Log in with', 'login_with_app_name' => 'LaunchKey', 'size' => in_array($this->wp_facade->get_locale(), array('fr_FR', 'es_ES')) ? 'small' : 'medium')));
 }
        $spMetadata = $metadata->getMetaDataConfig($logoutInfo['Issuer'], 'saml20-sp-remote');
        // Find the relaystate if cached.
        $relayState = isset($logoutInfo['RelayState']) ? $logoutInfo['RelayState'] : null;
        /* Create a Logout Response. */
        $rg = sspmod_saml2_Message::buildLogoutResponse($idpMetadata, $spMetadata);
        $rg->setInResponseTo($logoutInfo['RequestID']);
        $rg->setRelayState($relayState);
        $httpredirect = new SAML2_HTTPRedirect();
        /*
         * If the user is not logged into any other SPs, send the LogoutResponse immediately
         */
        if (count($sparray) + count($sparrayNoLogout) === 0) {
            $httpredirect->setDestination(sspmod_SAML2_Message::getDebugDestination());
            $httpredirect->send($rg);
        } else {
            $logoutresponse = $httpredirect->getRedirectURL($rg);
        }
    } elseif (array_key_exists('RelayState', $logoutInfo)) {
        SimpleSAML_Utilities::redirect($logoutInfo['RelayState']);
        exit;
    } else {
        echo 'You are logged out';
        exit;
    }
} catch (Exception $exception) {
    SimpleSAML_Utilities::fatalError($session->getTrackID(), 'GENERATELOGOUTRESPONSE', $exception);
}
$spmeta = $metadata->getMetaData($requester, 'saml20-sp-remote');
$spname = $requester;
if (array_key_exists('name', $spmeta)) {
    $spname = $spmeta['name'];
Esempio n. 8
0
 public function run($testrun)
 {
     $this->crawler->reset();
     /* ----- o ------ o ------
      * Initiate authentication. Send authentication request.
      * ----- o ------ o ------
      */
     $this->log($testrun, 'Getting an authentication request');
     $result1 = $this->crawler->getURLraw($this->initurl);
     // Fail if no authentication request was made
     $this->expectAuthenticationRequest($result1);
     $request = $result1['Request'];
     $requestRaw = $result1['RequestRaw'];
     $relaystate = $result1['RelayState'];
     /* ----- o ------ o ------
      * IdP Initiated Logout...
      * ----- o ------ o ------
      */
     // First create a response...
     $this->log($testrun, 'Creating a Response');
     $samlResponse = $this->createResponse($testrun, $request, $relaystate);
     // Create logout request
     $this->log($testrun, 'Creating a LogoutRequest');
     $lr = $this->createLogoutRequest($testrun, $samlResponse);
     $this->logoutrequestPrepared($lr);
     $binding = new SAML2_HTTPRedirect();
     $binding->setDestination($lr['url']);
     $redirURL = $binding->getRedirectURL($lr['RequestObj']);
     #error_log('getRedirectURL returns: ['. $redirURL . ']');
     $this->log($testrun, 'Sending a LogoutRequest');
     $result4 = $this->crawler->getURLraw($redirURL);
     $logoutResponse = $result4['Request'];
     $logoutResponseRaw = $result4['RequestRaw'];
     $this->expectLogoutResponse($logoutResponseRaw);
     /* ----- o ------ o ------
      * Create Response with Assertion...
      * ----- o ------ o ------
      */
     // Sent response and get web page as result
     $this->responsePrepared($samlResponse);
     $result2 = $this->crawler->sendResponse($samlResponse['url'], $samlResponse['Response'], $samlResponse['RelayState']);
     // Get authentication request
     $this->log($testrun, 'Do a new GET to the first page to check if the user is logged in.');
     $result5 = $this->crawler->getURLraw($this->attributeurl);
     $this->log($testrun, 'Prepare debug output');
     # getDebugOutput($testrun, $body, $request, $relaystate, $response, $logoutRequest, $logoutRelayState, $LogoutResponse, $result2) {
     /**
      * body		Web page shown after logout.
      * request	The authentication request
      * relaystate The relaystate of the authentication request
      * response	The Response
      * logoutRequest	The logout request
      * logoutRelayState 
      * result2	The web site shown at attribute page accessing after flow.
      */
     // $debugoutput = $this->getDebugOutputExtended($testrun,
     // 	$requestRaw,
     // 	isset($samlResponse['RelayState']) ? $samlResponse['RelayState'] : NULL,
     // 	isset($samlResponse['Response']) ? $samlResponse['Response'] : NULL,
     // 	isset($lr['Request']) ? $lr['Request'] : NULL,
     // 	isset($result4['RelayState']) ? $result4['RelayState'] : NULL,
     // 	isset($logoutResponseRaw) ? $logoutResponseRaw : NULL,
     // 	$result5['body']);
     $this->log($testrun, 'Check output if user is logged in.');
     $this->expectedResult($testrun, $result5['body'], null);
     #		error_log('url to logout: ' . $this->initslo);
     #		echo '<pre>'; print_r($this->flushResults()); exit;
     return $this->flushResults();
 }
$sparray = array();
$sparrayNoLogout = array();
foreach ($listofsps as $spentityid) {
    // ($issuer, $receiver, $nameid, $nameidformat, $sessionindex, $mode) {
    $nameId = $session->getSessionNameId('saml20-sp-remote', $spentityid);
    if ($nameId === NULL) {
        $nameId = $session->getNameID();
    }
    $spMetadata = $metadata->getMetaDataConfig($spentityid, 'saml20-sp-remote');
    $name = $spMetadata->getValue('name', $spentityid);
    try {
        $lr = sspmod_saml2_Message::buildLogoutRequest($idpMetadata, $spMetadata);
        $lr->setSessionIndex($session->getSessionIndex());
        $lr->setNameId($nameId);
        $httpredirect = new SAML2_HTTPRedirect();
        $url = $httpredirect->getRedirectURL($lr);
        $sparray[$spentityid] = array('url' => $url, 'name' => $name);
    } catch (Exception $e) {
        $sparrayNoLogout[$spentityid] = array('name' => $name);
    }
}
SimpleSAML_Logger::debug('SAML2.0 - SP Counter. other SPs with SLO support (' . count($sparray) . ')  without SLO support (' . count($sparrayNoLogout) . ')');
#print_r($sparray);
/*
 * If the user is not logged into any other SPs.
 */
if (count($sparray) + count($sparrayNoLogout) === 0) {
    SimpleSAML_Utilities::redirect($relayState);
    exit;
}
$et = new SimpleSAML_XHTML_Template($config, 'logout-iframe.php');