public override 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.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     if (!reader.IsStartElement(samlDictionary.DoNotCacheCondition, samlDictionary.Namespace))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.DoNotCacheCondition.Value })));
     }
     if (reader.IsEmptyElement)
     {
         reader.MoveToContent();
         reader.Read();
     }
     else
     {
         reader.MoveToContent();
         reader.Read();
         reader.ReadEndElement();
     }
 }
        public override 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.ThrowHelperError(new ArgumentNullException("samlSerializer"));

#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
            SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;

            if (!reader.IsStartElement(dictionary.DoNotCacheCondition, dictionary.Namespace))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.DoNotCacheCondition.Value)));

            // saml:DoNotCacheCondition is a empty element. So just issue a read for
            // the empty element.
            if (reader.IsEmptyElement)
            {
                reader.MoveToContent();
                reader.Read();
                return;
            }

            reader.MoveToContent();
            reader.Read();
            reader.ReadEndElement();
        }
        internal X509CertificateEndpointIdentity(XmlDictionaryReader reader)
        {
            if (reader == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");

            reader.MoveToContent();
            if (reader.IsEmptyElement)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.UnexpectedEmptyElementExpectingClaim, XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value)));

            reader.ReadStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace);
            while (reader.IsStartElement(XD.XmlSignatureDictionary.X509Certificate, XD.XmlSignatureDictionary.Namespace))
            {
                reader.MoveToContent();
                X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(reader.ReadContentAsString()));
                if (certificateCollection.Count == 0)
                {
                    // This is the first certificate. We assume this as the primary 
                    // certificate and initialize the base class.
                    Initialize(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
                }

                certificateCollection.Add(certificate);
            }

            reader.ReadEndElement();

            if (certificateCollection.Count == 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.UnexpectedEmptyElementExpectingClaim, XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value)));
        }
        public void ReadXml( XmlDictionaryReader reader )
        {
            if ( reader == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
            }

            reader.MoveToContent();
            if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace ) )
            {
                throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4188 ) );
            }

            reader.ReadStartElement( XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace );
            reader.ReadStartElement( XmlEncryptionConstants.Elements.CipherValue, XmlEncryptionConstants.Namespace );

            _cipherText = reader.ReadContentAsBase64();
            _iv         = null;

            // <CipherValue>
            reader.MoveToContent();           
            reader.ReadEndElement();

            
            // <CipherData>
            reader.MoveToContent();
            reader.ReadEndElement(); 
        }
        private static object DeserializeStruct(XmlDictionaryReader reader, Type targetType)
        {
            if (targetType.IsDefined(typeof(DataContractAttribute), false))
            {
                Dictionary<string, MemberInfo> dataMembers = GetDataMembers(targetType);
                object targetObject = Activator.CreateInstance(targetType);

                reader.ReadStartElement(XmlRpcProtocol.Struct);
                
                while( reader.NodeType != XmlNodeType.EndElement )
                {
                    string memberName;

                    reader.ReadStartElement(XmlRpcProtocol.Member);
                    reader.ReadStartElement(XmlRpcProtocol.Name);
                    memberName = reader.ReadContentAsString();
                    reader.ReadEndElement();
                    
                    reader.ReadStartElement(XmlRpcProtocol.Value);
                    reader.MoveToContent();
                    if (dataMembers.ContainsKey(memberName))
                    {
                        MemberInfo member = dataMembers[memberName];
                        if (member is PropertyInfo)
                        {
                            ((PropertyInfo)member).SetValue(
                                targetObject, 
                                Deserialize(reader, ((PropertyInfo)member).PropertyType), 
                                BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.NonPublic, 
                                null, null,
                                CultureInfo.CurrentCulture);
                        }
                        else if (member is FieldInfo)
                        {
                            ((FieldInfo)member).SetValue(
                                targetObject,
                                Deserialize(reader, ((FieldInfo)member).FieldType),
                                BindingFlags.Instance|BindingFlags.SetField|BindingFlags.Public|BindingFlags.NonPublic,
                                null,
                                CultureInfo.CurrentCulture);
                        }
                    }
                    reader.ReadEndElement(); // value
                    reader.ReadEndElement(); // member
                }
                reader.ReadEndElement(); // struct
                reader.MoveToContent();
                return targetObject;                
            }
            else
            {
                throw new InvalidOperationException();
            }
            
        }
        public void ReadXml( XmlDictionaryReader reader )
        {
            if ( reader == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
            }

            reader.MoveToContent();
            if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.EncryptionMethod, XmlEncryptionConstants.Namespace ) )
            {
                return;
            }

            _algorithm = reader.GetAttribute( XmlEncryptionConstants.Attributes.Algorithm, null );

            if ( !reader.IsEmptyElement )
            {
                //
                // Trace unread missing element
                //

                string xml = reader.ReadOuterXml();
                if ( DiagnosticUtility.ShouldTraceWarning )
                {
                    TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8024, reader.Name, reader.NamespaceURI, xml ) );
                }
            }
            else
            {
                //
                // Read to the next element
                //
                reader.Read();
            }
        }
 public XmlRpcMessage(MessageFault fault)
     : this()
 {
     isFault = true;
     bodyReader = XmlRpcDataContractSerializationHelper.CreateFaultReader(fault);
     bodyReader.MoveToContent();
 }
 public XmlRpcMessage(XmlDictionaryReader paramsSection)
     : this()
 {
     bodyReader = paramsSection;
     bodyReader.MoveToContent();
     isFault = false;
 }
