Skip to content

Migrate metadata generation to new SAML2-library#1901

Draft
tvdijen wants to merge 26 commits into
masterfrom
saml2v5_metadata
Draft

Migrate metadata generation to new SAML2-library#1901
tvdijen wants to merge 26 commits into
masterfrom
saml2v5_metadata

Conversation

@tvdijen
Copy link
Copy Markdown
Member

@tvdijen tvdijen commented Nov 20, 2023

This PR aims to partially migrate to the new SAML2 library. First run: metadata generation!

To do:

  • Raise coverage on the MetadataBuilder class.
  • Create a MetadataParser class as a replacement of the old SAMLParser class. This class should be able to parse XML metadata into SimpleSAMLphp's array-format. The Signer class should become obsolete.
  • Convert the ADFS module to use the new MetadataBuilder class. This also requires us to add a few missing classes to the ws-security library and . Missing classes are:
    • wst:RequestSecurityTokenResponse
    • wst:RequestSecurityToken
    • wsp:AppliesTo
  • Ensure that metadata we generate or consume complies with: https://docs.oasis-open.org/security/saml/Post2.0/sstc-metadata-iop-os.pdf

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 20, 2023

Codecov Report

Merging #1901 (74d478c) into master (d456913) will decrease coverage by 0.49%.
Report is 3 commits behind head on master.
The diff coverage is 52.95%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1901      +/-   ##
============================================
- Coverage     44.59%   44.10%   -0.49%     
+ Complexity     3743     3720      -23     
============================================
  Files           166      165       -1     
  Lines         12728    12728              
============================================
- Hits           5676     5614      -62     
- Misses         7052     7114      +62     

@tvdijen tvdijen force-pushed the saml2v5_metadata branch 4 times, most recently from 7cd3f83 to 74d478c Compare November 27, 2023 23:31
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from ccb9b02 to 120a100 Compare December 1, 2023 14:34
@tvdijen tvdijen force-pushed the saml2v5_metadata branch from 74d478c to 80b1a9d Compare April 2, 2024 18:53
@tvdijen tvdijen force-pushed the saml2v5_metadata branch 6 times, most recently from e0b429d to ab9195e Compare April 29, 2024 15:50
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 6004a77 to 58bf8db Compare May 4, 2024 23:45
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 5c9fb2c to 0970efc Compare May 27, 2024 12:27
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from c27831c to 71e49f4 Compare June 19, 2024 17:03
The unit test was also expecting an epoch integer here so that got
updated to expecting a Z time string.
There is a choice to either use an array of SAMLAnyURIValue for a
$SAML20Protocols function replacement and then intersect on that or we
can flatten the objects to strings an the normal array_intersect will
work ok on the same data types here.

I have code that does both things depending on which we are after.
@monkeyiq
Copy link
Copy Markdown
Contributor

There are still some changes in my vendor tree that I made to help things pass it seems. So working on that next...

@monkeyiq
Copy link
Copy Markdown
Contributor

Looking at my diffs I added some toArray() methods to the following. I am guessing that just adding them to release-6.1 / master in saml2 would be the way to go...

It seems github doesn't want to allow me to fork both saml2 and saml2-legacy. I could do a PR from a branch in the main saml2 repo or remove my saml2-legacy and fork and PR from there but either of those seem a little messy

Files I added toArray to:
saml2/src/XML/mdui/DomainHint.php
saml2/src/XML/mdui/GeolocationHint.php
saml2/src/XML/mdui/IPHint.php
saml2/src/XML/shibmd/Scope.php

@tvdijen
Copy link
Copy Markdown
Member Author

tvdijen commented Apr 21, 2026

This is strange, because you have all the admin-permissions you could possibly want on those libraries. saml2-legacy you can forget about.. That one only has the v4 version of the library.

For saml2 v6 I've created a pull request here.. Please review and let we know if you expect to need more classes to implement toArray/fromArray.

@monkeyiq
Copy link
Copy Markdown
Contributor

I now have the fork https://github.com/monkeyiq/saml2 I suspect that the saml2-legacy and saml2 repos were similar enough, or maybe even forked from each other in the past that github was not wanting to let me make a fork of both of them on my account.

The main saml2 lib fork is more useful so I have deleted the saml2-legacy fork I had in order to make this new fork happen.

@monkeyiq
Copy link
Copy Markdown
Contributor

The new MetadataParser uses SimpleSAML\SAML2\XML\shibmd\Scope::toArray() which I had a basic version of. saml2/master has a more real version of toArray() in it. I am not sure if the procedure is to

  • cherry pick things back from master to release-6.1 here
  • just copy the toArray() methods in PRs
  • something else.

I imagine I should be using saml2 6.1 branch because that is what the composer.json is calling for. It almost works against saml2/master.

@tvdijen
Copy link
Copy Markdown
Member Author

tvdijen commented Apr 24, 2026

It's not really a bugfix to add those helper-methods, so I will clone master into a new release-6.2 branch and tag it

The name of the self::flatten methods are just temporary still. They
are there to get the shape of the data into the format that the test
suite is expecting.

I will do a composer update next to make sure I have not changed
anything else locally that needs to be fed back.
@monkeyiq
Copy link
Copy Markdown
Contributor

ok so composer update seems to still have it working on the 11 tests in ./tests/src/SimpleSAML/Metadata/MetadataParserTest.php

@monkeyiq
Copy link
Copy Markdown
Contributor

I was looking for other example XML files with EntitiesDescriptor to add to the new MetadataParserTest.php. With a rgrep on the tree there doesn't seem to be other pickings. There are a few examples in sec 2.6 (page 23) of "Metadata for the OASIS Security Assertion Markup Language (SAML) V2.0".

@monkeyiq
Copy link
Copy Markdown
Contributor

I will take another look at the MetadataParser.php and it's test next.

@monkeyiq
Copy link
Copy Markdown
Contributor

I have also been trying to get ds:Signature creation / validation going for the MetadataParser. Sort of like validateSignature did. I have some nasty code that runs but does not verify it's own signatures correctly at the moment :/

@monkeyiq
Copy link
Copy Markdown
Contributor

It is also possible that the keys I am using from SignerTest might not match up in the way that I had hoped.

@tvdijen
Copy link
Copy Markdown
Member Author

tvdijen commented May 14, 2026

I was looking for other example XML files with EntitiesDescriptor to add to the new MetadataParserTest.php

There should be a few examples in the saml2-library. The interoperability-tests there download a few from the Czech and Greek edu-federations.

@monkeyiq
Copy link
Copy Markdown
Contributor

ok so I now have it working for signing and verifying. Sans a few nasty hacks in there and really nasty code in the current scratch zone.

But at least doing what I wanted to get to. Which is creating signatures on <md:EntitiesDescriptor>, saving to XML again, reloading, and verifying the sig.

@tvdijen
Copy link
Copy Markdown
Member Author

tvdijen commented May 18, 2026

Very nice work @monkeyiq !

@monkeyiq
Copy link
Copy Markdown
Contributor

So that is the test cleaned up a bit for less eye bleeding impact.

@tvdijen
Copy link
Copy Markdown
Member Author

tvdijen commented May 19, 2026

Do I understand correctly from the failing test that you need toArray/fromArray implemented for the shibmd:Scope element? If yes, then that's something I can take care of

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants