Exemplo n.º 1
0
        private static void AuthenticodeSignLicenseDom(XmlDocument licenseDom, CmiManifestSigner signer, string timeStampUrl)
        {
            if (signer.Certificate.PublicKey.Key.GetType() != typeof(RSACryptoServiceProvider))
            {
                throw new NotSupportedException();
            }
            ManifestSignedXml manifestSignedXml = new ManifestSignedXml(licenseDom);

            manifestSignedXml.SigningKey = signer.Certificate.PrivateKey;
            manifestSignedXml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
            manifestSignedXml.KeyInfo.AddClause((KeyInfoClause) new RSAKeyValue(signer.Certificate.PublicKey.Key as RSA));
            manifestSignedXml.KeyInfo.AddClause((KeyInfoClause) new KeyInfoX509Data((X509Certificate)signer.Certificate, signer.IncludeOption));
            Reference reference = new Reference();

            reference.Uri = "";
            reference.AddTransform((Transform) new XmlDsigEnvelopedSignatureTransform());
            reference.AddTransform((Transform) new XmlDsigExcC14NTransform());
            manifestSignedXml.AddReference(reference);
            manifestSignedXml.ComputeSignature();
            XmlElement xml = manifestSignedXml.GetXml();

            xml.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((XmlNode)xml, true));
            if (timeStampUrl != null && timeStampUrl.Length != 0)
            {
                SignedCmiManifest.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 StrongNameSignManifestDom(XmlDocument manifestDom, XmlDocument licenseDom, 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);
            }
            ManifestSignedXml manifestSignedXml = new ManifestSignedXml(elem);

            manifestSignedXml.SigningKey = signer.StrongNameKey;
            manifestSignedXml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
            manifestSignedXml.KeyInfo.AddClause((KeyInfoClause) new RSAKeyValue(strongNameKey));
            if (licenseDom != null)
            {
                manifestSignedXml.KeyInfo.AddClause((KeyInfoClause) new KeyInfoNode(licenseDom.DocumentElement));
            }
            manifestSignedXml.KeyInfo.Id = "StrongNameKeyInfo";
            Reference reference = new Reference();

            reference.Uri = "";
            reference.AddTransform((Transform) new XmlDsigEnvelopedSignatureTransform());
            reference.AddTransform((Transform) new XmlDsigExcC14NTransform());
            manifestSignedXml.AddReference(reference);
            manifestSignedXml.ComputeSignature();
            XmlElement xml = manifestSignedXml.GetXml();

            xml.SetAttribute("Id", "StrongNameSignature");
            elem.AppendChild((XmlNode)xml);
        }