Signedxml in NET 2 vs. NET 4.5

Asked

Viewed 31 times

1

I have a web application in Asp.net, which consumes a webservice in Delphi and that it uses a DLL created in C# to perform signatures.

With the web application installed on IIS, it shows an error. When running the web service within IIS using SOAPUI it also shows an error. When testing the webservice outside of IIS using Delphi + SOAPUI the process works. All tests were performed with NET 4.5.

All error scenarios occur in the Computesignature() method. Below is the error reported.

System.ArgumentException: Caracteres inválidos no caminho.
   em System.Security.Permissions.FileIOPermission.CheckIllegalCharacters(String[] str, Boolean onlyCheckExtras)
   em System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
   em System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
   em System.AppDomainSetup.VerifyDir(String dir, Boolean normalize)
   em System.AppDomainSetup.get_ConfigurationFile()
   em System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
   em System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
   em System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
   em System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp()
   em System.Configuration.ClientConfigurationSystem..ctor()
   em System.Configuration.ConfigurationManager.EnsureConfigurationSystem()

In the DLL when switching the NET version to the 2.0 signature method works normally, using within the IIS.

I would like to know why it works in 2.0 and if there is any configuration that should be done in DLL or IIS to work in version 4.5.

Below is the signature code:

private XmlElement GerarAssinatura(bool IsSalvador, XmlDocument doc, XmlNode childNodes)
        {
            XmlElement retorno = null;
            try
            {
                Reference reference = new Reference();
                reference.Uri = "";

                XmlElement childElemen = (XmlElement)childNodes;
                if (childElemen.GetAttributeNode("Id") != null)
                {
                    reference.Uri = "#" + childElemen.GetAttributeNode("Id").Value;
                }
                else if (childElemen.GetAttributeNode("id") != null)
                {
                    reference.Uri = "#" + childElemen.GetAttributeNode("id").Value;
                }

                RSACryptoServiceProvider privateKeyProvider = (RSACryptoServiceProvider)certificado.PrivateKey;

                SignedXml signedXml = new SignedXml(doc);
                signedXml.SigningKey = privateKeyProvider;

                XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
                reference.AddTransform(env);

                if (!IsSalvador)
                {
                    XmlDsigC14NTransform c14 = new XmlDsigC14NTransform();
                    reference.AddTransform(c14);
                }

                signedXml.AddReference(reference);

                KeyInfo keyInfo = new KeyInfo();
                KeyInfoX509Data x509Data = new KeyInfoX509Data(certificado);
                if (IsSalvador)
                {
                    KeyInfoClause rsaKeyVal = new RSAKeyValue((RSA)privateKeyProvider);
                    keyInfo.AddClause(rsaKeyVal);

                    x509Data.AddSubjectName(certificado.SubjectName.Name.ToString());
                }

                keyInfo.AddClause(x509Data);

                signedXml.KeyInfo = keyInfo;

                signedXml.ComputeSignature();

                retorno = signedXml.GetXml();
            }
            catch (Exception erro)
            {
                AddMensagem("Ocorreu erro ao assinar. " + erro.InnerException.ToString());
            }
            return retorno;
        }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.