예제 #1
0
        private static bool ReadContentsFrom200408(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection, out int pspSection)
        {
            buffer           = null;
            headers          = null;
            extensionSection = -1;
            metadataSection  = -1;
            pspSection       = -1;

            // Cache address string
            reader.MoveToContent();
            if (!reader.IsStartElement(XD.AddressingDictionary.Address, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing200408Dictionary.Namespace.Value)));
            }
            string address = reader.ReadElementContentAsString();

            // ReferenceProperites
            reader.MoveToContent();
            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceProperties, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                headers = AddressHeaderCollection.ReadServiceParameters(reader, true);
            }

            // ReferenceParameters
            reader.MoveToContent();
            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                if (headers != null)
                {
                    List <AddressHeader> headerList = new List <AddressHeader>();
                    foreach (AddressHeader ah in headers)
                    {
                        headerList.Add(ah);
                    }
                    AddressHeaderCollection tmp = AddressHeaderCollection.ReadServiceParameters(reader);
                    foreach (AddressHeader ah in tmp)
                    {
                        headerList.Add(ah);
                    }
                    headers = new AddressHeaderCollection(headerList);
                }
                else
                {
                    headers = AddressHeaderCollection.ReadServiceParameters(reader);
                }
            }

            XmlDictionaryWriter bufferWriter = null;

            // PortType
            reader.MoveToContent();
            if (reader.IsStartElement(XD.AddressingDictionary.PortType, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                if (bufferWriter == null)
                {
                    if (buffer == null)
                    {
                        buffer = new XmlBuffer(short.MaxValue);
                    }

                    bufferWriter = buffer.OpenSection(reader.Quotas);
                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                }
                bufferWriter.WriteNode(reader, true);
            }

            // ServiceName
            reader.MoveToContent();
            if (reader.IsStartElement(XD.AddressingDictionary.ServiceName, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                if (bufferWriter == null)
                {
                    if (buffer == null)
                    {
                        buffer = new XmlBuffer(short.MaxValue);
                    }

                    bufferWriter = buffer.OpenSection(reader.Quotas);
                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                }
                bufferWriter.WriteNode(reader, true);
            }

            // Policy
            reader.MoveToContent();
            while (reader.IsNamespaceUri(PolicyStrings.Namespace))
            {
                if (bufferWriter == null)
                {
                    if (buffer == null)
                    {
                        buffer = new XmlBuffer(short.MaxValue);
                    }

                    bufferWriter = buffer.OpenSection(reader.Quotas);
                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                }
                bufferWriter.WriteNode(reader, true);
                reader.MoveToContent();
            }

            // Finish PSP
            if (bufferWriter != null)
            {
                bufferWriter.WriteEndElement();
                buffer.CloseSection();
                pspSection   = buffer.SectionCount - 1;
                bufferWriter = null;
            }
            else
            {
                pspSection = -1;
            }


            // Metadata
            if (reader.IsStartElement(System.ServiceModel.Description.MetadataStrings.MetadataExchangeStrings.Metadata,
                                      System.ServiceModel.Description.MetadataStrings.MetadataExchangeStrings.Namespace))
            {
                if (bufferWriter == null)
                {
                    if (buffer == null)
                    {
                        buffer = new XmlBuffer(short.MaxValue);
                    }

                    bufferWriter = buffer.OpenSection(reader.Quotas);
                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                }
                bufferWriter.WriteNode(reader, true);
            }

            // Finish metadata
            if (bufferWriter != null)
            {
                bufferWriter.WriteEndElement();
                buffer.CloseSection();
                metadataSection = buffer.SectionCount - 1;
                bufferWriter    = null;
            }
            else
            {
                metadataSection = -1;
            }

            // Extensions
            reader.MoveToContent();
            buffer = ReadExtensions(reader, AddressingVersion.WSAddressingAugust2004, buffer, out identity, out extensionSection);

            // Finished reading
            if (buffer != null)
            {
                buffer.Close();
            }

            // Process Address
            if (address == Addressing200408Strings.Anonymous)
            {
                uri = AddressingVersion.WSAddressingAugust2004.AnonymousUri;
                if (headers == null && identity == null)
                {
                    return(true);
                }
            }
            else
            {
                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, AddressingVersion.WSAddressingAugust2004.Namespace)));
                }
            }
            return(false);
        }
