Exemple #1
0
        public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
        {
            XmlDictionaryString localName = this.isCanonicalizationMethod ? dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod : dictionaryManager.XmlSignatureDictionary.Transform;

            reader.MoveToStartElement(localName, dictionaryManager.XmlSignatureDictionary.Namespace);
            this.prefix = reader.Prefix;
            bool isEmptyElement = reader.IsEmptyElement;

            if (reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null) != this.Algorithm)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("AlgorithmMismatchForTransform")));
            }
            reader.Read();
            reader.MoveToContent();
            if (!isEmptyElement)
            {
                if (reader.IsStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace))
                {
                    reader.MoveToStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace);
                    this.inclusiveListElementPrefix = reader.Prefix;
                    bool flag2 = reader.IsEmptyElement;
                    this.InclusiveNamespacesPrefixList = reader.GetAttribute(dictionaryManager.ExclusiveC14NDictionary.PrefixList, null);
                    reader.Read();
                    if (!flag2)
                    {
                        reader.ReadEndElement();
                    }
                }
                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
        public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager, bool preserveComments)
        {
            XmlDictionaryString elementName = this.isCanonicalizationMethod ?
                                              dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod : dictionaryManager.XmlSignatureDictionary.Transform;

            reader.MoveToStartElement(elementName, dictionaryManager.XmlSignatureDictionary.Namespace);
            this.prefix = reader.Prefix;
            bool isEmptyElement = reader.IsEmptyElement;

            algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
            if (string.IsNullOrEmpty(algorithm))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.ID0001, dictionaryManager.XmlSignatureDictionary.Algorithm, reader.LocalName)));
            }

            if (algorithm == dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14nWithComments.Value)
            {
                // to include comments in canonicalization, two conditions need to be met
                // 1. the Reference must be an xpointer.
                // 2. the transform must be #withComments
                includeComments = preserveComments && true;
            }
            else if (algorithm == dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n.Value)
            {
                includeComments = false;
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.ID6005, algorithm)));
            }

            reader.Read();
            reader.MoveToContent();

            if (!isEmptyElement)
            {
                if (reader.IsStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace))
                {
                    reader.MoveToStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace);
                    this.inclusiveListElementPrefix = reader.Prefix;
                    bool emptyElement = reader.IsEmptyElement;
                    // We treat PrefixList as optional Attribute.
                    this.InclusiveNamespacesPrefixList = reader.GetAttribute(dictionaryManager.ExclusiveC14NDictionary.PrefixList, null);
                    reader.Read();
                    if (!emptyElement)
                    {
                        reader.ReadEndElement();
                    }
                }
                reader.MoveToContent();
                reader.ReadEndElement(); // Transform
            }
        }
Exemple #3
0
        // does not write start element or type attribute, writes other attributes and rest of content
        protected override void WriteContentsTo(XmlWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            if (_extension != null)

            {
                _extension.WriteTo(writer);
            }
            else if (_contentBuffer != null)
            {
                using (XmlDictionaryReader reader = _contentBuffer.GetReader(0))
                {
                    reader.MoveToStartElement();
                    if (!reader.IsEmptyElement)
                    {
                        reader.ReadStartElement();
                        while (reader.Depth >= 1 && reader.ReadState == ReadState.Interactive)
                        {
                            writer.WriteNode(reader, false);
                        }
                    }
                }
            }
        }
Exemple #4
0
 public void ReadFrom(XmlDictionaryReader reader, long maxBufferSize)
 {
     this.ValidateReadState();
     reader.MoveToStartElement(this.OpeningElementName, NamespaceUri);
     this.encoding = reader.GetAttribute(EncodingAttribute, null);
     this.id       = reader.GetAttribute(System.ServiceModel.XD.XmlEncryptionDictionary.Id, null) ?? System.ServiceModel.Security.SecurityUniqueId.Create().Value;
     this.wsuId    = reader.GetAttribute(System.ServiceModel.XD.XmlEncryptionDictionary.Id, System.ServiceModel.XD.UtilityDictionary.Namespace) ?? System.ServiceModel.Security.SecurityUniqueId.Create().Value;
     this.mimeType = reader.GetAttribute(MimeTypeAttribute, null);
     this.type     = reader.GetAttribute(TypeAttribute, null);
     this.ReadAdditionalAttributes(reader);
     reader.Read();
     if (reader.IsStartElement(EncryptionMethodElement.ElementName, NamespaceUri))
     {
         this.encryptionMethod.ReadFrom(reader);
     }
     if (this.tokenSerializer.CanReadKeyIdentifier(reader))
     {
         this.KeyIdentifier = this.tokenSerializer.ReadKeyIdentifier(reader);
     }
     reader.ReadStartElement(CipherDataElementName, NamespaceUri);
     reader.ReadStartElement(CipherValueElementName, NamespaceUri);
     if (maxBufferSize == 0L)
     {
         this.ReadCipherData(reader);
     }
     else
     {
         this.ReadCipherData(reader, maxBufferSize);
     }
     reader.ReadEndElement();
     reader.ReadEndElement();
     this.ReadAdditionalElements(reader);
     reader.ReadEndElement();
     this.State = EncryptionState.Read;
 }
Exemple #5
0
 public void ReadFrom(XmlDictionaryReader reader, long maxBufferSize)
 {
     this.ValidateReadState();
     reader.MoveToStartElement(this.OpeningElementName, EncryptedType.NamespaceUri);
     this.encoding = reader.GetAttribute(EncryptedType.EncodingAttribute, (XmlDictionaryString)null);
     this.id       = reader.GetAttribute(System.IdentityModel.XD.XmlEncryptionDictionary.Id, (XmlDictionaryString)null) ?? SecurityUniqueId.Create().Value;
     this.wsuId    = reader.GetAttribute(System.IdentityModel.XD.XmlEncryptionDictionary.Id, System.IdentityModel.XD.UtilityDictionary.Namespace) ?? SecurityUniqueId.Create().Value;
     this.mimeType = reader.GetAttribute(EncryptedType.MimeTypeAttribute, (XmlDictionaryString)null);
     this.type     = reader.GetAttribute(EncryptedType.TypeAttribute, (XmlDictionaryString)null);
     this.ReadAdditionalAttributes(reader);
     reader.Read();
     if (reader.IsStartElement(EncryptedType.EncryptionMethodElement.ElementName, EncryptedType.NamespaceUri))
     {
         this.encryptionMethod.ReadFrom(reader);
     }
     if (this.tokenSerializer.CanReadKeyIdentifier((XmlReader)reader))
     {
         XmlElement          xmlElement = (XmlElement)null;
         XmlDictionaryReader dictionaryReader;
         if (this.ShouldReadXmlReferenceKeyInfoClause)
         {
             xmlElement       = new XmlDocument().ReadNode((XmlReader)reader) as XmlElement;
             dictionaryReader = XmlDictionaryReader.CreateDictionaryReader((XmlReader) new XmlNodeReader((XmlNode)xmlElement));
         }
         else
         {
             dictionaryReader = reader;
         }
         try
         {
             this.KeyIdentifier = this.tokenSerializer.ReadKeyIdentifier((XmlReader)dictionaryReader);
         }
         catch (Exception ex)
         {
             if (Fx.IsFatal(ex) || !this.ShouldReadXmlReferenceKeyInfoClause)
             {
                 throw;
             }
             else
             {
                 this.keyIdentifier = this.ReadGenericXmlSecurityKeyIdentifier(XmlDictionaryReader.CreateDictionaryReader((XmlReader) new XmlNodeReader((XmlNode)xmlElement)), ex);
             }
         }
     }
     reader.ReadStartElement(EncryptedType.CipherDataElementName, EncryptedType.NamespaceUri);
     reader.ReadStartElement(EncryptedType.CipherValueElementName, EncryptedType.NamespaceUri);
     if (maxBufferSize == 0L)
     {
         this.ReadCipherData(reader);
     }
     else
     {
         this.ReadCipherData(reader, maxBufferSize);
     }
     reader.ReadEndElement();
     reader.ReadEndElement();
     this.ReadAdditionalElements(reader);
     reader.ReadEndElement();
     this.State = EncryptedType.EncryptionState.Read;
 }
 // does not write start element or type attribute, writes other attributes and rest of content
 protected override void WriteContentsTo(XmlWriter writer)
 {
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
     }
     if (this.extension != null)
     {
         this.extension.WriteTo(writer);
     }
     else if (this.contentBuffer != null)
     {
         using (XmlDictionaryReader reader = this.contentBuffer.GetReader(0))
         {
             reader.MoveToStartElement();
             if (!reader.IsEmptyElement)
             {
                 reader.ReadStartElement();
                 while (reader.Depth >= 1 && reader.ReadState == ReadState.Interactive)
                 {
                     writer.WriteNode(reader, false);
                 }
             }
         }
     }
 }
Exemple #7
0
        void CacheAllHeaderIds()
        {
            int crtHeaderPosition      = 0;
            XmlDictionaryReader reader = this.Message.Headers.GetReaderAtHeader(0);

            while (crtHeaderPosition < this.Message.Headers.Count)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.MoveToContent();
                }

                reader.MoveToStartElement();

                if (crtHeaderPosition != this.headerIndex)
                {
                    // Look if the header has an d:Id attribute.
                    // The headers's children are not of interest, because
                    // only top-level SOAP header blocks (/s:Envelope/s:Header/*) can be referenced.
                    string idValue = reader.GetAttribute(ProtocolStrings.IdAttributeName, this.DiscoveryInfo.DiscoveryNamespace);
                    if (!String.IsNullOrEmpty(idValue))
                    {
                        this.blockIds.AddHeader(idValue, crtHeaderPosition);
                    }
                }

                reader.Skip();
                crtHeaderPosition++;
            }

            reader.Close();
        }
Exemple #8
0
 private void ReadFrom(XmlDictionaryReader reader)
 {
     try
     {
         reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.Register, this.coordinationXmlDictionaryStrings.Namespace);
         reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.Protocol, this.coordinationXmlDictionaryStrings.Namespace);
         this.Protocol = WSAtomicTransactionStrings.WellKnownNameToProtocol(reader.ReadElementContentAsString().Trim(), this.protocolVersion);
         if (this.Protocol == ControlProtocol.None)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
         }
         this.ParticipantProtocolService = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(this.protocolVersion), reader, this.coordinationXmlDictionaryStrings.ParticipantProtocolService, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Loopback, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             this.Loopback = reader.ReadElementContentAsGuid();
         }
         while (reader.IsStartElement())
         {
             reader.Skip();
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
     }
 }
        /// <summary>
        /// Populates the ResourceObject from its full object definition
        /// </summary>
        /// <param name="reader">The XmlDictionaryReader containing the full object definition</param>
        private void PopulateResourceFromFullObject(XmlDictionaryReader reader)
        {
            Dictionary<string, List<string>> values = new Dictionary<string, List<string>>();

            reader.MoveToStartElement();

            string objectTypeName = reader.LocalName;
            this.ObjectType = ResourceManagementSchema.ObjectTypes[objectTypeName];

            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (!values.ContainsKey(reader.LocalName))
                {
                    values.Add(reader.LocalName, new List<string>());
                }

                string value = reader.ReadString();
                if (!string.IsNullOrEmpty(value))
                {
                    values[reader.LocalName].Add(value);
                }
            }

            this.SetInitialAttributeValues(values);
        }
        public DecryptedHeader(byte[] decryptedBuffer,
                               XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes,
                               MessageVersion version, SignatureTargetIdManager idManager, XmlDictionaryReaderQuotas quotas)
        {
            if (quotas == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("quotas");
            }

            this.decryptedBuffer    = decryptedBuffer;
            this.version            = version;
            this.envelopeAttributes = envelopeAttributes;
            this.headerAttributes   = headerAttributes;
            this.quotas             = quotas;

            XmlDictionaryReader reader = CreateReader();

            reader.MoveToStartElement();

            this.name         = reader.LocalName;
            this.namespaceUri = reader.NamespaceURI;
            MessageHeader.GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out this.isRefParam);
            this.id = idManager.ExtractId(reader);

            this.cachedReader = reader;
        }
