fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.
at Microsoft.AspNetCore.DataProtection.SP800_108.ManagedSP800_108_CTR_HMACSHA512.DeriveKeys(ReadOnlySpan`1 kdk, ReadOnlySpan`1 label, ReadOnlySpan`1 contextHeader, ReadOnlySpan`1 contextData, Span`1 operationSubkey, Span`1 validationSubkey, HashAlgorithm prf)
at Microsoft.AspNetCore.DataProtection.Managed.ManagedAuthenticatedEncryptor.CreateContextHeader()
at Microsoft.AspNetCore.DataProtection.Managed.ManagedAuthenticatedEncryptor..ctor(Secret keyDerivationKey, Func`1 symmetricAlgorithmFactory, Int32 symmetricAlgorithmKeySizeInBytes, Func`1 validationAlgorithmFactory, IManagedGenRandom genRandom)
at Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ManagedAuthenticatedEncryptorFactory.CreateAuthenticatedEncryptorInstance(ISecret secret, ManagedAuthenticatedEncryptorConfiguration configuration)
at Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.AuthenticatedEncryptorFactory.CreateAuthenticatedEncryptorInstance(ISecret secret, AuthenticatedEncryptorConfiguration authenticatedConfiguration)
at Microsoft.AspNetCore.DataProtection.KeyManagement.Key.CreateEncryptor()
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRing.KeyHolder.GetEncryptorInstance(Boolean& isRevoked)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRing.get_DefaultAuthenticatedEncryptor()
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext)
at Microsoft.AspNetCore.Session.CookieProtection.Protect(IDataProtector protector, String data)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Is there an existing issue for this?
Describe the bug
ASP.NET Core applications that use the Data Protection APIs (e.g. by using the session middleware), fail with cryptographic operation errors on Ubuntu 22.04 if FIPS mode is enabled. The same code works fine with .NET 8.
Expected Behavior
The application should work and not produce cryptographic operation errors.
Steps To Reproduce
Preparation
sudo apt update && sudo apt upgradesudo add-apt-repository ppa:dotnet/backportssudo apt install dotnet-sdk-10.0mkdir DotnetFipsIssue cd DotnetFipsIssue dotnet new webapiProgram.csas follows:Test without FIPS enabled
dotnet run --launch-profile httpscurl -k https://localhost:5000/weatherforecast(replace with the correct port as displayed by the
dotnet runcommand)curlcommand displays the weather forecast as expected andthe application runs without errors.
Test with FIPS enabled
sudo pro attach --no-auto-enable sudo pro enable fips-updatessudo reboot1.cd DotnetFipsIssue dotnet run --launch-profile httpscurl -k https://localhost:5000/weatherforecast(replace with the correct port as displayed by the
dotnet runcommand)curlcommand fails, displaying the developer error details and that the application logs show:Exceptions (if any)
.NET Version
10.0.100
Anything else?
10.0.100dotnet --info: