예제 #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();
 }
예제 #2
0
function sendQuery($dataId, $url, $nameId)
{
    assert('is_string($dataId)');
    assert('is_string($url)');
    assert('is_array($nameId)');
    SimpleSAML_Logger::debug('attributequery - sending request');
    $query = new SAML2_AttributeQuery();
    $query->setRelayState($dataId);
    $query->setDestination($url);
    $query->setIssuer($GLOBALS['spEntityId']);
    $query->setNameId($nameId);
    $binding = new SAML2_HTTPRedirect();
    $binding->setDestination(sspmod_saml2_Message::getDebugDestination());
    $binding->send($query);
}
예제 #3
0
파일: SLOTest.php 프로젝트: filonuse/fedlab
 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();
 }
예제 #4
0
파일: logout.php 프로젝트: hukumonline/yii
$spEntityId = $source->getEntityId();
$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
$idpMetadata = $metadata->getMetaDataConfig($idpEntityId, 'saml20-idp-remote');
$spMetadata = $source->getMetadata();
sspmod_saml2_Message::validateMessage($idpMetadata, $spMetadata, $message);
if ($message instanceof SAML2_LogoutResponse) {
    $relayState = $message->getRelayState();
    if ($relayState === NULL) {
        /* Somehow, our RelayState has been lost. */
        throw new SimpleSAML_Error_BadRequest('Missing RelayState in logout response.');
    }
    if (!$message->isSuccess()) {
        SimpleSAML_Logger::warning('Unsuccessful logout. Status was: ' . sspmod_saml2_Message::getResponseError($message));
    }
    $state = SimpleSAML_Auth_State::loadState($relayState, sspmod_saml2_Auth_Source_SP::STAGE_LOGOUTSENT);
    SimpleSAML_Auth_Source::completeLogout($state);
} elseif ($message instanceof SAML2_LogoutRequest) {
    SimpleSAML_Logger::debug('module/saml2/sp/logout: Request from ' . $idpEntityId);
    SimpleSAML_Logger::stats('saml20-idp-SLO idpinit ' . $spEntityId . ' ' . $idpEntityId);
    /* Notify source of logout, so that it may call logout callbacks. */
    $source->onLogout($idpEntityId);
    /* Create an send response. */
    $lr = sspmod_saml2_Message::buildLogoutResponse($spMetadata, $idpMetadata);
    $lr->setRelayState($message->getRelayState());
    $lr->setInResponseTo($message->getId());
    $binding = new SAML2_HTTPRedirect();
    $binding->setDestination(sspmod_SAML2_Message::getDebugDestination());
    $binding->send($lr);
} else {
    throw new SimpleSAML_Error_BadRequest('Unknown message received on logout endpoint: ' . get_class($message));
}
 /**
  * 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')));
 }
예제 #6
0
     * Check if the Single Logout procedure is initated by an SP (alternatively IdP initiated SLO)
     */
    if (array_key_exists('Issuer', $logoutInfo)) {
        $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');
예제 #7
0
파일: SP.php 프로젝트: hukumonline/yii
 /**
  * Start a SAML 2 logout operation.
  *
  * @param array $state  The logout state.
  */
 public function startSLO2(&$state)
 {
     assert('is_array($state)');
     assert('array_key_exists("saml:logout:IdP", $state)');
     assert('array_key_exists("saml:logout:NameID", $state)');
     assert('array_key_exists("saml:logout:SessionIndex", $state)');
     $id = SimpleSAML_Auth_State::saveState($state, 'saml:slosent');
     $idp = $state['saml:logout:IdP'];
     $nameId = $state['saml:logout:NameID'];
     $sessionIndex = $state['saml:logout:SessionIndex'];
     $idpMetadata = $this->getIdPMetadata($idp);
     $endpoint = $idpMetadata->getString('SingleLogoutService', FALSE);
     if ($endpoint === FALSE) {
         SimpleSAML_Logger::info('No logout endpoint for IdP ' . var_export($idp, TRUE) . '.');
         return;
     }
     $lr = sspmod_saml2_Message::buildLogoutRequest($this->metadata, $idpMetadata);
     $lr->setNameId($nameId);
     $lr->setSessionIndex($sessionIndex);
     $lr->setRelayState($id);
     $b = new SAML2_HTTPRedirect();
     $b->setDestination(sspmod_SAML2_Message::getDebugDestination());
     $b->send($lr);
     assert('FALSE');
 }
예제 #8
0
파일: SP.php 프로젝트: hukumonline/yii
 /**
  * Handle logout operation.
  *
  * @param array $state  The logout state.
  */
 public function logout(&$state)
 {
     assert('is_array($state)');
     assert('array_key_exists(self::LOGOUT_IDP, $state)');
     assert('array_key_exists(self::LOGOUT_NAMEID, $state)');
     assert('array_key_exists(self::LOGOUT_SESSIONINDEX, $state)');
     $id = SimpleSAML_Auth_State::saveState($state, self::STAGE_LOGOUTSENT);
     $idp = $state[self::LOGOUT_IDP];
     $nameId = $state[self::LOGOUT_NAMEID];
     $sessionIndex = $state[self::LOGOUT_SESSIONINDEX];
     if (array_key_exists('value', $nameId)) {
         /*
          * This session was saved by an old version of simpleSAMLphp.
          * Convert to the new NameId format.
          *
          * TODO: Remove this conversion once every session should use the new format.
          */
         $nameId['Value'] = $nameId['value'];
         unset($nameId['value']);
     }
     $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
     $idpMetadata = $metadata->getMetaDataConfig($idp, 'saml20-idp-remote');
     $lr = sspmod_saml2_Message::buildLogoutRequest($this->metadata, $idpMetadata);
     $lr->setNameId($nameId);
     $lr->setSessionIndex($sessionIndex);
     $lr->setRelayState($id);
     $b = new SAML2_HTTPRedirect();
     $b->setDestination(sspmod_SAML2_Message::getDebugDestination());
     $b->send($lr);
     assert('FALSE');
 }
예제 #9
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();
 }