getSPcert() public method

Returns the x509 public cert of the SP.
public getSPcert ( ) : string
return string SP public cert
示例#1
0
 /**
  * Tests the checkSPCerts method of the OneLogin_Saml2_Settings
  *
  * @covers OneLogin_Saml2_Settings::checkSPCerts
  * @covers OneLogin_Saml2_Settings::getSPcert
  * @covers OneLogin_Saml2_Settings::getSPkey
  */
 public function testCheckSPCerts()
 {
     $settings = new OneLogin_Saml2_Settings();
     $this->assertTrue($settings->checkSPCerts());
     $settingsDir = TEST_ROOT . '/settings/';
     include $settingsDir . 'settings2.php';
     $settings2 = new OneLogin_Saml2_Settings($settingsInfo);
     $this->assertTrue($settings2->checkSPCerts());
     $this->assertEquals($settings2->getSPkey(), $settings->getSPkey());
     $this->assertEquals($settings2->getSPcert(), $settings->getSPcert());
 }
示例#2
0
 /**
  * Tests the addSign method of the OneLogin_Saml2_Utils
  *
  * @covers OneLogin_Saml2_Utils::addSign
  */
 public function testAddSign()
 {
     $settingsDir = TEST_ROOT . '/settings/';
     include $settingsDir . 'settings1.php';
     $settings = new OneLogin_Saml2_Settings($settingsInfo);
     $key = $settings->getSPkey();
     $cert = $settings->getSPcert();
     $xmlAuthn = base64_decode(file_get_contents(TEST_ROOT . '/data/requests/authn_request.xml.base64'));
     $xmlAuthnSigned = OneLogin_Saml2_Utils::addSign($xmlAuthn, $key, $cert);
     $this->assertContains('<ds:SignatureValue>', $xmlAuthnSigned);
     $res = new DOMDocument();
     $res->loadXML($xmlAuthnSigned);
     $dsSignature = $res->firstChild->firstChild->nextSibling->nextSibling;
     $this->assertContains('ds:Signature', $dsSignature->tagName);
     $dom = new DOMDocument();
     $dom->loadXML($xmlAuthn);
     $xmlAuthnSigned2 = OneLogin_Saml2_Utils::addSign($dom, $key, $cert);
     $this->assertContains('<ds:SignatureValue>', $xmlAuthnSigned2);
     $res2 = new DOMDocument();
     $res2->loadXML($xmlAuthnSigned2);
     $dsSignature2 = $res2->firstChild->firstChild->nextSibling->nextSibling;
     $this->assertContains('ds:Signature', $dsSignature2->tagName);
     $xmlLogoutReq = base64_decode(file_get_contents(TEST_ROOT . '/data/logout_requests/logout_request.xml.base64'));
     $xmlLogoutReqSigned = OneLogin_Saml2_Utils::addSign($xmlLogoutReq, $key, $cert);
     $this->assertContains('<ds:SignatureValue>', $xmlLogoutReqSigned);
     $res3 = new DOMDocument();
     $res3->loadXML($xmlLogoutReqSigned);
     $dsSignature3 = $res3->firstChild->firstChild->nextSibling->nextSibling;
     $this->assertContains('ds:Signature', $dsSignature3->tagName);
     $xmlLogoutRes = base64_decode(file_get_contents(TEST_ROOT . '/data/logout_responses/logout_response.xml.base64'));
     $xmlLogoutResSigned = OneLogin_Saml2_Utils::addSign($xmlLogoutRes, $key, $cert);
     $this->assertContains('<ds:SignatureValue>', $xmlLogoutResSigned);
     $res4 = new DOMDocument();
     $res4->loadXML($xmlLogoutResSigned);
     $dsSignature4 = $res4->firstChild->firstChild->nextSibling->nextSibling;
     $this->assertContains('ds:Signature', $dsSignature4->tagName);
     $xmlMetadata = file_get_contents(TEST_ROOT . '/data/metadata/metadata_settings1.xml');
     $xmlMetadataSigned = OneLogin_Saml2_Utils::addSign($xmlMetadata, $key, $cert);
     $this->assertContains('<ds:SignatureValue>', $xmlMetadataSigned);
     $res5 = new DOMDocument();
     $res5->loadXML($xmlMetadataSigned);
     $dsSignature5 = $res5->firstChild->firstChild;
     $this->assertContains('ds:Signature', $dsSignature5->tagName);
 }
    /**
     * Constructs the AuthnRequest object.
     *
     * @param OneLogin_Saml2_Settings $settings Settings
     * @param bool   $forceAuthn When true the AuthNReuqest will set the ForceAuthn='true'
     * @param bool   $isPassive  When true the AuthNReuqest will set the Ispassive='true' 
     */
    public function __construct(OneLogin_Saml2_Settings $settings, $forceAuthn = false, $isPassive = false)
    {
        $this->_settings = $settings;
        $spData = $this->_settings->getSPData();
        $idpData = $this->_settings->getIdPData();
        $security = $this->_settings->getSecurityData();
        $id = OneLogin_Saml2_Utils::generateUniqueID();
        $issueInstant = OneLogin_Saml2_Utils::parseTime2SAML(time());
        $nameIDPolicyFormat = $spData['NameIDFormat'];
        if (isset($security['wantNameIdEncrypted']) && $security['wantNameIdEncrypted']) {
            $nameIDPolicyFormat = OneLogin_Saml2_Constants::NAMEID_ENCRYPTED;
        }
        $providerNameStr = '';
        $organizationData = $settings->getOrganization();
        if (!empty($organizationData)) {
            $langs = array_keys($organizationData);
            if (in_array('en-US', $langs)) {
                $lang = 'en-US';
            } else {
                $lang = $langs[0];
            }
            if (isset($organizationData[$lang]['displayname']) && !empty($organizationData[$lang]['displayname'])) {
                $providerNameStr = <<<PROVIDERNAME
    ProviderName="{$organizationData[$lang]['displayname']}" 
PROVIDERNAME;
            }
        }
        $forceAuthnStr = '';
        if ($forceAuthn) {
            $forceAuthnStr = <<<FORCEAUTHN

    ForceAuthn="true"
FORCEAUTHN;
        }
        $isPassiveStr = '';
        if ($isPassive) {
            $isPassiveStr = <<<ISPASSIVE

    IsPassive="true"
ISPASSIVE;
        }
        $requestedAuthnStr = '';
        if (isset($security['requestedAuthnContext']) && $security['requestedAuthnContext'] !== false) {
            if ($security['requestedAuthnContext'] === true) {
                $requestedAuthnStr = <<<REQUESTEDAUTHN
    <samlp:RequestedAuthnContext Comparison="exact">
        <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
    </samlp:RequestedAuthnContext>
REQUESTEDAUTHN;
            } else {
                $requestedAuthnStr .= "    <samlp:RequestedAuthnContext Comparison=\"exact\">\n";
                foreach ($security['requestedAuthnContext'] as $contextValue) {
                    $requestedAuthnStr .= "        <saml:AuthnContextClassRef>" . $contextValue . "</saml:AuthnContextClassRef>\n";
                }
                $requestedAuthnStr .= '    </samlp:RequestedAuthnContext>';
            }
        }
        $signature = '';
        if (isset($security['authnRequestsSigned']) && $security['authnRequestsSigned']) {
            $key = $this->_settings->getSPkey();
            $objKey = new XMLSecurityKey($security['signatureAlgorithm'], array('type' => 'private'));
            $objKey->loadKey($key, false);
            $signatureValue = $objKey->signData(time());
            $signatureValue = base64_encode($signatureValue);
            $digestValue = base64_encode(sha1(time()));
            $x509Cert = $this->_settings->getSPcert();
            $x509Cert = OneLogin_Saml2_Utils::formatCert($x509Cert, false);
            $signature = <<<SIGNATURE
            <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
        <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
        <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
        <ds:Reference>
            <ds:Transforms>
                <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <ds:DigestValue>{$digestValue}</ds:DigestValue>
        </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>asd{$signatureValue}</ds:SignatureValue>
    <ds:KeyInfo>
        <ds:X509Data>
            <ds:X509Certificate>{$x509Cert}</ds:X509Certificate>
        </ds:X509Data>
    </ds:KeyInfo>
</ds:Signature>
SIGNATURE;
        }
        $request = <<<AUTHNREQUEST
<samlp:AuthnRequest
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    ID="{$id}"
    Version="2.0"
{$providerNameStr}{$forceAuthnStr}{$isPassiveStr}
    IssueInstant="{$issueInstant}"
    Destination="{$idpData['singleSignOnService']['url']}"
    ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
    AssertionConsumerServiceURL="{$spData['assertionConsumerService']['url']}">
    <saml:Issuer>{$spData['entityId']}</saml:Issuer>
    {$signature}
    <samlp:NameIDPolicy
        Format="{$nameIDPolicyFormat}"
        AllowCreate="true" />
{$requestedAuthnStr}
</samlp:AuthnRequest>
AUTHNREQUEST;
        $this->_id = $id;
        $this->_authnRequest = $request;
    }