示例#9
0
        public virtual void ReadXml( XmlDictionaryReader reader )
        {
            if ( reader == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
            }

            reader.MoveToContent();
            if ( reader.IsStartElement( XD.XmlSignatureDictionary.KeyInfo.Value, XD.XmlSignatureDictionary.Namespace.Value ) )
            {
                // <KeyInfo>
                reader.ReadStartElement();

                while ( reader.IsStartElement() )
                {
                    // <RetrievalMethod>
                    if ( reader.IsStartElement( XmlSignatureConstants.Elements.RetrievalMethod, XD.XmlSignatureDictionary.Namespace.Value ) )
                    {
                        string method = reader.GetAttribute( XD.XmlSignatureDictionary.URI.Value );
                        if ( !string.IsNullOrEmpty( method ) )
                        {
                            _retrieval = method;
                        }
                        reader.Skip();
                    }
                    // check if internal serializer can handle clause
                    else if ( _keyInfoSerializer.CanReadKeyIdentifierClause( reader ) )
                    {
                        _ski.Add( _keyInfoSerializer.ReadKeyIdentifierClause( reader ) );
                    }
                    // trace we skipped over an element
                    else if ( reader.IsStartElement() )
                    {
                        string xml = reader.ReadOuterXml();

                        if ( DiagnosticUtility.ShouldTraceWarning )
                        {
                            TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8023, reader.Name, reader.NamespaceURI, xml ) );
                        }
                    }
                    reader.MoveToContent();
                }

                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
