public override void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode)
        {
            bool primarySignatureFound = false;

            for (int position = 0; position < elementManager.Count; position++)
            {
                ReceiveSecurityHeaderEntry entry;
                elementManager.GetElementEntry(position, out entry);
                if (entry.elementCategory == ReceiveSecurityHeaderElementCategory.Signature)
                {
                    if (!messageSecurityMode)
                    {
                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Endorsing);
                        continue;
                    }
                    SignedXml          signedXml  = (SignedXml)entry.element;
                    StandardSignedInfo signedInfo = (StandardSignedInfo)signedXml.Signature.SignedInfo;
                    bool targetsSignature         = false;
                    if (signedInfo.ReferenceCount == 1)
                    {
                        string uri = signedInfo[0].Uri;
                        string id;
                        if (uri != null && uri.Length > 1 && uri[0] == '#')
                        {
                            id = uri.Substring(1);
                        }
                        else
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                      new MessageSecurityException(SR.GetString(SR.UnableToResolveReferenceUriForSignature, uri)));
                        }
                        for (int j = 0; j < elementManager.Count; j++)
                        {
                            ReceiveSecurityHeaderEntry inner;
                            elementManager.GetElementEntry(j, out inner);
                            if (j != position && inner.elementCategory == ReceiveSecurityHeaderElementCategory.Signature && inner.id == id)
                            {
                                targetsSignature = true;
                                break;
                            }
                        }
                    }
                    if (targetsSignature)
                    {
                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Endorsing);
                        continue;
                    }
                    else
                    {
                        if (primarySignatureFound)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.AtMostOnePrimarySignatureInReceiveSecurityHeader)));
                        }
                        primarySignatureFound = true;
                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Primary);
                        continue;
                    }
                }
            }
        }
 protected ReceiveSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay,
                                 SecurityStandardsManager standardsManager,
                                 SecurityAlgorithmSuite algorithmSuite,
                                 int headerIndex,
                                 MessageDirection direction)
     : base(message, actor, mustUnderstand, relay, standardsManager, algorithmSuite, direction)
 {
     HeaderIndex    = headerIndex;
     ElementManager = new ReceiveSecurityHeaderElementManager(this);
 }
 public override void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode)
 {
     for (int i = 1; i < elementManager.Count; i++)
     {
         if (elementManager.GetElementCategory(i) == ReceiveSecurityHeaderElementCategory.Timestamp)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("TimestampMustOccurFirstInSecurityHeaderLayout")));
         }
     }
     base.MarkElements(elementManager, messageSecurityMode);
 }
Beispiel #4
0
        public override void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode)
        {
            bool flag = false;

            for (int i = 0; i < elementManager.Count; i++)
            {
                ReceiveSecurityHeaderEntry entry;
                elementManager.GetElementEntry(i, out entry);
                if (entry.elementCategory == ReceiveSecurityHeaderElementCategory.Signature)
                {
                    if (!messageSecurityMode)
                    {
                        elementManager.SetBindingMode(i, ReceiveSecurityHeaderBindingModes.Endorsing);
                        continue;
                    }
                    SignedXml          element    = (SignedXml)entry.element;
                    StandardSignedInfo signedInfo = (StandardSignedInfo)element.Signature.SignedInfo;
                    bool flag2 = false;
                    if (signedInfo.ReferenceCount == 1)
                    {
                        string uri = signedInfo[0].Uri;
                        if (((uri == null) || (uri.Length <= 1)) || (uri[0] != '#'))
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("UnableToResolveReferenceUriForSignature", new object[] { uri })));
                        }
                        string str2 = uri.Substring(1);
                        for (int j = 0; j < elementManager.Count; j++)
                        {
                            ReceiveSecurityHeaderEntry entry2;
                            elementManager.GetElementEntry(j, out entry2);
                            if (((j != i) && (entry2.elementCategory == ReceiveSecurityHeaderElementCategory.Signature)) && (entry2.id == str2))
                            {
                                flag2 = true;
                                break;
                            }
                        }
                    }
                    if (flag2)
                    {
                        elementManager.SetBindingMode(i, ReceiveSecurityHeaderBindingModes.Endorsing);
                    }
                    else
                    {
                        if (flag)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("AtMostOnePrimarySignatureInReceiveSecurityHeader")));
                        }
                        flag = true;
                        elementManager.SetBindingMode(i, ReceiveSecurityHeaderBindingModes.Primary);
                    }
                }
            }
        }
        public override void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode)
        {
            bool flag = false;

            for (int i = 0; i < elementManager.Count; i++)
            {
                ReceiveSecurityHeaderEntry entry;
                elementManager.GetElementEntry(i, out entry);
                if (entry.elementCategory == ReceiveSecurityHeaderElementCategory.Signature)
                {
                    if (!messageSecurityMode || flag)
                    {
                        elementManager.SetBindingMode(i, ReceiveSecurityHeaderBindingModes.Endorsing);
                    }
                    else
                    {
                        elementManager.SetBindingMode(i, ReceiveSecurityHeaderBindingModes.Primary);
                        flag = true;
                    }
                }
            }
        }
        public override void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode)
        {
            bool primarySignatureFound = false;

            for (int position = 0; position < elementManager.Count; position++)
            {
                ReceiveSecurityHeaderEntry entry;
                elementManager.GetElementEntry(position, out entry);
                if (entry._elementCategory == ReceiveSecurityHeaderElementCategory.Signature)
                {
                    if (!messageSecurityMode || primarySignatureFound)
                    {
                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Endorsing);
                    }
                    else
                    {
                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Primary);
                        primarySignatureFound = true;
                    }
                }
            }
        }
 public abstract void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode);