private static void AuthenticodeSignLicenseDom(XmlDocument licenseDom, System.Deployment.Internal.CodeSigning.CmiManifestSigner signer, string timeStampUrl)
 {
     if (signer.Certificate.PublicKey.Key.GetType() != typeof(RSACryptoServiceProvider))
     {
         throw new NotSupportedException();
     }
     System.Deployment.Internal.CodeSigning.ManifestSignedXml xml = new System.Deployment.Internal.CodeSigning.ManifestSignedXml(licenseDom) {
         SigningKey = signer.Certificate.PrivateKey
     };
     xml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
     xml.KeyInfo.AddClause(new RSAKeyValue(signer.Certificate.PublicKey.Key as RSA));
     xml.KeyInfo.AddClause(new KeyInfoX509Data(signer.Certificate, signer.IncludeOption));
     Reference reference = new Reference {
         Uri = ""
     };
     reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
     reference.AddTransform(new XmlDsigExcC14NTransform());
     xml.AddReference(reference);
     xml.ComputeSignature();
     XmlElement node = xml.GetXml();
     node.SetAttribute("Id", "AuthenticodeSignature");
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(licenseDom.NameTable);
     nsmgr.AddNamespace("r", "urn:mpeg:mpeg21:2003:01-REL-R-NS");
     (licenseDom.SelectSingleNode("r:license/r:issuer", nsmgr) as XmlElement).AppendChild(licenseDom.ImportNode(node, true));
     if ((timeStampUrl != null) && (timeStampUrl.Length != 0))
     {
         TimestampSignedLicenseDom(licenseDom, timeStampUrl);
     }
     licenseDom.DocumentElement.ParentNode.InnerXml = "<msrel:RelData xmlns:msrel=\"http://schemas.microsoft.com/windows/rel/2005/reldata\">" + licenseDom.OuterXml + "</msrel:RelData>";
 }
Exemplo n.º 2
0
        private static void AuthenticodeSignLicenseDom(XmlDocument licenseDom, System.Deployment.Internal.CodeSigning.CmiManifestSigner signer, string timeStampUrl)
        {
            if (signer.Certificate.PublicKey.Key.GetType() != typeof(RSACryptoServiceProvider))
            {
                throw new NotSupportedException();
            }
            System.Deployment.Internal.CodeSigning.ManifestSignedXml xml = new System.Deployment.Internal.CodeSigning.ManifestSignedXml(licenseDom)
            {
                SigningKey = signer.Certificate.PrivateKey
            };
            xml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
            xml.KeyInfo.AddClause(new RSAKeyValue(signer.Certificate.PublicKey.Key as RSA));
            xml.KeyInfo.AddClause(new KeyInfoX509Data(signer.Certificate, signer.IncludeOption));
            Reference reference = new Reference {
                Uri = ""
            };

            reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            reference.AddTransform(new XmlDsigExcC14NTransform());
            xml.AddReference(reference);
            xml.ComputeSignature();
            XmlElement node = xml.GetXml();

            node.SetAttribute("Id", "AuthenticodeSignature");
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(licenseDom.NameTable);

            nsmgr.AddNamespace("r", "urn:mpeg:mpeg21:2003:01-REL-R-NS");
            (licenseDom.SelectSingleNode("r:license/r:issuer", nsmgr) as XmlElement).AppendChild(licenseDom.ImportNode(node, true));
            if ((timeStampUrl != null) && (timeStampUrl.Length != 0))
            {
                TimestampSignedLicenseDom(licenseDom, timeStampUrl);
            }
            licenseDom.DocumentElement.ParentNode.InnerXml = "<msrel:RelData xmlns:msrel=\"http://schemas.microsoft.com/windows/rel/2005/reldata\">" + licenseDom.OuterXml + "</msrel:RelData>";
        }
Exemplo n.º 3
0
        private static void StrongNameSignManifestDom(XmlDocument manifestDom, XmlDocument licenseDom, System.Deployment.Internal.CodeSigning.CmiManifestSigner signer)
        {
            RSA strongNameKey = signer.StrongNameKey as RSA;

            if (strongNameKey == null)
            {
                throw new NotSupportedException();
            }
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(manifestDom.NameTable);

            nsmgr.AddNamespace("asm", "urn:schemas-microsoft-com:asm.v1");
            XmlElement elem = manifestDom.SelectSingleNode("asm:assembly", nsmgr) as XmlElement;

            if (elem == null)
            {
                throw new CryptographicException(-2146762749);
            }
            System.Deployment.Internal.CodeSigning.ManifestSignedXml xml = new System.Deployment.Internal.CodeSigning.ManifestSignedXml(elem)
            {
                SigningKey = signer.StrongNameKey
            };
            xml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
            xml.KeyInfo.AddClause(new RSAKeyValue(strongNameKey));
            if (licenseDom != null)
            {
                xml.KeyInfo.AddClause(new KeyInfoNode(licenseDom.DocumentElement));
            }
            xml.KeyInfo.Id = "StrongNameKeyInfo";
            Reference reference = new Reference {
                Uri = ""
            };

            reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            reference.AddTransform(new XmlDsigExcC14NTransform());
            xml.AddReference(reference);
            xml.ComputeSignature();
            XmlElement newChild = xml.GetXml();

            newChild.SetAttribute("Id", "StrongNameSignature");
            elem.AppendChild(newChild);
        }
 private static void StrongNameSignManifestDom(XmlDocument manifestDom, XmlDocument licenseDom, System.Deployment.Internal.CodeSigning.CmiManifestSigner signer)
 {
     RSA strongNameKey = signer.StrongNameKey as RSA;
     if (strongNameKey == null)
     {
         throw new NotSupportedException();
     }
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(manifestDom.NameTable);
     nsmgr.AddNamespace("asm", "urn:schemas-microsoft-com:asm.v1");
     XmlElement elem = manifestDom.SelectSingleNode("asm:assembly", nsmgr) as XmlElement;
     if (elem == null)
     {
         throw new CryptographicException(-2146762749);
     }
     System.Deployment.Internal.CodeSigning.ManifestSignedXml xml = new System.Deployment.Internal.CodeSigning.ManifestSignedXml(elem) {
         SigningKey = signer.StrongNameKey
     };
     xml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
     xml.KeyInfo.AddClause(new RSAKeyValue(strongNameKey));
     if (licenseDom != null)
     {
         xml.KeyInfo.AddClause(new KeyInfoNode(licenseDom.DocumentElement));
     }
     xml.KeyInfo.Id = "StrongNameKeyInfo";
     Reference reference = new Reference {
         Uri = ""
     };
     reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
     reference.AddTransform(new XmlDsigExcC14NTransform());
     xml.AddReference(reference);
     xml.ComputeSignature();
     XmlElement newChild = xml.GetXml();
     newChild.SetAttribute("Id", "StrongNameSignature");
     elem.AppendChild(newChild);
 }