示例#10
0
		public XmlReaderBodyWriter (XmlDictionaryReader reader)
			: base (false)
		{
			reader.MoveToContent ();
			if (reader.NodeType != XmlNodeType.Element)
				throw new InvalidOperationException ("Argument XmlReader is expected to be positioned at element");
			this.reader = reader;
		}
 public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
 {
     reader.MoveToContent();
     if (XmlHelper.ReadEmptyElementAndRequiredAttribute(reader, dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace, dictionaryManager.XmlSignatureDictionary.Algorithm, out this.prefix) != this.Algorithm)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("AlgorithmMismatchForTransform")));
     }
 }
 static PollingDuplexSession ReadHeaderValue(XmlDictionaryReader reader)
 {
     string str = null;
     string str2 = null;
     if (reader.IsStartElement("Duplex", "http://schemas.microsoft.com/2008/04/netduplex"))
     {
         reader.ReadStartElement();
         reader.MoveToContent();
         while (reader.IsStartElement())
         {
             if (reader.IsStartElement("SessionId", "http://schemas.microsoft.com/2008/04/netduplex"))
             {
                 if (!string.IsNullOrEmpty(str2))
                 {
                     throw new InvalidOperationException("Multiple sessionId elements in a duplex header.");
                 }
                 str2 = reader.ReadElementContentAsString();
                 if (string.IsNullOrEmpty(str2))
                 {
                     throw new InvalidOperationException("Invalid sessionId element content in a duplex header.");
                 }
             }
             else
             {
                 if (reader.IsStartElement("Address", "http://schemas.microsoft.com/2008/04/netduplex"))
                 {
                     if (!string.IsNullOrEmpty(str))
                     {
                         throw new InvalidOperationException("Multiple address elements in a duplex header.");
                     }
                     str = reader.ReadElementContentAsString();
                     if (string.IsNullOrEmpty(str))
                     {
                         throw new InvalidOperationException("Invalid address element in a duplex header.");
                     }
                     continue;
                 }
                 if (reader.IsStartElement("CloseSession", "http://schemas.microsoft.com/2008/04/netduplex"))
                 {
                     reader.Skip();
                     continue;
                 }
                 reader.Skip();
             }
         }
         reader.ReadEndElement();
     }
     if (str == null)
     {
         throw new InvalidOperationException("Missing address in a duplex header.");
     }
     if (str2 == null)
     {
         throw new InvalidOperationException("Missing sessionId in a duplex header.");
     }
     return new PollingDuplexSession(str, str2);
 }
 public XmlReaderBodyWriter(XmlDictionaryReader reader, EnvelopeVersion version) : base(false)
 {
     this.reader = reader;
     if (reader.MoveToContent() != XmlNodeType.Element)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("InvalidReaderPositionOnCreateMessage"), "reader"));
     }
     this.isFault = Message.IsFaultStartElement(reader, version);
 }
 public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(this.elementName, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     bool isEmptyElement = reader.IsEmptyElement;
     this.algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     if (this.algorithm == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("RequiredAttributeMissing", new object[] { dictionaryManager.XmlSignatureDictionary.Algorithm, this.elementName })));
     }
     reader.Read();
     reader.MoveToContent();
     if (!isEmptyElement)
     {
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
 /// <summary>
 /// Indicates whether this is the start of an object we are prepared to handle
 /// </summary>
 public override bool IsStartObject(System.Xml.XmlDictionaryReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     reader.MoveToContent();
     return(reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name == PROTO_ELEMENT);
 }
示例#16
0
        /// <summary>
        /// Reads the body of an object
        /// </summary>
        public override object ReadObject(System.Xml.XmlDictionaryReader reader, bool verifyObjectName)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            reader.MoveToContent();
            bool isSelfClosed = reader.IsEmptyElement, isNil = reader.GetAttribute("nil") == "true";

            reader.ReadStartElement(PROTO_ELEMENT);

            // explicitly null
            if (isNil)
            {
                if (!isSelfClosed)
                {
                    reader.ReadEndElement();
                }
                return(null);
            }
            if (isSelfClosed) // no real content
            {
                if (isList || isEnum)
                {
                    return(model.Deserialize(Stream.Null, null, type, null));
                }
                using (ProtoReader protoReader = new ProtoReader(Stream.Null, model, null))
                {
                    return(model.Deserialize(key, null, protoReader));
                }
            }

            object result;

            Helpers.DebugAssert(reader.CanReadBinaryContent, "CanReadBinaryContent");
            using (MemoryStream ms = new MemoryStream(reader.ReadContentAsBase64()))
            {
                if (isList || isEnum)
                {
                    result = model.Deserialize(ms, null, type, null);
                }
                else
                {
                    using (ProtoReader protoReader = new ProtoReader(ms, model, null))
                    {
                        result = model.Deserialize(key, null, protoReader);
                    }
                }
            }
            reader.ReadEndElement();
            return(result);
        }
 public StreamedMessage(XmlDictionaryReader reader, int maxSizeOfHeaders, MessageVersion desiredVersion)
 {
     if (reader.NodeType != XmlNodeType.Element)
     {
         reader.MoveToContent();
     }
     if (desiredVersion.Envelope == EnvelopeVersion.None)
     {
         this.reader = reader;
         this.headerAttributes = XmlAttributeHolder.emptyArray;
         this.headers = new MessageHeaders(desiredVersion);
     }
     else
     {
         this.envelopeAttributes = XmlAttributeHolder.ReadAttributes(reader, ref maxSizeOfHeaders);
         this.envelopePrefix = reader.Prefix;
         EnvelopeVersion envelopeVersion = ReceivedMessage.ReadStartEnvelope(reader);
         if (desiredVersion.Envelope != envelopeVersion)
         {
             Exception innerException = new ArgumentException(System.ServiceModel.SR.GetString("EncoderEnvelopeVersionMismatch", new object[] { envelopeVersion, desiredVersion.Envelope }), "reader");
             throw TraceUtility.ThrowHelperError(new CommunicationException(innerException.Message, innerException), this);
         }
         if (ReceivedMessage.HasHeaderElement(reader, envelopeVersion))
         {
             this.headerPrefix = reader.Prefix;
             this.headerAttributes = XmlAttributeHolder.ReadAttributes(reader, ref maxSizeOfHeaders);
             this.headers = new MessageHeaders(desiredVersion, reader, this.envelopeAttributes, this.headerAttributes, ref maxSizeOfHeaders);
         }
         else
         {
             this.headerAttributes = XmlAttributeHolder.emptyArray;
             this.headers = new MessageHeaders(desiredVersion);
         }
         if (reader.NodeType != XmlNodeType.Element)
         {
             reader.MoveToContent();
         }
         this.bodyPrefix = reader.Prefix;
         ReceivedMessage.VerifyStartBody(reader, envelopeVersion);
         this.bodyAttributes = XmlAttributeHolder.ReadAttributes(reader, ref maxSizeOfHeaders);
         if (base.ReadStartBody(reader))
         {
             this.reader = reader;
         }
         else
         {
             this.quotas = new XmlDictionaryReaderQuotas();
             reader.Quotas.CopyTo(this.quotas);
             reader.Close();
         }
     }
 }