Exemple #11
0
        public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager, bool preserveComments)
        {
            reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace);
            this.prefix = reader.Prefix;
            bool   isEmptyElement = reader.IsEmptyElement;
            string algorithm      = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);

            if (algorithm != this.Algorithm)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.AlgorithmMismatchForTransform)));
            }

            reader.MoveToContent();
            reader.Read();

            if (!isEmptyElement)
            {
                if (reader.IsStartElement(XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace))
                {
                    this.transformationParameters.ReadFrom(reader, dictionaryManager);
                }

                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            switch (this.state)
            {
            case BodyState.Created:
                this.InnerMessage.WriteBodyContents(writer);
                return;

            case BodyState.Signed:
                using (XmlDictionaryReader reader = Utility.CreateReader(this.fullBodyBuffer))
                {
                    reader.MoveToStartElement();
                    reader.ReadStartElement();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        writer.WriteNode(reader, false);
                    }

                    reader.ReadEndElement();
                }
                return;

            default:
                throw new ArgumentException("Can't write the message because it is in a bad or unknown state");
            }
        }
            public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver)
            {
                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);
                UniqueId contextId = reader.ReadElementContentAsUniqueId();

                if (CanReadGeneration(reader))
                {
                    generation = ReadGeneration(reader);
                }
                if (reader.IsStartElement(Parent.SerializerDictionary.Cookie, XD.DotNetSecurityDictionary.Namespace))
                {
                    isCookieMode = true;
                    sct          = TryResolveSecurityContextToken(contextId, generation, id, tokenResolver, out ISecurityContextSecurityTokenCache sctCache);
                    if (sct == null)
                    {
                        byte[] 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.Format(SR.NoSecurityContextIdentifier)));
                }

                if (sct == null && !isCookieMode)
                {
                    sct = TryResolveSecurityContextToken(contextId, generation, id, tokenResolver, out ISecurityContextSecurityTokenCache sctCache);
                }
                if (sct == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new Exception(SR.Format(SR.SecurityContextNotRegistered, contextId, generation)));
                }
                return(sct);
            }
Exemple #14
0
            public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver)
            {
                UniqueId generation = (UniqueId)null;
                string   attribute  = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);

                reader.ReadFullStartElement();
                reader.MoveToStartElement(this.parent.SerializerDictionary.Identifier, this.parent.SerializerDictionary.Namespace);
                UniqueId contextId = reader.ReadElementContentAsUniqueId();

                if (this.CanReadGeneration(reader))
                {
                    generation = this.ReadGeneration(reader);
                }
#if FEATURE_CORECLR
                throw new NotImplementedException("DotNetSecurityDictionary not implemented in .NET Core");