예제 #2
0
        private static bool ReadContentsFrom10(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection)
        {
            buffer           = null;
            extensionSection = -1;
            metadataSection  = -1;

            // Cache address string
            if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value)));
            }

            string address = reader.ReadElementContentAsString();

            // Headers
            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace))
            {
                headers = AddressHeaderCollection.ReadServiceParameters(reader);
            }
            else
            {
                headers = null;
            }

            // Metadata
            if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace))
            {
                reader.ReadFullStartElement();  // the wsa10:Metadata element is never stored in the buffer
                buffer          = new XmlBuffer(short.MaxValue);
                metadataSection = 0;
                XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
                writer.WriteStartElement(DummyName, DummyNamespace);
                while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF)
                {
                    writer.WriteNode(reader, true);
                }
                writer.Flush();
                buffer.CloseSection();
                reader.ReadEndElement();
            }

            // Extensions
            buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection);
            if (buffer != null)
            {
                buffer.Close();
            }

            // Process Address
            if (address == Addressing10Strings.Anonymous)
            {
                uri = AddressingVersion.WSAddressing10.AnonymousUri;
                if (headers == null && identity == null)
                {
                    return(true);
                }
            }
            else if (address == Addressing10Strings.NoneAddress)
            {
                uri = AddressingVersion.WSAddressing10.NoneUri;
                return(false);
            }
            else
            {
                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value)));
                }
            }
            return(false);
        }
 public override bool CanReadClause(XmlDictionaryReader reader, string tokenType)
 {
     if (((tokenType == null) || (tokenType == this.parent.SerializerDictionary.SecurityContextTokenType.Value)) && reader.IsStartElement(XD.SecurityJan2004Dictionary.Reference, XD.SecurityJan2004Dictionary.Namespace))
     {
         string attribute = reader.GetAttribute(XD.SecurityJan2004Dictionary.ValueType, null);
         if ((attribute != null) && (attribute != this.parent.SerializerDictionary.SecurityContextTokenReferenceValueType.Value))
         {
             return(false);
         }
         string str2 = reader.GetAttribute(XD.SecurityJan2004Dictionary.URI, null);
         if (((str2 != null) && (str2.Length > 0)) && (str2[0] != '#'))
         {
             return(true);
         }
     }
     return(false);
 }
 internal override bool IsReaderAtTimestamp(XmlDictionaryReader reader)
 {
     return(reader.IsStartElement(System.ServiceModel.XD.UtilityDictionary.Timestamp, System.ServiceModel.XD.UtilityDictionary.Namespace));
 }
예제 #5
0
 public override bool CanReadClause(XmlDictionaryReader reader, string tokenType)
 {
     return(reader.IsStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace));
 }
 public virtual void ReadDerivedKeyTokenParameters(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver, out string id, out string derivationAlgorithm, out string label, out int length, out byte[] nonce, out int offset, out int generation, out SecurityKeyIdentifierClause tokenToDeriveIdentifier, out SecurityToken tokenToDerive)
 {
     if (tokenResolver == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenResolver");
     }
     id = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);
     derivationAlgorithm = reader.GetAttribute(XD.XmlSignatureDictionary.Algorithm, null);
     if (derivationAlgorithm == null)
     {
         derivationAlgorithm = this.parent.DerivationAlgorithm;
     }
     reader.ReadStartElement();
     tokenToDeriveIdentifier = null;
     tokenToDerive           = null;
     if (!reader.IsStartElement(XD.SecurityJan2004Dictionary.SecurityTokenReference, XD.SecurityJan2004Dictionary.Namespace))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("DerivedKeyTokenRequiresTokenReference")));
     }
     tokenToDeriveIdentifier = this.parent.WSSecurityTokenSerializer.ReadKeyIdentifierClause(reader);
     tokenResolver.TryResolveToken(tokenToDeriveIdentifier, out tokenToDerive);
     generation = -1;
     if (reader.IsStartElement(this.parent.SerializerDictionary.Generation, this.parent.SerializerDictionary.Namespace))
     {
         reader.ReadStartElement();
         generation = reader.ReadContentAsInt();
         reader.ReadEndElement();
         if (generation < 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("DerivedKeyInvalidGenerationSpecified", new object[] { (int)generation })));
         }
     }
     offset = -1;
     if (reader.IsStartElement(this.parent.SerializerDictionary.Offset, this.parent.SerializerDictionary.Namespace))
     {
         reader.ReadStartElement();
         offset = reader.ReadContentAsInt();
         reader.ReadEndElement();
         if (offset < 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("DerivedKeyInvalidOffsetSpecified", new object[] { (int)offset })));
         }
     }
     length = 0x20;
     if (reader.IsStartElement(this.parent.SerializerDictionary.Length, this.parent.SerializerDictionary.Namespace))
     {
         reader.ReadStartElement();
         length = reader.ReadContentAsInt();
         reader.ReadEndElement();
     }
     if ((offset == -1) && (generation == -1))
     {
         offset = 0;
     }
     DerivedKeySecurityToken.EnsureAcceptableOffset(offset, generation, length, this.maxKeyDerivationOffset);
     label = null;
     if (reader.IsStartElement(this.parent.SerializerDictionary.Label, this.parent.SerializerDictionary.Namespace))
     {
         reader.ReadStartElement();
         label = reader.ReadString();
         reader.ReadEndElement();
     }
     if ((label != null) && (label.Length > this.maxKeyDerivationLabelLength))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new MessageSecurityException(System.ServiceModel.SR.GetString("DerivedKeyTokenLabelTooLong", new object[] { label.Length, this.maxKeyDerivationLabelLength })));
     }
     nonce = null;
     reader.ReadStartElement(this.parent.SerializerDictionary.Nonce, this.parent.SerializerDictionary.Namespace);
     nonce = reader.ReadContentAsBase64();
     reader.ReadEndElement();
     if ((nonce != null) && (nonce.Length > this.maxKeyDerivationNonceLength))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new MessageSecurityException(System.ServiceModel.SR.GetString("DerivedKeyTokenNonceTooLong", new object[] { nonce.Length, this.maxKeyDerivationNonceLength })));
     }
     reader.ReadEndElement();
 }
