void CreateSecurityProtocolFactory() { SecurityProtocolFactory incomingProtocolFactory; SecurityProtocolFactory outgoingProtocolFactory; ChannelProtectionRequirements protectionRequirements; lock (ThisLock) { if (null != securityProtocolFactory) { return; } TimeoutHelper timeoutHelper = new TimeoutHelper(ServiceDefaults.SendTimeout); if (!enableSigning) { outgoingProtocolFactory = new PeerDoNothingSecurityProtocolFactory(); incomingProtocolFactory = new PeerDoNothingSecurityProtocolFactory(); } else { X509Certificate2 cert = credManager.Certificate; if (cert != null) { SecurityBindingElement securityBindingElement = SecurityBindingElement.CreateCertificateSignatureBindingElement(); securityBindingElement.ReaderQuotas = this.readerQuotas; BindingParameterCollection bpc = new BindingParameterCollection(); if (protection == null) { protectionRequirements = new ChannelProtectionRequirements(); } else { protectionRequirements = new ChannelProtectionRequirements(protection); } ApplySigningRequirements(protectionRequirements.IncomingSignatureParts); ApplySigningRequirements(protectionRequirements.OutgoingSignatureParts); bpc.Add(protectionRequirements); bpc.Add(this.auditBehavior); bpc.Add(credManager); BindingContext context = new BindingContext(new CustomBinding(securityBindingElement), bpc); outgoingProtocolFactory = securityBindingElement.CreateSecurityProtocolFactory <IOutputChannel>(context, credManager, false, null); } else { outgoingProtocolFactory = new PeerDoNothingSecurityProtocolFactory(); } SecurityTokenResolver resolver; X509SecurityTokenAuthenticator auth = tokenManager.CreateSecurityTokenAuthenticator(PeerSecurityCredentialsManager.PeerClientSecurityTokenManager.CreateRequirement(SecurityTokenTypes.X509Certificate, true), out resolver) as X509SecurityTokenAuthenticator; if (auth != null) { SecurityBindingElement securityBindingElement = SecurityBindingElement.CreateCertificateSignatureBindingElement(); securityBindingElement.ReaderQuotas = this.readerQuotas; BindingParameterCollection bpc = new BindingParameterCollection(); if (protection == null) { protectionRequirements = new ChannelProtectionRequirements(); } else { protectionRequirements = new ChannelProtectionRequirements(protection); } ApplySigningRequirements(protectionRequirements.IncomingSignatureParts); ApplySigningRequirements(protectionRequirements.OutgoingSignatureParts); bpc.Add(protectionRequirements); bpc.Add(this.auditBehavior); bpc.Add(credManager); BindingContext context = new BindingContext(new CustomBinding(securityBindingElement), bpc); incomingProtocolFactory = securityBindingElement.CreateSecurityProtocolFactory <IOutputChannel>(context, credManager, true, null); } else { incomingProtocolFactory = new PeerDoNothingSecurityProtocolFactory(); } } DuplexSecurityProtocolFactory tempFactory = new DuplexSecurityProtocolFactory(outgoingProtocolFactory, incomingProtocolFactory); tempFactory.Open(true, timeoutHelper.RemainingTime()); securityProtocolFactory = tempFactory; } }
private void CreateSecurityProtocolFactory() { lock (this.ThisLock) { if (this.securityProtocolFactory == null) { SecurityProtocolFactory factory; SecurityProtocolFactory factory2; TimeoutHelper helper = new TimeoutHelper(ServiceDefaults.SendTimeout); if (!this.enableSigning) { factory2 = new PeerDoNothingSecurityProtocolFactory(); factory = new PeerDoNothingSecurityProtocolFactory(); } else { ChannelProtectionRequirements requirements; SecurityTokenResolver resolver; if (this.credManager.Certificate != null) { SecurityBindingElement element = SecurityBindingElement.CreateCertificateSignatureBindingElement(); element.ReaderQuotas = this.readerQuotas; BindingParameterCollection parameters = new BindingParameterCollection(); if (this.protection == null) { requirements = new ChannelProtectionRequirements(); } else { requirements = new ChannelProtectionRequirements(this.protection); } this.ApplySigningRequirements(requirements.IncomingSignatureParts); this.ApplySigningRequirements(requirements.OutgoingSignatureParts); parameters.Add(requirements); parameters.Add(this.auditBehavior); parameters.Add(this.credManager); BindingContext context = new BindingContext(new CustomBinding(new BindingElement[] { element }), parameters); factory2 = element.CreateSecurityProtocolFactory <IOutputChannel>(context, this.credManager, false, null); } else { factory2 = new PeerDoNothingSecurityProtocolFactory(); } if (this.tokenManager.CreateSecurityTokenAuthenticator(PeerSecurityCredentialsManager.PeerClientSecurityTokenManager.CreateRequirement(SecurityTokenTypes.X509Certificate, true), out resolver) is X509SecurityTokenAuthenticator) { SecurityBindingElement element2 = SecurityBindingElement.CreateCertificateSignatureBindingElement(); element2.ReaderQuotas = this.readerQuotas; BindingParameterCollection parameters2 = new BindingParameterCollection(); if (this.protection == null) { requirements = new ChannelProtectionRequirements(); } else { requirements = new ChannelProtectionRequirements(this.protection); } this.ApplySigningRequirements(requirements.IncomingSignatureParts); this.ApplySigningRequirements(requirements.OutgoingSignatureParts); parameters2.Add(requirements); parameters2.Add(this.auditBehavior); parameters2.Add(this.credManager); BindingContext context2 = new BindingContext(new CustomBinding(new BindingElement[] { element2 }), parameters2); factory = element2.CreateSecurityProtocolFactory <IOutputChannel>(context2, this.credManager, true, null); } else { factory = new PeerDoNothingSecurityProtocolFactory(); } } DuplexSecurityProtocolFactory factory3 = new DuplexSecurityProtocolFactory(factory2, factory); factory3.Open(true, helper.RemainingTime()); this.securityProtocolFactory = factory3; } } }