#else
                bool flag = false;
                SecurityContextSecurityToken token = (SecurityContextSecurityToken)null;
                if (reader.IsStartElement(this.parent.SerializerDictionary.Cookie, DotNetSecurityDictionary.Namespace))
                {
                    flag = true;
                    ISecurityContextSecurityTokenCache sctCache;
                    token = this.TryResolveSecurityContextToken(contextId, generation, attribute, tokenResolver, out sctCache);
                    if (token == null)
                    {
                        byte[] encodedCookie = reader.ReadElementContentAsBase64();
                        if (encodedCookie != null)
                        {
                            token = this.cookieSerializer.CreateSecurityContextFromCookie(encodedCookie, contextId, generation, attribute, reader.Quotas);
                            if (sctCache != null)
                            {
                                sctCache.AddContext(token);
                            }
                        }
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
                reader.ReadEndElement();
                if (contextId == (UniqueId)null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError((Exception) new MessageSecurityException(SR.GetString("NoSecurityContextIdentifier")));
                }
                if (token == null && !flag)
                {
                    ISecurityContextSecurityTokenCache sctCache;
                    token = this.TryResolveSecurityContextToken(contextId, generation, attribute, tokenResolver, out sctCache);
                }
                if (token == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning((Exception) new SecurityContextTokenValidationException(SR.GetString("SecurityContextNotRegistered", (object)contextId, (object)generation)));
                }
                return((SecurityToken)token);
#endif
            }
 public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.SignatureValue, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     this.Id     = reader.GetAttribute("Id", null);
     reader.Read();
     this.signatureText  = reader.ReadString();
     this.signatureValue = Convert.FromBase64String(this.signatureText.Trim());
     reader.ReadEndElement();
 }
            public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver)
            {
                UniqueId contextId = null;

                byte[]   encodedCookie             = null;
                UniqueId generation                = null;
                bool     flag                      = false;
                string   attribute                 = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);
                SecurityContextSecurityToken token = null;

                reader.ReadFullStartElement();
                reader.MoveToStartElement(this.parent.SerializerDictionary.Identifier, this.parent.SerializerDictionary.Namespace);
                contextId = reader.ReadElementContentAsUniqueId();
                if (this.CanReadGeneration(reader))
                {
                    generation = this.ReadGeneration(reader);
                }
                if (reader.IsStartElement(this.parent.SerializerDictionary.Cookie, XD.DotNetSecurityDictionary.Namespace))
                {
                    ISecurityContextSecurityTokenCache cache;
                    flag  = true;
                    token = this.TryResolveSecurityContextToken(contextId, generation, attribute, tokenResolver, out cache);
                    if (token == null)
                    {
                        encodedCookie = reader.ReadElementContentAsBase64();
                        if (encodedCookie != null)
                        {
                            token = this.cookieSerializer.CreateSecurityContextFromCookie(encodedCookie, contextId, generation, attribute, reader.Quotas);
                            if (cache != null)
                            {
                                cache.AddContext(token);
                            }
                        }
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
                reader.ReadEndElement();
                if (contextId == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("NoSecurityContextIdentifier")));
                }
                if ((token == null) && !flag)
                {
                    ISecurityContextSecurityTokenCache cache2;
                    token = this.TryResolveSecurityContextToken(contextId, generation, attribute, tokenResolver, out cache2);
                }
                if (token == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityContextTokenValidationException(System.ServiceModel.SR.GetString("SecurityContextNotRegistered", new object[] { contextId, generation })));
                }
                return(token);
            }
        public void ReadFrom(XmlDictionaryReader reader, long maxBufferSize)
        {
            bool flag;

            reader.MoveToStartElement(ElementName, NamespaceUri);
            MessageHeader.GetHeaderAttributes(reader, this.version, out this.actor, out this.mustUnderstand, out this.relay, out flag);
            this.id = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);
            reader.ReadStartElement();
            this.encryptedData.ReadFrom(reader, maxBufferSize);
            reader.ReadEndElement();
        }
 public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.DigestValue, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     reader.Read();
     reader.MoveToContent();
     this.digestText  = reader.ReadString();
     this.digestValue = Convert.FromBase64String(this.digestText.Trim());
     reader.MoveToContent();
     reader.ReadEndElement();
 }
        private void ReadFrom(XmlDictionaryReader reader)
        {
            try
            {
                reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.CreateCoordinationContext, this.coordinationXmlDictionaryStrings.Namespace);
                if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.Expires, this.coordinationXmlDictionaryStrings.Namespace))
                {
                    int num = reader.ReadElementContentAsInt();
                    if (num < 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
                    }
                    this.expiration     = (uint)num;
                    this.expiresPresent = true;
                }
                if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace))
                {
                    this.CurrentContext = CoordinationContext.ReadFrom(reader, this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace, this.protocolVersion);
                }
                reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.CoordinationType, this.coordinationXmlDictionaryStrings.Namespace);
                if (reader.ReadElementContentAsString().Trim() != this.atomicTransactionStrings.Namespace)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
                }
                if (!reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
                {
                    goto Label_016B;
                }
                this.IsolationLevel = (System.Transactions.IsolationLevel)reader.ReadElementContentAsInt();
                if (((this.IsolationLevel >= System.Transactions.IsolationLevel.Serializable) && (this.IsolationLevel <= System.Transactions.IsolationLevel.Unspecified)) && (this.IsolationLevel != System.Transactions.IsolationLevel.Snapshot))
                {
                    goto Label_016B;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
Label_0165:
                reader.Skip();
Label_016B:
                if (reader.IsStartElement())
                {
                    goto Label_0165;
                }
                reader.ReadEndElement();
            }
            catch (XmlException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
            }
            catch (InvalidCoordinationContextException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception2));
            }
        }
