public void ApplySecurityAndWriteHeaders(MessageHeaders headers, XmlDictionaryWriter writer, SecurityIdGenerator securityIdGenerator)
        {
            // There is no way to look through the headers attributes without changing the way
            // Headers.WriterStartHeader / headers.writeHeadercontents writes the header
            // So i'm using a copy that I can change without worries.
            MessageHeaders copyHeaders = new MessageHeaders(headers);

            for (int i = 0; i < headers.Count; i++)
            {
                MessageHeaderInfo header = headers[i];

                // We are not supporting another d:Security header, throw if there is already one in the message
                if (this.IsSecurityElement(header))
                {
                    throw new ArgumentException("The message already contains a d:security header.");
                }

                if (this.ShouldProtectHeader(header))
                {
                    string headerId;
                    bool idInserted;
                    this.GetHeaderId(copyHeaders.GetReaderAtHeader(i), securityIdGenerator, true, out headerId, out idInserted);

                    // Add a reference for this header
                    this.signer.AddReference(headers, i, writer, headerId, idInserted);
                }
                else
                {
                    headers.WriteHeader(i, writer);
                }
            }
        }
Exemplo n.º 2
0
        public SignedMessage(
            Message innerMessage,
            X509Certificate2 certificate,
            ProtocolSettings discoveryInfo)
        {
            Utility.IfNullThrowNullArgumentException(innerMessage, "innerMessage");
            this.innerMessage = innerMessage;
            this.envelopeUri  = (innerMessage.Version.Envelope == EnvelopeVersion.Soap11) ?
                                ProtocolStrings.SoapNamespace11Uri : ProtocolStrings.SoapNamespace12Uri;
            this.envelopePrefix = ProtocolStrings.SoapPrefix;

            this.discoveryInfo       = discoveryInfo;
            this.securityIdGenerator = new SecurityIdGenerator();
            this.securityHeader      = new SendCompactSignatureHeader(this, certificate, discoveryInfo);
            this.state = BodyState.Created;
        }
Exemplo n.º 3
0
        public SignedMessage(
            Message innerMessage,
            X509Certificate2 certificate,
            ProtocolSettings discoveryInfo)
        {
            Utility.IfNullThrowNullArgumentException(innerMessage, "innerMessage");
            this.innerMessage = innerMessage;
            this.envelopeUri = (innerMessage.Version.Envelope == EnvelopeVersion.Soap11) ?
                ProtocolStrings.SoapNamespace11Uri : ProtocolStrings.SoapNamespace12Uri;
            this.envelopePrefix = ProtocolStrings.SoapPrefix;

            this.discoveryInfo = discoveryInfo;
            this.securityIdGenerator = new SecurityIdGenerator();
            this.securityHeader = new SendCompactSignatureHeader(this, certificate, discoveryInfo);
            this.state = BodyState.Created;
        }
Exemplo n.º 4
0
        void GetHeaderId(
            XmlDictionaryReader reader,
            SecurityIdGenerator securityIdGenerator,
            bool closeReader,
            out string headerId,
            out bool idInserted)
        {
            // Look if the header already has a discovery Id attribute defined
            headerId = reader.GetAttribute(ProtocolStrings.IdAttributeName, this.DiscoveryInfo.DiscoveryNamespace);
            if (closeReader)
            {
                reader.Close();
            }

            idInserted = false;
            if (String.IsNullOrEmpty(headerId))
            {
                // The header doesn't contain a d:Id, so generate one.
                headerId   = securityIdGenerator.GenerateId();
                idInserted = true;
            }
        }
        void GetHeaderId(
            XmlDictionaryReader reader,
            SecurityIdGenerator securityIdGenerator,
            bool closeReader,
            out string headerId,
            out bool idInserted)
        {
            // Look if the header already has a discovery Id attribute defined
            headerId = reader.GetAttribute(ProtocolStrings.IdAttributeName, this.DiscoveryInfo.DiscoveryNamespace);
            if (closeReader)
            {
                reader.Close();
            }

            idInserted = false;
            if (String.IsNullOrEmpty(headerId))
            {
                // The header doesn't contain a d:Id, so generate one.
                headerId = securityIdGenerator.GenerateId();
                idInserted = true;
            }
        }
Exemplo n.º 6
0
        public void ApplySecurityAndWriteHeaders(MessageHeaders headers, XmlDictionaryWriter writer, SecurityIdGenerator securityIdGenerator)
        {
            // There is no way to look through the headers attributes without changing the way
            // Headers.WriterStartHeader / headers.writeHeadercontents writes the header
            // So i'm using a copy that I can change without worries.
            MessageHeaders copyHeaders = new MessageHeaders(headers);

            for (int i = 0; i < headers.Count; i++)
            {
                MessageHeaderInfo header = headers[i];

                // We are not supporting another d:Security header, throw if there is already one in the message
                if (this.IsSecurityElement(header))
                {
                    throw new ArgumentException("The message already contains a d:security header.");
                }

                if (this.ShouldProtectHeader(header))
                {
                    string headerId;
                    bool   idInserted;
                    this.GetHeaderId(copyHeaders.GetReaderAtHeader(i), securityIdGenerator, true, out headerId, out idInserted);

                    // Add a reference for this header
                    this.signer.AddReference(headers, i, writer, headerId, idInserted);
                }
                else
                {
                    headers.WriteHeader(i, writer);
                }
            }
        }