예제 #7
0
 internal override bool IsReaderAtSignatureConfirmation(XmlDictionaryReader reader)
 {
     return(reader.IsStartElement(XD.SecurityXXX2005Dictionary.SignatureConfirmation, XD.SecurityXXX2005Dictionary.Namespace));
 }
예제 #8
0
 public virtual bool CanReadTokenCore(XmlDictionaryReader reader)
 {
     return(reader.IsStartElement(LocalName, NamespaceUri) &&
            reader.GetAttribute(XD.SecurityJan2004Dictionary.ValueType, null) == ValueTypeUri);
 }
예제 #9
0
            public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver)
            {
#if disaled
                UniqueId contextId     = null;
                byte[]   encodedCookie = null;
                UniqueId generation    = null;
                bool     isCookieMode  = false;

                Fx.Assert(reader.NodeType == XmlNodeType.Element, "");

                // check if there is an id
                string id = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);

                SecurityContextSecurityToken sct = null;

                // There needs to be at least a contextId in here.
                reader.ReadFullStartElement();
                reader.MoveToStartElement(parent.SerializerDictionary.Identifier, parent.SerializerDictionary.Namespace);
                contextId = reader.ReadElementContentAsUniqueId();
                if (CanReadGeneration(reader))
                {
                    generation = ReadGeneration(reader);
                }
                if (reader.IsStartElement(parent.SerializerDictionary.Cookie, XD.DotNetSecurityDictionary.Namespace))
                {
                    isCookieMode = true;
                    ISecurityContextSecurityTokenCache sctCache;
                    sct = TryResolveSecurityContextToken(contextId, generation, id, tokenResolver, out sctCache);
                    if (sct == null)
                    {
                        encodedCookie = reader.ReadElementContentAsBase64();
                        if (encodedCookie != null)
                        {
                            sct = cookieSerializer.CreateSecurityContextFromCookie(encodedCookie, contextId, generation, id, reader.Quotas);
                            if (sctCache != null)
                            {
                                sctCache.AddContext(sct);
                            }
                        }
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
                reader.ReadEndElement();

                if (contextId == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.NoSecurityContextIdentifier));
                }

                if (sct == null && !isCookieMode)
                {
                    ISecurityContextSecurityTokenCache sctCache;
                    sct = TryResolveSecurityContextToken(contextId, generation, id, tokenResolver, out sctCache);
                }
                if (sct == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityContextTokenValidationException(SR.Format(SR.SecurityContextNotRegistered, contextId, generation)));
                }
                return(sct);
#else
                throw new NotImplementedException();
#endif
            }