Exemple #20
0
            internal override ISignatureValueSecurityElement ReadSignatureConfirmation(XmlDictionaryReader reader)
            {
                reader.MoveToStartElement(XD.SecurityXXX2005Dictionary.SignatureConfirmation, XD.SecurityXXX2005Dictionary.Namespace);
                bool   isEmptyElement = reader.IsEmptyElement;
                string id             = XmlHelper.GetRequiredNonEmptyAttribute(reader, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);

                byte[] signatureValue = XmlHelper.GetRequiredBase64Attribute(reader, XD.SecurityXXX2005Dictionary.ValueAttribute, null);
                reader.ReadStartElement();
                if (!isEmptyElement)
                {
                    reader.ReadEndElement();
                }
                return(new SignatureConfirmationElement(id, signatureValue, this));
            }
 public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Signature, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     this.Id     = reader.GetAttribute(dictionaryManager.UtilityDictionary.IdAttribute, null);
     reader.Read();
     this.signedInfo.ReadFrom(reader, this.signedXml.TransformFactory, dictionaryManager);
     this.signatureValueElement.ReadFrom(reader, dictionaryManager);
     if (this.signedXml.SecurityTokenSerializer.CanReadKeyIdentifier(reader))
     {
         this.keyIdentifier = this.signedXml.SecurityTokenSerializer.ReadKeyIdentifier(reader);
     }
     reader.ReadEndElement();
 }
            internal override SecurityTimestamp ReadTimestamp(XmlDictionaryReader reader, string digestAlgorithm, SignatureResourcePool resourcePool)
            {
                bool       canonicalize = digestAlgorithm != null && reader.CanCanonicalize;
                HashStream hashStream   = null;

                reader.MoveToStartElement(XD.UtilityDictionary.Timestamp, XD.UtilityDictionary.Namespace);
                if (canonicalize)
                {
                    hashStream = resourcePool.TakeHashStream(digestAlgorithm);
                    reader.StartCanonicalization(hashStream, false, null);
                }
                string id = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);

                reader.ReadStartElement();

                reader.ReadStartElement(XD.UtilityDictionary.CreatedElement, XD.UtilityDictionary.Namespace);
                DateTime creationTimeUtc = reader.ReadContentAsDateTime().ToUniversalTime();

                reader.ReadEndElement();

                DateTime expiryTimeUtc;

                if (reader.IsStartElement(XD.UtilityDictionary.ExpiresElement, XD.UtilityDictionary.Namespace))
                {
                    reader.ReadStartElement();
                    expiryTimeUtc = reader.ReadContentAsDateTime().ToUniversalTime();
                    reader.ReadEndElement();
                }
                else
                {
                    expiryTimeUtc = SecurityUtils.MaxUtcDateTime;
                }

                reader.ReadEndElement();

                byte[] digest;
                if (canonicalize)
                {
                    reader.EndCanonicalization();
                    digest = hashStream.FlushHashAndGetValue();
                }
                else
                {
                    digest = null;
                }
                return(new SecurityTimestamp(creationTimeUtc, expiryTimeUtc, id, digestAlgorithm, digest));
            }