示例#18
0
		public XmlReaderBodyWriter (string xml, int maxBufferSize, XmlParserContext ctx)
			: base (true)
		{
			var settings = new XmlReaderSettings () {
				// FIXME: enable this line (once MaxCharactersInDocument is implemented)
				// MaxCharactersInDocument = maxBufferSize,
				ConformanceLevel = ConformanceLevel.Fragment
				};
			reader = XmlDictionaryReader.CreateDictionaryReader (XmlReader.Create (new StringReader (xml), settings, ctx));
			reader.MoveToContent ();
			xml_bak = xml;
			parser_context = ctx;
		}
示例#19
0
 public virtual void ReadXml(XmlDictionaryReader reader)
 {
     if (reader == null)
     {
         throw DiagnosticUtil.ExceptionUtil.ThrowHelperArgumentNull("reader");
     }
     reader.MoveToContent();
     if (reader.IsStartElement("KeyInfo", "http://www.w3.org/2000/09/xmldsig#"))
     {
         reader.ReadStartElement();
         while (reader.IsStartElement())
         {
             if (reader.IsStartElement("RetrievalMethod", "http://www.w3.org/2000/09/xmldsig#"))
             {
                 string attribute = reader.GetAttribute("URI");
                 if (!string.IsNullOrEmpty(attribute))
                 {
                     this._retrieval = attribute;
                 }
                 reader.Skip();
             }
             else if (this._keyInfoSerializer.CanReadKeyIdentifierClause(reader))
             {
                 this._ski.Add(this._keyInfoSerializer.ReadKeyIdentifierClause(reader));
             }
             else if (reader.IsStartElement())
             {
                 string str2 = reader.ReadOuterXml();
                 //if (DiagnosticUtil.TraceUtil.ShouldTrace(TraceEventType.Warning))
                 //{
                 //    DiagnosticUtil.TraceUtil.TraceString(TraceEventType.Warning, SR.GetString("ID8023", new object[] { reader.Name, reader.NamespaceURI, str2 }), new object[0]);
                 //}
             }
             reader.MoveToContent();
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
        public static MakeConnectionMessageInfo Create(XmlDictionaryReader reader)
        {
            MakeConnectionMessageInfo makeConnectionInfo = new MakeConnectionMessageInfo();

            if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.Name, MakeConnectionConstants.Namespace))
            {
                reader.ReadStartElement();
                reader.MoveToContent();

                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.AddressElement, MakeConnectionConstants.Namespace))
                    {
                        if (!string.IsNullOrEmpty(makeConnectionInfo.Address))
                        {
                            makeConnectionInfo.MultipleAddressHeaders = true;
                            reader.Skip();
                        }
                        else
                        {
                            makeConnectionInfo.Address = reader.ReadElementContentAsString();
                        }
                    }
                    else if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.IdentifierElement, MakeConnectionConstants.Namespace))
                    {
                        if (makeConnectionInfo.Identifier != null)
                        {
                            makeConnectionInfo.MultipleIdentifierHeaders = true;
                            reader.Skip();
                        }
                        else
                        {
                            makeConnectionInfo.Identifier = reader.ReadElementContentAsUniqueId();
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(makeConnectionInfo.UnknownSelection))
                        {
                            makeConnectionInfo.UnknownSelection = reader.LocalName;
                        }

                        reader.Skip();
                    }
                }

                reader.ReadEndElement();
            }

            return makeConnectionInfo;
        }
        public override 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.ThrowHelperError(new ArgumentNullException("samlSerializer"));