예제 #10
0
        public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
            }
            if (samlSerializer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("samlSerializer");
            }
            SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;

            reader.MoveToContent();
            reader.Read();
            if (reader.IsStartElement(samlDictionary.NameIdentifier, samlDictionary.Namespace))
            {
                this.nameFormat    = reader.GetAttribute(samlDictionary.NameIdentifierFormat, null);
                this.nameQualifier = reader.GetAttribute(samlDictionary.NameIdentifierNameQualifier, null);
                reader.MoveToContent();
                this.name = reader.ReadString();
                if (this.name == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLNameIdentifierMissingIdentifierValueOnRead")));
                }
                reader.MoveToContent();
                reader.ReadEndElement();
            }
            if (reader.IsStartElement(samlDictionary.SubjectConfirmation, samlDictionary.Namespace))
            {
                reader.MoveToContent();
                reader.Read();
                while (reader.IsStartElement(samlDictionary.SubjectConfirmationMethod, samlDictionary.Namespace))
                {
                    string str = reader.ReadString();
                    if (string.IsNullOrEmpty(str))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.SubjectConfirmationMethod.Value })));
                    }
                    this.confirmationMethods.Add(str);
                    reader.MoveToContent();
                    reader.ReadEndElement();
                }
                if (this.confirmationMethods.Count == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLSubjectConfirmationClauseMissingConfirmationMethodOnRead")));
                }
                if (reader.IsStartElement(samlDictionary.SubjectConfirmationData, samlDictionary.Namespace))
                {
                    reader.MoveToContent();
                    this.confirmationData = reader.ReadString();
                    reader.MoveToContent();
                    reader.ReadEndElement();
                }
                if (reader.IsStartElement(samlSerializer.DictionaryManager.XmlSignatureDictionary.KeyInfo, samlSerializer.DictionaryManager.XmlSignatureDictionary.Namespace))
                {
                    XmlDictionaryReader reader2 = XmlDictionaryReader.CreateDictionaryReader(reader);
                    this.securityKeyIdentifier = SamlSerializer.ReadSecurityKeyIdentifier(reader2, keyInfoSerializer);
                    this.crypto = SamlSerializer.ResolveSecurityKey(this.securityKeyIdentifier, outOfBandTokenResolver);
                    if (this.crypto == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SamlUnableToExtractSubjectKey")));
                    }
                    this.subjectToken = SamlSerializer.ResolveSecurityToken(this.securityKeyIdentifier, outOfBandTokenResolver);
                }
                if ((this.confirmationMethods.Count == 0) && string.IsNullOrEmpty(this.name))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLSubjectRequiresNameIdentifierOrConfirmationMethodOnRead")));
                }
                reader.MoveToContent();
                reader.ReadEndElement();
            }
            reader.MoveToContent();
            reader.ReadEndElement();
        }