Exemple #23
0
        public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
        {
            reader.MoveToContent();
            reader.MoveToStartElement(XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace);
            string prefix = reader.Prefix;

            bool skipReadingTransformEnd = reader.IsEmptyElement;

            reader.ReadStartElement();

            if (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, dictionaryManager.XmlSignatureDictionary.Namespace))
            {
                string algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                // Canonicalization Method can be empty.
                // <elementNOTempty></elementNOTempty>
                // <elementEmpty/>
                bool skipReadingC14End = reader.IsEmptyElement;

                reader.ReadStartElement();

                if (algorithm == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(
                                                                                  SR.GetString(SR.RequiredAttributeMissing, dictionaryManager.XmlSignatureDictionary.Algorithm, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod)));
                }

                if (algorithm != this.CanonicalizationAlgorithm)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.AlgorithmMismatchForTransform)));
                }


                // ReadEndElement() called only if element was not empty
                if (!skipReadingC14End)
                {
                    reader.MoveToContent();
                    reader.ReadEndElement();
                }
            }

            // If it was empty, don't read endElement as it was read in ReadStartElement
            if (!skipReadingTransformEnd)
            {
                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
 public void ReadFrom(XmlDictionaryReader reader, TransformFactory transformFactory, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Reference, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     this.Id     = reader.GetAttribute("Id", null);
     this.Uri    = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.URI, null);
     this.Type   = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Type, null);
     reader.Read();
     if (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.Transforms, dictionaryManager.XmlSignatureDictionary.Namespace))
     {
         this.transformChain.ReadFrom(reader, transformFactory, dictionaryManager);
     }
     this.digestMethodElement.ReadFrom(reader, dictionaryManager);
     this.digestValueElement.ReadFrom(reader, dictionaryManager);
     reader.MoveToContent();
     reader.ReadEndElement();
 }
        /// <summary>
        /// Populates the ResourceObject from its full object definition received from a Get request
        /// </summary>
        /// <param name="reader">The XmlDictionaryReader containing the full object definition</param>
        private void PopulateResourceFromFullObject(XmlDictionaryReader reader)
        {
            Dictionary <string, List <string> >      values      = new Dictionary <string, List <string> >();
            Dictionary <string, AttributePermission> permissions = new Dictionary <string, AttributePermission>();

            reader.MoveToStartElement();

            string objectTypeName = reader.LocalName;

            this.ObjectType = ResourceManagementSchema.GetObjectType(objectTypeName);

            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (!values.ContainsKey(reader.LocalName))
                {
                    values.Add(reader.LocalName, new List <string>());
                }

                AttributePermission p;
                if (Enum.TryParse(reader.GetAttribute("permissions", Namespaces.ResourceManagement), out p))
                {
                    if (!permissions.ContainsKey(reader.LocalName))
                    {
                        permissions.Add(reader.LocalName, p);
                    }
                    else
                    {
                        permissions[reader.LocalName] = p;
                    }
                }

                string value = reader.ReadString();
                if (!string.IsNullOrEmpty(value))
                {
                    values[reader.LocalName].Add(value);
                }
            }

            this.SetInitialAttributeValues(values, permissions);
        }
Exemple #26
0
        private static WsatRegistrationHeader ReadFrom(XmlDictionaryReader reader)
        {
            string str;
            string str2;

            reader.ReadFullStartElement(XD.DotNetAtomicTransactionExternalDictionary.RegisterInfo, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
            reader.MoveToStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
            Guid transactionId = reader.ReadElementContentAsGuid();

            if (transactionId == Guid.Empty)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderTransactionId")));
            }
            if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.ContextId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
            {
                Uri uri;
                str = reader.ReadElementContentAsString().Trim();
                if (((str.Length == 0) || (str.Length > 0x100)) || !Uri.TryCreate(str, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderIdentifier")));
                }
            }
            else
            {
                str = null;
            }
            if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.TokenId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
            {
                str2 = reader.ReadElementContentAsString().Trim();
                if (str2.Length == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderTokenId")));
                }
            }
            else
            {
                str2 = null;
            }
            while (reader.IsStartElement())
            {
                reader.Skip();
            }
            reader.ReadEndElement();
            return(new WsatRegistrationHeader(transactionId, str, str2));
        }
Exemple #27
0
 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);
     }
 }
        internal static string ReadEmptyElementAndRequiredAttribute(XmlDictionaryReader reader, XmlDictionaryString name, XmlDictionaryString namespaceUri, XmlDictionaryString attributeName, out string prefix)
        {
            reader.MoveToStartElement(name, namespaceUri);
            prefix = reader.Prefix;
            bool   isEmptyElement = reader.IsEmptyElement;
            string attribute      = reader.GetAttribute(attributeName, null);

            if (attribute == null)
            {
                OnRequiredAttributeMissing(attributeName.Value, null);
            }
            reader.Read();
            if (!isEmptyElement)
            {
                reader.ReadEndElement();
            }
            return(attribute);
        }
Exemple #29
0
 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 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();
            }
        }