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

Supporto per .NET 9 #82

Open
FedericoValeri opened this issue Nov 18, 2024 · 3 comments
Open

Supporto per .NET 9 #82

FedericoValeri opened this issue Nov 18, 2024 · 3 comments

Comments

@FedericoValeri
Copy link

FedericoValeri commented Nov 18, 2024

Describe the bug
La libreria smette di funzionare dopo aver aggiornato a .NET 9.

To Reproduce
Aggiornando la mia applicazione a .NET 9 la libreria smette di funzionare dando il seguente errore:

SPID.AspNetCore.Authentication.Exceptions.SpidException: La chiave privata del certificato non è presente\r\n ---> System.Security.Cryptography.CryptographicException: Keyset non esistente.\r\n   at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider, CngKeyOpenOptions openOptions)\r\n   at System.Security.Cryptography.X509Certificates.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()\r\n   at SPID.AspNetCore.Authentication.Helpers.XmlHelpers.SignXMLDoc(XmlDocument doc, X509Certificate2 certificate, String referenceUri, String signatureMethod, String digestMethod)\r\n   --- End of inner exception stack trace ---\r\n   at SPID.AspNetCore.Authentication.Helpers.XmlHelpers.SignXMLDoc(XmlDocument doc, X509Certificate2 certificate, String referenceUri, String signatureMethod, String digestMethod)\r\n   at SPID.AspNetCore.Authentication.Saml.SamlHandler.SignDocumentInternal(String serializedDocument, X509Certificate2 certificate, String uuid, Int32 childIndex)\r\n   at SPID.AspNetCore.Authentication.Saml.SamlHandler.SignSerializedDocument(String serializedDocument, X509Certificate2 certificate, String uuid)\r\n   at SPID.AspNetCore.Authentication.SpidHandler.RequestHandler.HandleRequest[T](T message, String messageId, X509Certificate2 certificate, String signOnUrl, RequestMethod method)\r\n   at SPID.AspNetCore.Authentication.SpidHandler.HandleChallengeAsync(AuthenticationProperties properties)\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.ChallengeAsync(AuthenticationProperties properties)\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties)\r\n   at Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync(ActionContext context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)\r\n   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)\r\n   at SPID.AspNetCore.Authentication.Extensions.SpidSPMetadataMiddleware.Invoke(HttpContext context, IOptionsSnapshot`1 options, IServiceProvidersFactory serviceProvidersFactory)\r\n   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\r\n   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Expected behavior
La libreria dovrebbe funzionare anche con applicazioni che utilizzano la versione .NET 9.

Desktop:

  • OS: Windows 11 24H2
  • Browser: Chrome, Edge, Mozilla
  • Version: latest

Additional context
Deduco che il problema sia l'aggiornamento a .NET 9 dato che facendo un rollback alla versione 8.0.11 la libreria SPID funziona correttamente.

@danielegiallonardo
Copy link
Collaborator

Salve,
si, normalmente dovrebbe essere così, al netto di Breaking Changes introdotte da .Net9.
Facendo una rapida ricerca mi sono imbattuto in questo:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/9.0#cryptography
https://learn.microsoft.com/en-us/dotnet/core/compatibility/cryptography/9.0/private-key-lifetime

Credo necessiti di un approfondimento e di un adeguamento a .Net9

@sm15455
Copy link
Collaborator

sm15455 commented Nov 19, 2024

Io ho avuto un problema simile due settimane fa. Ho rigenerato da zero un pfx e ha ripreso a funzionare. Non so spiegarne il motivo.

@FedericoValeri
Copy link
Author

Io ho avuto un problema simile due settimane fa. Ho rigenerato da zero un pfx e ha ripreso a funzionare. Non so spiegarne il motivo.

Come posso rigenerare un pfx? Al momento sto utilizzando il file spid-aspnetcore-test.pfx che trovo nei progetti sample.

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

No branches or pull requests

3 participants