예제 #11
0
            // xml format
            //<DerivedKeyToken wsu:Id="..." wsse:Algorithm="..."> id required, alg optional (curr disallowed)
            //  <SecurityTokenReference>...</SecurityTokenReference> - required
            //  <Properties>...</Properties> - disallowed (optional in spec, but we disallow it)
            // choice begin - (schema requires a choice - we allow neither on read - we always write one)
            //  <Generation>...</Generation> - optional
            //  <Offset>...</Offset> - optional
            // choice end
            //  <Length>...</Length> - optional - default 32 on read (default specified in spec, not in schema - we always write it)
            //  <Label>...</Label> - optional
            //  <Nonce>...</Nonce> - required (optional in spec, but we require it)
            //</DerivedKeyToken>
            public virtual void ReadDerivedKeyTokenParameters(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver, out string id, out string derivationAlgorithm, out string label, out int length, out byte[] nonce, out int offset, out int generation, out SecurityKeyIdentifierClause tokenToDeriveIdentifier, out SecurityToken tokenToDerive)
            {
                if (tokenResolver == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenResolver");
                }

                id = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);

                derivationAlgorithm = reader.GetAttribute(XD.XmlSignatureDictionary.Algorithm, null);
                if (derivationAlgorithm == null)
                {
                    derivationAlgorithm = _parent.DerivationAlgorithm;
                }

                reader.ReadStartElement();

                tokenToDeriveIdentifier = null;
                tokenToDerive           = null;

                if (reader.IsStartElement(XD.SecurityJan2004Dictionary.SecurityTokenReference, XD.SecurityJan2004Dictionary.Namespace))
                {
                    tokenToDeriveIdentifier = _parent.WSSecurityTokenSerializer.ReadKeyIdentifierClause(reader);
                    tokenResolver.TryResolveToken(tokenToDeriveIdentifier, out tokenToDerive);
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SRServiceModel.DerivedKeyTokenRequiresTokenReference));
                }

                // no support for properties

                generation = -1;
                if (reader.IsStartElement(_parent.SerializerDictionary.Generation, _parent.SerializerDictionary.Namespace))
                {
                    reader.ReadStartElement();
                    generation = reader.ReadContentAsInt();
                    reader.ReadEndElement();
                    if (generation < 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(string.Format(SRServiceModel.DerivedKeyInvalidGenerationSpecified, generation)));
                    }
                }

                offset = -1;
                if (reader.IsStartElement(_parent.SerializerDictionary.Offset, _parent.SerializerDictionary.Namespace))
                {
                    reader.ReadStartElement();
                    offset = reader.ReadContentAsInt();
                    reader.ReadEndElement();
                    if (offset < 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(string.Format(SRServiceModel.DerivedKeyInvalidOffsetSpecified, offset)));
                    }
                }

                length = DerivedKeySecurityToken.DefaultDerivedKeyLength;
                if (reader.IsStartElement(_parent.SerializerDictionary.Length, _parent.SerializerDictionary.Namespace))
                {
                    reader.ReadStartElement();
                    length = reader.ReadContentAsInt();
                    reader.ReadEndElement();
                }

                if ((offset == -1) && (generation == -1))
                {
                    offset = 0;
                }

                // verify that the offset is not larger than the max allowed
                DerivedKeySecurityToken.EnsureAcceptableOffset(offset, generation, length, _maxKeyDerivationOffset);

                label = null;
                if (reader.IsStartElement(_parent.SerializerDictionary.Label, _parent.SerializerDictionary.Namespace))
                {
                    reader.ReadStartElement();
                    label = reader.ReadString();
                    reader.ReadEndElement();
                }
                if (label != null && label.Length > _maxKeyDerivationLabelLength)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new MessageSecurityException(string.Format(SRServiceModel.DerivedKeyTokenLabelTooLong, label.Length, _maxKeyDerivationLabelLength)));
                }

                nonce = null;
                reader.ReadStartElement(_parent.SerializerDictionary.Nonce, _parent.SerializerDictionary.Namespace);
                nonce = reader.ReadContentAsBase64();
                reader.ReadEndElement();

                if (nonce != null && nonce.Length > _maxKeyDerivationNonceLength)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new MessageSecurityException(string.Format(SRServiceModel.DerivedKeyTokenNonceTooLong, nonce.Length, _maxKeyDerivationNonceLength)));
                }

                reader.ReadEndElement();
            }
예제 #12
0
 protected static bool HasHeaderElement(XmlDictionaryReader reader, EnvelopeVersion envelopeVersion)
 {
     return(reader.IsStartElement(XD.MessageDictionary.Header, envelopeVersion.DictionaryNamespace));
 }
예제 #13
0
 public override bool CanReadKeyIdentifierClauseCore(XmlDictionaryReader reader)
 {
     return(reader.IsStartElement(LocalName, NamespaceUri) || reader.IsStartElement(LocalName, _otherDictionary.Namespace));
 }
예제 #14
0
        private void WriteContentsTo200408(XmlDictionaryWriter writer)
        {
            // Address
            writer.WriteStartElement(XD.AddressingDictionary.Address, XD.Addressing200408Dictionary.Namespace);
            if (IsAnonymous)
            {
                writer.WriteString(XD.Addressing200408Dictionary.Anonymous);
            }
            else if (IsNone)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("addressingVersion", SR.Format(SR.SFxNone2004));
            }
            else
            {
                writer.WriteString(Uri.AbsoluteUri);
            }
            writer.WriteEndElement();

            // ReferenceProperties
            if (_headers != null && _headers.HasReferenceProperties)
            {
                writer.WriteStartElement(XD.AddressingDictionary.ReferenceProperties, XD.Addressing200408Dictionary.Namespace);
                _headers.WriteReferencePropertyContentsTo(writer);
                writer.WriteEndElement();
            }

            // ReferenceParameters
            if (_headers != null && _headers.HasNonReferenceProperties)
            {
                writer.WriteStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing200408Dictionary.Namespace);
                _headers.WriteNonReferencePropertyContentsTo(writer);
                writer.WriteEndElement();
            }

            // PSP (PortType, ServiceName, Policy)
            XmlDictionaryReader reader = null;

            if (_pspSection >= 0)
            {
                reader = GetReaderAtSection(Buffer, _pspSection);
                Copy(writer, reader);
            }

            // Metadata
            reader = null;
            if (_metadataSection >= 0)
            {
                reader = GetReaderAtSection(Buffer, _metadataSection);
                Copy(writer, reader);
            }

            // EndpointIdentity
            if (Identity != null)
            {
                Identity.WriteTo(writer);
            }

            // Extensions
            if (_extensionSection >= 0)
            {
                reader = GetReaderAtSection(Buffer, _extensionSection);
                while (reader.IsStartElement())
                {
                    if (reader.NamespaceURI == AddressingVersion.WSAddressingAugust2004.Namespace)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.AddressingExtensionInBadNS, reader.LocalName, reader.NamespaceURI)));
                    }

                    writer.WriteNode(reader, true);
                }
            }
        }
        protected override object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
            }
            if (parameters == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parameters"));
            }

            MessageInfo messageInfo;

            if (isRequest)
            {
                messageInfo = requestMessageInfo;
            }
            else
            {
                messageInfo = replyMessageInfo;
            }

            if (messageInfo.WrapperName != null)
            {
                if (!reader.IsStartElement(messageInfo.WrapperName, messageInfo.WrapperNamespace))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.SFxInvalidMessageBody, messageInfo.WrapperName, messageInfo.WrapperNamespace, reader.NodeType, reader.Name, reader.NamespaceURI)));
                }
                bool isEmptyElement = reader.IsEmptyElement;
                reader.Read();
                if (isEmptyElement)
                {
                    return(null);
                }
            }
            object returnValue = null;

            if (messageInfo.ReturnPart != null)
            {
                while (true)
                {
                    PartInfo part = messageInfo.ReturnPart;
                    if (part.Serializer.IsStartObject(reader))
                    {
                        returnValue = DeserializeParameter(reader, part, isRequest);
                        break;
                    }
                    if (!reader.IsStartElement())
                    {
                        break;
                    }
                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
            DeserializeParameters(reader, messageInfo.BodyParts, parameters, isRequest);
            if (messageInfo.WrapperName != null)
            {
                reader.ReadEndElement();
            }
            return(returnValue);
        }
예제 #16
0
        internal static EndpointIdentity ReadIdentity(XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }

            EndpointIdentity readIdentity = null;

            reader.MoveToContent();
            if (reader.IsEmptyElement)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(string.Format(SRServiceModel.UnexpectedEmptyElementExpectingClaim, XD.AddressingDictionary.Identity.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value)));
            }

            reader.ReadStartElement(XD.AddressingDictionary.Identity, XD.AddressingDictionary.IdentityExtensionNamespace);

            if (reader.IsStartElement(XD.AddressingDictionary.Spn, XD.AddressingDictionary.IdentityExtensionNamespace))
            {
                readIdentity = new SpnEndpointIdentity(reader.ReadElementString());
            }
            else if (reader.IsStartElement(XD.AddressingDictionary.Upn, XD.AddressingDictionary.IdentityExtensionNamespace))
            {
                readIdentity = new UpnEndpointIdentity(reader.ReadElementString());
            }
            else if (reader.IsStartElement(XD.AddressingDictionary.Dns, XD.AddressingDictionary.IdentityExtensionNamespace))
            {
                readIdentity = new DnsEndpointIdentity(reader.ReadElementString());
            }
            else if (reader.IsStartElement(XD.XmlSignatureDictionary.KeyInfo, XD.XmlSignatureDictionary.Namespace))
            {
                reader.ReadStartElement();
                if (reader.IsStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace))
                {
                    readIdentity = new X509CertificateEndpointIdentity(reader);
                }
                else if (reader.IsStartElement(XD.XmlSignatureDictionary.RsaKeyValue, XD.XmlSignatureDictionary.Namespace))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(string.Format(SRServiceModel.UnrecognizedIdentityType, reader.Name, reader.NamespaceURI)));
                }
                reader.ReadEndElement();
            }
            else if (reader.NodeType == XmlNodeType.Element)
            {
                //
                // Something unknown
                //
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(string.Format(SRServiceModel.UnrecognizedIdentityType, reader.Name, reader.NamespaceURI)));
            }
            else
            {
                //
                // EndpointIdentity element is empty or some other invalid xml
                //
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SRServiceModel.InvalidIdentityElement));
            }

            reader.ReadEndElement();

            return(readIdentity);
        }
 private bool IsPartElement(XmlDictionaryReader reader, PartInfo part)
 {
     return(reader.IsStartElement(part.DictionaryName, part.DictionaryNamespace));
 }