#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
            SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;

            reader.MoveToContent();
            reader.Read();
            while (reader.IsStartElement())
            {
                if (reader.IsStartElement(dictionary.Audience, dictionary.Namespace))
                {
                    reader.MoveToContent();
                    string audience = reader.ReadString();
                    if (string.IsNullOrEmpty(audience))
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAudienceRestrictionInvalidAudienceValueOnRead)));

                    this.audiences.Add(new Uri(audience));
                    reader.MoveToContent();
                    reader.ReadEndElement();
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.AudienceRestrictionCondition.Value)));
                }
            }

            if (this.audiences.Count == 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAudienceRestrictionShouldHaveOneAudienceOnRead)));

            reader.MoveToContent();
            reader.ReadEndElement();
        }
 public override 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.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     reader.MoveToContent();
     reader.Read();
     while (reader.IsStartElement())
     {
         if (!reader.IsStartElement(samlDictionary.Audience, samlDictionary.Namespace))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.AudienceRestrictionCondition.Value })));
         }
         reader.MoveToContent();
         string str = reader.ReadString();
         if (string.IsNullOrEmpty(str))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAudienceRestrictionInvalidAudienceValueOnRead")));
         }
         this.audiences.Add(new Uri(str));
         reader.MoveToContent();
         reader.ReadEndElement();
     }
     if (this.audiences.Count == 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAudienceRestrictionShouldHaveOneAudienceOnRead")));
     }
     reader.MoveToContent();
     reader.ReadEndElement();
 }
 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.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     if (reader.IsStartElement(samlDictionary.Action, samlDictionary.Namespace))
     {
         this.ns = reader.GetAttribute(samlDictionary.ActionNamespaceAttribute, null);
         reader.MoveToContent();
         this.action = reader.ReadString();
         if (string.IsNullOrEmpty(this.action))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLActionNameRequiredOnRead")));
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
 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.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     if (reader.IsEmptyElement)
     {
         reader.MoveToContent();
         reader.Read();
     }
     else
     {
         reader.MoveToContent();
         reader.Read();
         while (reader.IsStartElement())
         {
             if (!reader.IsStartElement(samlDictionary.AssertionIdReference, samlDictionary.Namespace))
             {
                 if (!reader.IsStartElement(samlDictionary.Assertion, samlDictionary.Namespace))
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.Advice.Value })));
                 }
                 SamlAssertion item = new SamlAssertion();
                 item.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
                 this.assertions.Add(item);
             }
             else
             {
                 reader.MoveToContent();
                 this.assertionIdReferences.Add(reader.ReadString());
                 reader.MoveToContent();
                 reader.ReadEndElement();
                 continue;
             }
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
 public void ReadFrom(XmlDictionaryReader reader, TransformFactory transformFactory, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Transforms, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     reader.Read();
     while (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace))
     {
         string attribute = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
         Transform transform = transformFactory.CreateTransform(attribute);
         transform.ReadFrom(reader, dictionaryManager);
         this.Add(transform);
     }
     reader.MoveToContent();
     reader.ReadEndElement();
     if (this.TransformCount == 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("AtLeastOneTransformRequired")));
     }
 }
 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.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     string attribute = reader.GetAttribute(samlDictionary.NotBefore, null);
     if (!string.IsNullOrEmpty(attribute))
     {
         this.notBefore = DateTime.ParseExact(attribute, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime();
     }
     attribute = reader.GetAttribute(samlDictionary.NotOnOrAfter, null);
     if (!string.IsNullOrEmpty(attribute))
     {
         this.notOnOrAfter = DateTime.ParseExact(attribute, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime();
     }
     if (reader.IsEmptyElement)
     {
         reader.MoveToContent();
         reader.Read();
     }
     else
     {
         reader.MoveToContent();
         reader.Read();
         while (reader.IsStartElement())
         {
             SamlCondition item = samlSerializer.LoadCondition(reader, keyInfoSerializer, outOfBandTokenResolver);
             if (item == null)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLUnableToLoadCondtion")));
             }
             this.conditions.Add(item);
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
示例#27
0
		public override bool IsStartObject (XmlDictionaryReader reader)
		{
			if (reader == null)
				throw new ArgumentNullException ("reader");
			reader.MoveToContent ();
			return reader.IsStartElement (root_name, root_ns);
		}
 void MoveToSecurityHeader(XmlDictionaryReader reader, int headerIndex, bool captureAttributes)
 {
     MoveToHeaderBlock(reader, captureAttributes);
     reader.ReadStartElement();
     while (true)
     {
         if (reader.NodeType != XmlNodeType.Element)
         {
             reader.MoveToContent();
         }
         if (headerIndex == 0)
         {
             break;
         }
         reader.Skip();
         headerIndex--;
     }
 }
 void MoveToHeaderBlock(XmlDictionaryReader reader, bool captureAttributes)
 {
     if (reader.NodeType != XmlNodeType.Element)
     {
         reader.MoveToContent();
     }
     if (captureAttributes)
     {
         this.envelopePrefix = reader.Prefix;
         this.envelopeAttributes = XmlAttributeHolder.ReadAttributes(reader);
     }
     reader.ReadStartElement();
     reader.MoveToStartElement(XD.MessageDictionary.Header, this.Version.Envelope.DictionaryNamespace);
     if (captureAttributes)
     {
         this.headerAttributes = XmlAttributeHolder.ReadAttributes(reader);
     }
 }
 void MoveToBody(XmlDictionaryReader reader)
 {
     if (reader.NodeType != XmlNodeType.Element)
     {
         reader.MoveToContent();
     }
     reader.ReadStartElement();
     if (reader.IsStartElement(XD.MessageDictionary.Header, this.Version.Envelope.DictionaryNamespace))
     {
         reader.Skip();
     }
     if (reader.NodeType != XmlNodeType.Element)
     {
         reader.MoveToContent();
     }
 }
 /// <summary>
 /// Indicates whether this is the start of an object we are prepared to handle
 /// </summary>
 public override bool IsStartObject(System.Xml.XmlDictionaryReader reader)
 {
     reader.MoveToContent();
     return(reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name == PROTO_ELEMENT);
 }
 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();
 }
 internal X509CertificateEndpointIdentity(XmlDictionaryReader reader)
 {
     this.certificateCollection = new X509Certificate2Collection();
     if (reader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
     }
     reader.MoveToContent();
     if (reader.IsEmptyElement)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedEmptyElementExpectingClaim", new object[] { XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value })));
     }
     reader.ReadStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace);
     while (reader.IsStartElement(XD.XmlSignatureDictionary.X509Certificate, XD.XmlSignatureDictionary.Namespace))
     {
         X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(reader.ReadElementString()));
         if (this.certificateCollection.Count == 0)
         {
             base.Initialize(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
         }
         this.certificateCollection.Add(certificate);
     }
     reader.ReadEndElement();
     if (this.certificateCollection.Count == 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedEmptyElementExpectingClaim", new object[] { XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value })));
     }
 }