public virtual XmlElement CreateWsspBootstrapPolicyAssertion(MetadataExporter exporter, SecurityBindingElement bootstrapSecurity)
        {
            if (bootstrapSecurity == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bootstrapBinding");

            WSSecurityPolicy sp = WSSecurityPolicy.GetSecurityPolicyDriver(bootstrapSecurity.MessageSecurityVersion);

            // create complete bootstrap binding

            CustomBinding bootstrapBinding = new CustomBinding(bootstrapSecurity);
            if (exporter.State.ContainsKey(SecurityPolicyStrings.SecureConversationBootstrapBindingElementsBelowSecurityKey))
            {
                BindingElementCollection bindingElementsBelowSecurity = exporter.State[SecurityPolicyStrings.SecureConversationBootstrapBindingElementsBelowSecurityKey] as BindingElementCollection;
                if (bindingElementsBelowSecurity != null)
                {
                    foreach (BindingElement be in bindingElementsBelowSecurity)
                    {
                        bootstrapBinding.Elements.Add(be);
                    }
                }
            }

            // generate policy for the "how" of security 

            ServiceEndpoint bootstrapEndpoint = new ServiceEndpoint(NullContract);
            bootstrapEndpoint.Binding = bootstrapBinding;
            PolicyConversionContext policyContext = exporter.ExportPolicy(bootstrapEndpoint);

            // generate policy for the "what" of security (protection assertions)

            // hard-coded requirements in V1: sign and encrypt RST and RSTR body
            ChannelProtectionRequirements bootstrapProtection = new ChannelProtectionRequirements();
            bootstrapProtection.IncomingEncryptionParts.AddParts(new MessagePartSpecification(true));
            bootstrapProtection.OutgoingEncryptionParts.AddParts(new MessagePartSpecification(true));
            bootstrapProtection.IncomingSignatureParts.AddParts(new MessagePartSpecification(true));
            bootstrapProtection.OutgoingSignatureParts.AddParts(new MessagePartSpecification(true));

            // add boostrap binding protection requirements (e.g. addressing headers)
            ChannelProtectionRequirements cpr = bootstrapBinding.GetProperty<ChannelProtectionRequirements>(new BindingParameterCollection());
            if (cpr != null)
            {
                bootstrapProtection.Add(cpr);
            }

            // extract channel-scope protection requirements and union them across request and response
            MessagePartSpecification encryption = new MessagePartSpecification();
            encryption.Union(bootstrapProtection.IncomingEncryptionParts.ChannelParts);
            encryption.Union(bootstrapProtection.OutgoingEncryptionParts.ChannelParts);
            encryption.MakeReadOnly();
            MessagePartSpecification signature = new MessagePartSpecification();
            signature.Union(bootstrapProtection.IncomingSignatureParts.ChannelParts);
            signature.Union(bootstrapProtection.OutgoingSignatureParts.ChannelParts);
            signature.MakeReadOnly();

            // create final boostrap policy assertion

            XmlElement nestedPolicy = CreateWspPolicyWrapper(
                    exporter,
                    sp.CreateWsspSignedPartsAssertion(signature),
                    sp.CreateWsspEncryptedPartsAssertion(encryption));
            foreach (XmlElement e in sp.FilterWsspPolicyAssertions(policyContext.GetBindingAssertions()))
            {
                nestedPolicy.AppendChild(e);
            }
            XmlElement result = CreateWsspAssertion(BootstrapPolicyName);
            result.AppendChild(nestedPolicy);

            return result;
        }
 public virtual XmlElement CreateWsspBootstrapPolicyAssertion(MetadataExporter exporter, SecurityBindingElement bootstrapSecurity)
 {
     if (bootstrapSecurity == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bootstrapBinding");
     }
     WSSecurityPolicy securityPolicyDriver = GetSecurityPolicyDriver(bootstrapSecurity.MessageSecurityVersion);
     CustomBinding binding = new CustomBinding(new BindingElement[] { bootstrapSecurity });
     if (exporter.State.ContainsKey("SecureConversationBootstrapBindingElementsBelowSecurityKey"))
     {
         BindingElementCollection elements = exporter.State["SecureConversationBootstrapBindingElementsBelowSecurityKey"] as BindingElementCollection;
         if (elements != null)
         {
             foreach (BindingElement element in elements)
             {
                 binding.Elements.Add(element);
             }
         }
     }
     ServiceEndpoint endpoint = new ServiceEndpoint(NullContract) {
         Binding = binding
     };
     PolicyConversionContext context = exporter.ExportPolicy(endpoint);
     ChannelProtectionRequirements requirements = new ChannelProtectionRequirements();
     requirements.IncomingEncryptionParts.AddParts(new MessagePartSpecification(true));
     requirements.OutgoingEncryptionParts.AddParts(new MessagePartSpecification(true));
     requirements.IncomingSignatureParts.AddParts(new MessagePartSpecification(true));
     requirements.OutgoingSignatureParts.AddParts(new MessagePartSpecification(true));
     ChannelProtectionRequirements property = binding.GetProperty<ChannelProtectionRequirements>(new BindingParameterCollection());
     if (property != null)
     {
         requirements.Add(property);
     }
     MessagePartSpecification parts = new MessagePartSpecification();
     parts.Union(requirements.IncomingEncryptionParts.ChannelParts);
     parts.Union(requirements.OutgoingEncryptionParts.ChannelParts);
     parts.MakeReadOnly();
     MessagePartSpecification specification2 = new MessagePartSpecification();
     specification2.Union(requirements.IncomingSignatureParts.ChannelParts);
     specification2.Union(requirements.OutgoingSignatureParts.ChannelParts);
     specification2.MakeReadOnly();
     XmlElement newChild = this.CreateWspPolicyWrapper(exporter, new XmlElement[] { securityPolicyDriver.CreateWsspSignedPartsAssertion(specification2), securityPolicyDriver.CreateWsspEncryptedPartsAssertion(parts) });
     foreach (XmlElement element3 in securityPolicyDriver.FilterWsspPolicyAssertions(context.GetBindingAssertions()))
     {
         newChild.AppendChild(element3);
     }
     XmlElement element4 = this.CreateWsspAssertion("BootstrapPolicy");
     element4.AppendChild(newChild);
     return element4;
 }