Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple certificates for DigiD/eHerkenning #79

Merged
merged 19 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
41b8f9f
:fire: Delete metadata generation management commands
sergei-maertens Jul 19, 2024
0ba2f45
:art: Misc implementation/test improvements
sergei-maertens Jul 19, 2024
5069a4e
:card_file_box: [#74] Add models and admin integration for digid/eh c…
sergei-maertens Jul 19, 2024
da167c7
:sparkles: [#74] Implement checks to consider valid candidates
sergei-maertens Jul 19, 2024
f103cf9
:card_file_box: [#74] Migrate from single FK certificate model to new…
sergei-maertens Jul 19, 2024
4822b96
:card_file_box: [#74] Delete the old certificate field
sergei-maertens Jul 19, 2024
a3d76c3
:sparkles: [#74] Update the admin interface
sergei-maertens Jul 19, 2024
ec40fac
:white_check_mark: [#74] Update fixtures to set up certificates corre…
sergei-maertens Jul 19, 2024
122b369
:building_construction: [#74] Flip around how we acquire the signing …
sergei-maertens Jul 19, 2024
fc36f02
:sparkles: [#74] First pass at implementing the certificate selection
sergei-maertens Jul 19, 2024
c65573b
:white_check_mark: [#74] Update test that was accessing certificate t…
sergei-maertens Jul 19, 2024
473c833
:arrow_up: [#74] Require simple-certmanager 2.3.0+
sergei-maertens Jul 19, 2024
a88309a
:white_check_mark: [#74] Add test for digid metadata generation with …
sergei-maertens Jul 22, 2024
afedbf5
:sparkles: [#74] Ensure that the next certificate is included in the …
sergei-maertens Jul 22, 2024
891f5e1
:white_check_mark: [#74] Make test assertions more strict
sergei-maertens Jul 22, 2024
d5c278c
:recycle: [#74] Refactor eherkenning metadata settings
sergei-maertens Jul 22, 2024
0be6ac0
:white_check_mark: [#74] Add tests for the admin configuration pages
sergei-maertens Jul 22, 2024
a9f8b8d
:white_check_mark: [#74] Add tests for current/next certificate selec…
sergei-maertens Jul 22, 2024
e6c9c1e
:bug: [#74] Fix string representation of new model
sergei-maertens Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
Changelog
=========

0.17.0 (DEVELOPMENT)
====================

**💥⚠️ Breaking changes**

* Removed the ``generate_digid_metadata``, ``generate_eherkenning_metadata`` and
``generate_eherkenning_dienstcatalogus`` management commands. This metadata is
available through the admin interface and existing URLs/views.

**Features**

...

Comment on lines +14 to +17
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll amend this in the release branch once this is done and merged :)

0.16.0 (2024-07-02)
===================

Expand Down
231 changes: 129 additions & 102 deletions digid_eherkenning/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from datetime import datetime

from django.contrib import admin
from django.urls import reverse
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _

from privates.admin import PrivateMediaMixin
from privates.widgets import PrivateFileWidget
from solo.admin import SingletonModelAdmin

from .models import DigidConfiguration, EherkenningConfiguration
from .models import ConfigCertificate, DigidConfiguration, EherkenningConfiguration
from .models.base import BaseConfiguration


class CustomPrivateFileWidget(PrivateFileWidget):
Expand All @@ -16,14 +21,39 @@ class CustomPrivateMediaMixin(PrivateMediaMixin):
private_media_file_widget = CustomPrivateFileWidget


@admin.register(DigidConfiguration)
class DigidConfigurationAdmin(CustomPrivateMediaMixin, SingletonModelAdmin):
readonly_fields = ("idp_service_entity_id",)
fieldsets = (
class BaseAdmin(CustomPrivateMediaMixin, SingletonModelAdmin):
readonly_fields = (
"link_to_certificates",
"idp_service_entity_id",
)
private_media_fields = ("idp_metadata_file",)

@admin.display(description=_("certificates"))
def link_to_certificates(self, obj: BaseConfiguration) -> str:
path = reverse(
"admin:digid_eherkenning_configcertificate_changelist",
current_app=self.admin_site.name,
)
config_type = obj._as_config_type()
qs = ConfigCertificate.objects.filter(config_type=config_type)
url = f"{path}?config_type__exact={config_type}"
return format_html(
'<a href="{url}" target="_blank">{label}</a>',
url=url,
config_type=config_type.value,
label=_("Manage ({count})").format(count=qs.count()),
)


def _fieldset_factory(middle):
"""
Output custom fieldsets (model-specific) between fixed shared field(set)s.
"""
head = [
(
_("X.509 Certificate"),
{
"fields": ("certificate",),
"fields": ("link_to_certificates",),
},
),
(
Expand All @@ -50,18 +80,8 @@ class DigidConfigurationAdmin(CustomPrivateMediaMixin, SingletonModelAdmin):
),
},
),
(
_("Service details"),
{
"fields": (
"service_name",
"service_description",
"requested_attributes",
"attribute_consuming_service_index",
"slo",
),
},
),
]
tail = [
(
_("Organization details"),
{
Expand All @@ -73,96 +93,103 @@ class DigidConfigurationAdmin(CustomPrivateMediaMixin, SingletonModelAdmin):
),
},
),
]

return tuple(head + list(middle) + tail)


@admin.register(DigidConfiguration)
class DigidConfigurationAdmin(BaseAdmin):
fieldsets = _fieldset_factory(
[
(
_("Service details"),
{
"fields": (
"service_name",
"service_description",
"requested_attributes",
"attribute_consuming_service_index",
"slo",
),
},
),
]
)
change_form_template = "admin/digid_eherkenning/digidconfiguration/change_form.html"
private_media_fields = ("idp_metadata_file",)


@admin.register(EherkenningConfiguration)
class EherkenningConfigurationAdmin(CustomPrivateMediaMixin, SingletonModelAdmin):
readonly_fields = ("idp_service_entity_id",)
fieldsets = (
(
_("X.509 Certificate"),
{
"fields": ("certificate",),
},
),
(
_("Identity provider"),
{
"fields": (
"metadata_file_source",
"idp_service_entity_id",
"idp_metadata_file",
),
},
),
(
_("SAML configuration"),
{
"fields": (
"entity_id",
"base_url",
"artifact_resolve_content_type",
"want_assertions_signed",
"want_assertions_encrypted",
"signature_algorithm",
"digest_algorithm",
),
},
),
(
_("Service details"),
{
"fields": (
"service_name",
"service_description",
"oin",
"makelaar_id",
"privacy_policy",
"service_language",
),
},
),
(
_("eHerkenning"),
{
"fields": (
"eh_requested_attributes",
"eh_attribute_consuming_service_index",
"eh_service_uuid",
"eh_service_instance_uuid",
"eh_loa",
),
},
),
(
_("eIDAS"),
{
"fields": (
"no_eidas",
"eidas_requested_attributes",
"eidas_attribute_consuming_service_index",
"eidas_service_uuid",
"eidas_service_instance_uuid",
"eidas_loa",
),
},
),
(
_("Organization details"),
{
"fields": (
"technical_contact_person_telephone",
"technical_contact_person_email",
"organization_url",
"organization_name",
),
},
),
class EherkenningConfigurationAdmin(BaseAdmin):
fieldsets = _fieldset_factory(
[
(
_("Service details"),
{
"fields": (
"service_name",
"service_description",
"oin",
"makelaar_id",
"privacy_policy",
"service_language",
),
},
),
(
_("eHerkenning"),
{
"fields": (
"eh_requested_attributes",
"eh_attribute_consuming_service_index",
"eh_service_uuid",
"eh_service_instance_uuid",
"eh_loa",
),
},
),
(
_("eIDAS"),
{
"fields": (
"no_eidas",
"eidas_requested_attributes",
"eidas_attribute_consuming_service_index",
"eidas_service_uuid",
"eidas_service_instance_uuid",
"eidas_loa",
),
},
),
]
)

change_form_template = (
"admin/digid_eherkenning/eherkenningconfiguration/change_form.html"
)
private_media_fields = ("idp_metadata_file",)


@admin.register(ConfigCertificate)
class ConfigCertificateAdmin(admin.ModelAdmin):
list_display = (
"config_type",
"certificate",
"valid_from",
"expiry_date",
"is_ready",
)
list_filter = ("config_type",)
search_fields = ("certificate__label",)
raw_id_fields = ("certificate",)

@admin.display(description=_("valid from"))
def valid_from(self, obj: ConfigCertificate) -> datetime:
return obj.certificate.valid_from

@admin.display(description=_("expires on"))
def expiry_date(self, obj: ConfigCertificate) -> datetime:
return obj.certificate.expiry_date

@admin.display(description=_("valid candidate?"), boolean=True)
def is_ready(self, obj: ConfigCertificate) -> bool:
return obj.is_ready_for_authn_requests
9 changes: 9 additions & 0 deletions digid_eherkenning/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
from onelogin.saml2.constants import OneLogin_Saml2_Constants


class ConfigTypes(models.TextChoices):
"""
Maps a config type enum to a configuration model.
"""

digid = "digid_eherkenning.DigidConfiguration", _("DigiD")
eherkenning = "digid_eherkenning.EherkenningConfiguration", _("eHerkenning")


class SectorType(models.TextChoices):
bsn = "s00000000", "BSN"
sofi = "s00000001", "SOFI"
Expand Down
6 changes: 6 additions & 0 deletions digid_eherkenning/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ class eHerkenningError(SAML2Error):

class eHerkenningNoRSINError(eHerkenningError):
pass


class CertificateProblem(Exception):
def __init__(self, msg: str, *args, **kwargs):
super().__init__(*args, **kwargs)
self.message = msg
Loading