예제 #1
0
        /// <summary>
        /// Add the signature element to the memory stream.
        /// </summary>
        /// <param name="memoryStream">The memory stream.</param>
        internal override void Sign(MemoryStream memoryStream)
        {
            memoryStream.Position = 0;

            SafeXmlDocument document = new SafeXmlDocument();

            document.PreserveWhitespace = true;
            document.Load(memoryStream);

            WSSecurityUtilityIdSignedXml signedXml = new WSSecurityUtilityIdSignedXml(document);

            signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;

            //signedXml.AddReference("/soap:Envelope/soap:Header/t:ExchangeImpersonation");
            signedXml.AddReference("/soap:Envelope/soap:Header/wsse:Security/wsu:Timestamp");

            signedXml.KeyInfo.AddClause(this.keyInfoNode);
            using (var hashedAlgorithm = new HMACSHA1(ExchangeServiceBase.SessionKey))
            {
                signedXml.ComputeSignature(hashedAlgorithm);
            }

            XmlElement signature = signedXml.GetXml();

            XmlNode wssecurityNode = document.SelectSingleNode(
                "/soap:Envelope/soap:Header/wsse:Security",
                WSSecurityBasedCredentials.NamespaceManager);

            wssecurityNode.AppendChild(signature);

            memoryStream.Position = 0;
            document.Save(memoryStream);
        }
예제 #2
0
        /// <summary>
        /// Add the signature element to the memory stream.
        /// </summary>
        /// <param name="memoryStream">The memory stream.</param>
        internal override void Sign(MemoryStream memoryStream)
        {
            memoryStream.Position = 0;

            SafeXmlDocument document = new SafeXmlDocument();

            document.PreserveWhitespace = true;
            document.Load(memoryStream);

            WSSecurityUtilityIdSignedXml signedXml = new WSSecurityUtilityIdSignedXml(document);

            signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;

            signedXml.SigningKey = this.certificate.PrivateKey;
            signedXml.AddReference("/soap:Envelope/soap:Header/wsa:To");
            signedXml.AddReference("/soap:Envelope/soap:Header/wsse:Security/wsu:Timestamp");

            signedXml.KeyInfo.AddClause(this.keyInfoClause);
            signedXml.ComputeSignature();
            XmlElement signature = signedXml.GetXml();

            XmlNode wssecurityNode = document.SelectSingleNode(
                "/soap:Envelope/soap:Header/wsse:Security",
                WSSecurityBasedCredentials.NamespaceManager);

            wssecurityNode.AppendChild(signature);

            memoryStream.Position = 0;
            document.Save(memoryStream);
        }
예제 #3
0
        /// <summary>
        /// Helper to convert to xml dcouemnt from the current value.
        /// </summary>
        /// <param name="reader">the reader.</param>
        /// <returns>The xml document</returns>
        internal static SafeXmlDocument ReadToXmlDocument(EwsServiceXmlReader reader)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                reader.ReadBase64ElementValue(stream);
                stream.Position = 0;

                SafeXmlDocument manifest = new SafeXmlDocument();
                manifest.Load(stream);
                return(manifest);
            }
        }
예제 #4
0
        /// <summary>
        /// Helper to convert to xml dcouemnt from the current value.
        /// </summary>
        /// <param name="reader">the reader.</param>
        /// <returns>The xml document</returns>
        internal static SafeXmlDocument ReadToXmlDocument(EwsServiceXmlReader reader)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                reader.ReadBase64ElementValue(stream);
                stream.Position = 0;

                SafeXmlDocument manifest = new SafeXmlDocument();
                manifest.Load(stream);
                return manifest;
            }
        }
        /// <summary>
        /// Add the signature element to the memory stream.
        /// </summary>
        /// <param name="memoryStream">The memory stream.</param>
        internal override void Sign(MemoryStream memoryStream)
        {
            memoryStream.Position = 0;

            SafeXmlDocument document = new SafeXmlDocument();
            document.PreserveWhitespace = true;
            document.Load(memoryStream);

            WSSecurityUtilityIdSignedXml signedXml = new WSSecurityUtilityIdSignedXml(document);
            signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;

            signedXml.SigningKey = this.certificate.PrivateKey;
            signedXml.AddReference("/soap:Envelope/soap:Header/wsa:To");
            signedXml.AddReference("/soap:Envelope/soap:Header/wsse:Security/wsu:Timestamp");

            signedXml.KeyInfo.AddClause(this.keyInfoClause);
            signedXml.ComputeSignature();
            XmlElement signature = signedXml.GetXml();

            XmlNode wssecurityNode = document.SelectSingleNode(
                "/soap:Envelope/soap:Header/wsse:Security",
                WSSecurityBasedCredentials.NamespaceManager);

            wssecurityNode.AppendChild(signature);

            memoryStream.Position = 0;
            document.Save(memoryStream);
        }
        /// <summary>
        /// Add the signature element to the memory stream.
        /// </summary>
        /// <param name="memoryStream">The memory stream.</param>
        internal override void Sign(MemoryStream memoryStream)
        {
            memoryStream.Position = 0;

            SafeXmlDocument document = new SafeXmlDocument();
            document.PreserveWhitespace = true;
            document.Load(memoryStream);

            WSSecurityUtilityIdSignedXml signedXml = new WSSecurityUtilityIdSignedXml(document);
            signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;

            //signedXml.AddReference("/soap:Envelope/soap:Header/t:ExchangeImpersonation");
            signedXml.AddReference("/soap:Envelope/soap:Header/wsse:Security/wsu:Timestamp");

            signedXml.KeyInfo.AddClause(this.keyInfoNode);
            using (var hashedAlgorithm = new HMACSHA1(ExchangeServiceBase.SessionKey))
            {
                signedXml.ComputeSignature(hashedAlgorithm);
            }

            XmlElement signature = signedXml.GetXml();

            XmlNode wssecurityNode = document.SelectSingleNode(
                "/soap:Envelope/soap:Header/wsse:Security",
                WSSecurityBasedCredentials.NamespaceManager);

            wssecurityNode.AppendChild(signature);

            memoryStream.Position = 0;
            document.Save(memoryStream);
        }