Ejemplo n.º 1
0
        public override void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode)
        {
            bool primarySignatureFound = false;

            for (int position = 0; position < elementManager.Count; position++)
            {
                elementManager.GetElementEntry(position, out ReceiveSecurityHeaderEntry entry);
                if (entry.elementCategory == ReceiveSecurityHeaderElementCategory.Signature)
                {
                    if (!messageSecurityMode)
                    {
                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Endorsing);
                        continue;
                    }
                    SignedXml signedXml = (SignedXml)entry.element;

                    SignedInfo signedInfo       = signedXml.Signature.SignedInfo;
                    bool       targetsSignature = false;
                    if (signedInfo.References.Count == 1)
                    {
                        Reference signedXmlReference = (Reference)signedInfo.References[0];
                        string    uri = signedXmlReference.Uri;
                        string    id;
                        if (uri != null && uri.Length > 1 && uri[0] == '#')
                        {
                            id = uri.Substring(1);
                        }
                        else
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                      new MessageSecurityException(SR.Format(SR.UnableToResolveReferenceUriForSignature, uri)));
                        }
                        for (int j = 0; j < elementManager.Count; j++)
                        {
                            elementManager.GetElementEntry(j, out ReceiveSecurityHeaderEntry 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.Format(SR.AtMostOnePrimarySignatureInReceiveSecurityHeader)));
                        }
                        primarySignatureFound = true;
                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Primary);
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode)
        {
            bool primarySignatureFound = false;

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