"Padding is invalid and cannot be removed." error with a twist - c#

I'm getting the following error in our QA environment but only through the IIS7 reverse proxy. If I hit the application server directly it works fine. In our DEV environment it works fine through the proxy or directly.
I'm not really sure where to go with this, any ideas?
Server Error in '/' Application.
Padding is invalid and cannot be removed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[CryptographicException: Padding is invalid and cannot be removed.]
System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast) +2910
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +286
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +51
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) +318
System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType) +115
System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +140
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4927

If this is happens on page with out post back then probably your proxy is convertting the url in lowercase chars and break the code.
I have one more bigger answer here with a trick to log the error and see whats really get on your page:
CryptographicException: Padding is invalid and cannot be removed and Validation of viewstate MAC failed

Related

"System.ComponentModel.Win32Exception (0x80090308): The token supplied to the function is invalid" when TLS13 is enabled

After adding the below registry key to enable TLS1.3 on Windows Server 2022
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
The .NET Client application throws the below exception
System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.ComponentModel.Win32Exception (0x80090308): The token supplied to the function is invalid
--- End of inner exception stack trace ---
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
Is there anything i am missing? In the .NET Client application i had set the protocol version to TLS13.
Thanks in advance.
Try the below before you call the server if server is also on windows 2022+
Otherwise it will not work if server is not 2022+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13

Server error after updating Jspool

i'm working with React.NET, i recently updated those nugets:
And now i receive this error :
Method not found: 'JavaScriptEngineSwitcher.Core.IJsEngine JSPool.IJsPool.GetEngine(System.Nullable`1<System.TimeSpan>)'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: Method not found: 'JavaScriptEngineSwitcher.Core.IJsEngine JSPool.IJsPool.GetEngine(System.Nullable`1<System.TimeSpan>)'.
Stack trace:
[MissingMethodException: Method not found: 'JavaScriptEngineSwitcher.Core.IJsEngine JSPool.IJsPool.GetEngine(System.Nullable`1<System.TimeSpan>)'.]
React.JavaScriptEngineFactory.GetEngine() +0
System.Lazy`1.CreateValue() +741
System.Lazy`1.LazyInitValue() +430
React.ReactEnvironment.EnsureUserScriptsLoaded() +40
React.ReactEnvironment.CreateComponent(String componentName, T props, String containerId, Boolean clientOnly) +43
Google didn't helped much, maby you can.
Thanks.
JavaScriptEnginerSwitch 2.0 is not supported yet: https://github.com/reactjs/React.NET/issues/319
and
https://github.com/reactjs/React.NET/issues/306
You will need to revert back to the previous version of those packages to get things working.

PermissionSet - Request Failed error

I have few projects communicating using ChannelSink, ServerSink and ClientSink.
I've upgraded the projects from .NET 2.0 to .NET 4.0. Before the upgrade everything worked fine.
Now, when I try to communicate , - for a specific message - my OnReceiveMessage isn't called and throwing the following exception:
System.Security.SecurityException: Request failed
Server stack trace:
at System.Array.InternalCreate(Void* elementType, Int32 rank, Int32* pLengths, Int32*
pLowerBounds)
at System.Array.CreateInstance(Type elementType, Int32 Length)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseArray(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseObject(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Parse(ParseRecord
pr)
System.Runtime.Serialization.Formatters.Soap.SoapHandler.StartChildren()
at System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXML()
System.Runtime.Serialization.Formatters.Soap.ObjectReader.Run()
System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler,
ISerParser
serParser)
System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream
serializationStream,
HeaderHandler handler)
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeSoapRequestMessage(Stream
inputStream, Header[] h, Boolean bStrictBinding)
at System.Runtime.Remoting.Chanels.SoapServerFormatterSink.ProcessMessage
(IServerChannelSinkStack sinkStack, IMessage requestMsg,
ITransportHeaders requestHeaders, Stream
requestStream, IMessage& responseMsg, ITransportHeaders&
responseHeaders, Stream& responseStream)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage (IMessage reqMsg, IMessage
retMSg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
.
. (some of my files)
. The action that failed was: Demand The type of the first permission that failed was: System.Security.PermissionSet The demand
was for:
The only permitted permissions were:
The method that caused that failure was:
System.Runtime.Remoting.Channels.ServerProcessing
ProcessMessage(System.Runtime.Remoting.Channels.IServerChannelSinkStack,
System.Runtime.Remoting.Messaging.IMessage,
System.Runtime.Remoting.Channels.ITransportHeaders, System.IO.Stream,
System.Runtime.Remoting.Messaging.IMessage ByRef,
System.Runtime.Remoting.Channels.ITransportHeaders ByRef,
System.IO.Stream ByRef)
The thing is, if I create a dummy method and add it to the sinkstack - it calls it. even if I use the same proxy which denies the message.
Other thing is, The other messages are working just fine. only one type of messages isnt working from all the types iv'e created.
I haven't requested PermissionSet at my app at all, Any help?
Pah - should have guess that 5 minutes after posting on stack exchange I would find it. I simply had to replace:
<formatter ref="soap" />
by
<formatter ref="soap" typeFilterLevel="Full" />
The MSDN documentation for typeFilterLevel explains what's happening, although I'm not entirely sure why an array isn't considered a "basic" type

How to resolve "error code is 0x80070001"?

I get the following error with the following stack trace. How do I resolve this?
error code is 0x80070001
Stack trace
[Type] Error | [Source] AccountsServices:An error occurred while communicating with the remote host. The error code is 0x80070001. | [Category] None | [Event] 0 | [User] | [Computer] VM2014.conduit.local | [Description] Message was not found: 0
_Duration=207593.75
Message:An error occurred while communicating with the remote host. The error code is 0x80070001.
StackTrace: at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
at System.Web.Hosting.IIS7WorkerRequest.ReadEntityCoreSync(Byte[] buffer, Int32 offset, Int32 size)
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.get_Form()
at System.Web.HttpRequest.FillInParamsCollection()
at System.Web.HttpRequest.GetParams()
at BrandToolbar.Web.Profile.ConduitProfileModule.UpdateVar() in d:\conduit\RnD\Server\Infrastructure\Providers\Web\Profile\Dev\ConduitProfileModule.cs:line 119
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
This isn't an issue with your application code, but probably your environment configuration. Are you using VMs?
You may or may not find this forum post helpful: http://social.technet.microsoft.com/Forums/en-US/winserverhyperv/thread/698e2b2b-af59-4848-b041-4fbb11c5bb6b

Strange webserver exception after patching web farm

We recently patched our 12 servers, now have been getting the following exceptions across all servers when hitting URL similar to this... (URL has been modified)
http://thedomain.com/WebResource.axd?d=yj6P234W1h22bOvqe2sdf2f=
System.Web.HttpException - Invalid viewstate.
Stack trace:
at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType)
at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
UPDATE
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo, Boolean signData)
at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType)
at System.Web.Handlers.ScriptResourceHandler.DecryptParameter(NameValueCollection queryString)
at System.Web.Handlers.ScriptResourceHandler.ProcessRequestInternal(HttpResponse response, NameValueCollection queryString, VirtualFileReader fileReader)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
This sounds like you have different encryption keys for the servers, which results in one server not being able to decrypt ViewState generated on a different server. See the following for additional information on how to fix it:
How To: Configure MachineKey in ASP.NET 2.0
Generate Machine Key Elements for Web Farms

Categories

Resources