Skip to content

Conversation

@tvdijen
Copy link
Member

@tvdijen tvdijen commented Sep 1, 2024

This particular code was used by the ADFS-module to generate metadata.
The new adfs-module (currently in dev-feature/library) now has it's own metadata-builder and uses the low-level ws-security library to build the SecurityTokenServiceType-element and it's content.

Since this is fully backwards compatible once I tag a new major of the module (people can still use the adfs metadata-endpoint and get the same result), this should be fine to merge in the current release.

tvdijen and others added 2 commits September 2, 2024 11:19
* Remove deprecated spaceless-filter

* Fix whitespace-issue in converted metadata block

* Add update-note
…find things (#2235)

* docs: add some dev info about ssp-assets-base to help new developers find things

* docs: cleaning
@tvdijen tvdijen requested a review from thijskh September 3, 2024 09:36
* Throw user-friendly exception with the proper HTTP statuscode for 'method not found'

* Suppress traceback for MethodNotAllowed error, unless debug-logging is set

* Be able to suppress error reporting for specific types of errors
Copy link
Contributor

@monkeyiq monkeyiq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can check out the no metadata signing issue before or after merge.

@tvdijen
Copy link
Member Author

tvdijen commented Oct 16, 2024

Should be fixed in the feature/library branch now. If no keys are available, the code will continue without signing the assertion.
@monkeyiq Since you have some sort of test-setup, would you mind confirming that the signing issue was resolved?

@monkeyiq
Copy link
Contributor

My setup is probably a little strange.

I have in my config.php:

    'metadata.sign.enable' => false,

    'metadata.sign.privatekey' => null,
    'metadata.sign.privatekey_pass' => null,
    'metadata.sign.certificate' => null,

I have in my adfs-idp-hosted.php metadata file

    'privatekey' => 'host200404.pem',
    'certificate' => 'host200404.crt',

With that configuration I have to add a test like this in ADFS.php

        if(Configuration::getInstance()->getOptionalBoolean('metadata.sign.enable',true)) {
            if ($privateKeyFile !== null && $certificateFile !== null && $algo !== null) {
                $assertion = ADFS::signAssertion($assertion, $privateKeyFile, $certificateFile, $algo, $passphrase);
                $assertion = Assertion::fromXML($assertion->toXML());
            }
        }

After digging into this a bit more what I think we want is for me to set the privatekey/certificate to null in the idp file and the code to load keys changes to something like


        $assertion = ADFS::generateAssertion($idpEntityId, $spEntityId, $nameid, $attributes, $assertionLifetime);

        $configUtils = new Utils\Config();
        $privateKeyFile = null;
        $certificateFile = null;
        $path = $idpMetadata->getOptionalString('privatekey',null);
        if( $path ) {
            $privateKeyFile = $configUtils->getCertPath($path);
        }
        $path = $idpMetadata->getOptionalString('certificate',null);
        if( $path ) {
            $certificateFile = $configUtils->getCertPath($path);
        }
        $path = null;
        
        $passphrase = $idpMetadata->getOptionalString('privatekey_pass', null);

Otherwise the getString on 'privatekey' fails because it is set to null. getString calls getValue which calls hasValue which checks for the key and also !is_null($this->configuration[$name])

Oct 17 19:47:36 simplesamlphp ERROR [0bb4150be6] 12 /opt/sspdev/vendor/simplesamlphp/assert/src/Assert.php:389 (SimpleSAML\Assert\Assert::__callStatic)
Oct 17 19:47:36 simplesamlphp ERROR [0bb4150be6] 11 /opt/sspdev/src/SimpleSAML/Configuration.php:402 (SimpleSAML\Configuration::getValue)
Oct 17 19:47:36 simplesamlphp ERROR [0bb4150be6] 10 /opt/sspdev/src/SimpleSAML/Configuration.php:693 (SimpleSAML\Configuration::getString)
Oct 17 19:47:36 simplesamlphp ERROR [0bb4150be6] 9 /opt/sspdev/modules/adfs/src/IdP/ADFS.php:445 (SimpleSAML\Module\adfs\IdP\ADFS::sendResponse)

@monkeyiq
Copy link
Contributor

monkeyiq commented Oct 17, 2024

Thinking a bit more, it is a bit cleaner if the privatekey/certificate calls remain not optional but are moved into a block that is wrapped in a test if signing is desired (true by default).

if($idpMetadata->getOptionalBoolean('metadata.sign.enable', true)) {
   // sign it here
   $privateKeyFile = $configUtils->getCertPath($idpMetadata->getString('privatekey'));
   $certificateFile = $configUtils->getCertPath($idpMetadata->getString('certificate'));
   $passphrase = $idpMetadata->getOptionalString('privatekey_pass', null);
   ...

@tvdijen
Copy link
Member Author

tvdijen commented Oct 17, 2024

I'm not sure I follow what you're doing? What does metadata.sign.enable have to do with signing assertions? Metadata-signing uses a separate key-pair from config.php and doesn't affect the authentication process.

If you want your assertions signed, you have to set a key-pair in the adfs-idp-hosted.php file. This is not different from SAML IDPs by the way.

@monkeyiq
Copy link
Contributor

Please ignore my comment about 'metadata.sign.enable' I was thinking about how the code might be a little simpler if it was using a config key but it was the end of a long day so the key I mentioned was not valid.

@monkeyiq
Copy link
Contributor

The end of my slightly older comment is still ok though... the code does need to check for privatekey using getOptionalString or it will assert out if privatekey is set to null in the idp configuration.

@tvdijen
Copy link
Member Author

tvdijen commented Oct 17, 2024

Gotcha, changed two getString with getOptionalString

@monkeyiq
Copy link
Contributor

Hmm, getCertPath can not take a null value. Perhaps we can wrap the signing block with

if( $idpMetadata->getOptionalString('privatekey', null) !== null
  && $idpMetadata->getOptionalString('certificate', null) !== null ) {
...
}

@tvdijen
Copy link
Member Author

tvdijen commented Oct 22, 2024

I think I properly fixed it now

@monkeyiq
Copy link
Contributor

Cool. Login works without key/cert here.

@monkeyiq
Copy link
Contributor

Should we tag a release of the module before merging?

@tvdijen
Copy link
Member Author

tvdijen commented Oct 23, 2024

I've tagged v3.0.0-rc1 for the module and I will rebase this PR against the 2.4 release branch

@tvdijen tvdijen changed the base branch from simplesamlphp-2.3 to simplesamlphp-2.4 October 23, 2024 10:52
@monkeyiq
Copy link
Contributor

I took a quick look at the PR after the rebase. It seems LanguageTest.php is being changed in the PR and src/SimpleSAML/Locale/Language.php. The former seems ok but the later seems to be removing the lower casing of the language from 2.4 so maybe something was a little funky in the rebase?

$language = strtolower($language);

@tvdijen
Copy link
Member Author

tvdijen commented Oct 24, 2024

The strtolower only seems to exist in 2.4 ... Not in 2.3, not in master.. Something wasn't properly cherry-picked along the different branches here

@monkeyiq
Copy link
Contributor

Ah I see commit b9e38b9 above seems to be it.

@tvdijen
Copy link
Member Author

tvdijen commented Oct 25, 2024

Right, so it was intentionally removed in the 2.3 branch, but we failed to cherry-pick it to 2.4 ..

@monkeyiq
Copy link
Contributor

I am wondering about the many other commits at the top of the PR. For example the "Add link to 2.3 upgrade notes" doesn't seem to be in 2.4 either.

@monkeyiq
Copy link
Contributor

Ah I see, they were cherry picked into feature/adfs-upgrade and are now being merged into simplesamlphp-2.4.

@monkeyiq
Copy link
Contributor

I am thinking the "rebase and merge" option is probably the way to go? This will keep info about the cherry picked stuff separate in the history.

@monkeyiq
Copy link
Contributor

I will merge this tomorrow morning.

@monkeyiq
Copy link
Contributor

hmm, the rebase and merge is saying it cannot be done due to conflicts :(

@monkeyiq
Copy link
Contributor

I guess the normal merge is the second best option. The squash seems like the least desirable for this PR.

@monkeyiq monkeyiq merged commit ec4de5b into simplesamlphp-2.4 Oct 25, 2024
@tvdijen tvdijen deleted the feature/adfs-upgrade branch October 26, 2024 07:29
tvdijen pushed a commit that referenced this pull request Oct 26, 2024
Disconnect ADFS-module from SimpleSAMLphp
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants