public static SecurityTokenAuthenticator GetCertificateTokenAuthenticator(SecurityTokenManager tokenManager, string transportScheme, Uri listenUri) { RecipientServiceModelSecurityTokenRequirement clientAuthRequirement = new RecipientServiceModelSecurityTokenRequirement(); clientAuthRequirement.TokenType = SecurityTokenTypes.X509Certificate; clientAuthRequirement.RequireCryptographicToken = true; clientAuthRequirement.KeyUsage = SecurityKeyUsage.Signature; clientAuthRequirement.TransportScheme = transportScheme; clientAuthRequirement.ListenUri = listenUri; SecurityTokenResolver dummy; return(tokenManager.CreateSecurityTokenAuthenticator(clientAuthRequirement, out dummy)); }
public static SecurityTokenAuthenticator GetCertificateTokenAuthenticator(SecurityTokenManager tokenManager, string transportScheme, Uri listenUri) { SecurityTokenResolver resolver; RecipientServiceModelSecurityTokenRequirement tokenRequirement = new RecipientServiceModelSecurityTokenRequirement { TokenType = SecurityTokenTypes.X509Certificate, RequireCryptographicToken = true, KeyUsage = SecurityKeyUsage.Signature, TransportScheme = transportScheme, ListenUri = listenUri }; return(tokenManager.CreateSecurityTokenAuthenticator(tokenRequirement, out resolver)); }
public override SecurityTokenAuthenticator CreateTokenAuthenticator(SecurityTokenParameters p, out SecurityTokenResolver resolver) { resolver = null; // This check might be almost extra, though it is // needed to check correct signing token existence. // // Not sure if it is limited to this condition, but // Ssl parameters do not support token provider and // still do not fail. X509 parameters do fail. if (!RecipientParameters.InternalSupportsServerAuthentication) { return(null); } SecurityTokenRequirement r = CreateRequirement(); r.Properties [ReqType.MessageDirectionProperty] = MessageDirection.Input; InitializeRequirement(p, r); return(SecurityTokenManager.CreateSecurityTokenAuthenticator(r, out resolver)); }
protected void SetSecurityTokenAuthenticator(string scheme, BindingContext context) { if (base.ReceiveParameters.TransportSecurity.MsmqAuthenticationMode == MsmqAuthenticationMode.Certificate) { SecurityTokenResolver resolver; SecurityCredentialsManager manager = context.BindingParameters.Find <SecurityCredentialsManager>(); if (manager == null) { manager = ServiceCredentials.CreateDefaultCredentials(); } SecurityTokenManager manager2 = manager.CreateSecurityTokenManager(); RecipientServiceModelSecurityTokenRequirement tokenRequirement = new RecipientServiceModelSecurityTokenRequirement { TokenType = SecurityTokenTypes.X509Certificate, TransportScheme = scheme, ListenUri = this.Uri, KeyUsage = SecurityKeyUsage.Signature }; this.x509SecurityTokenAuthenticator = manager2.CreateSecurityTokenAuthenticator(tokenRequirement, out resolver); } }
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; } }
public override SecurityTokenAuthenticator CreateSecurityTokenAuthenticator(SecurityTokenRequirement tokenRequirement, out SecurityTokenResolver outOfBandTokenResolver) { ServiceModelSecurityTokenRequirement requirement = tokenRequirement as ServiceModelSecurityTokenRequirement; outOfBandTokenResolver = null; if (requirement != null) { if (IsX509TokenRequirement(requirement)) { if (mode == PeerAuthenticationMode.Password && IsForConnectionValidator(requirement)) { return(new X509SecurityTokenAuthenticator(X509CertificateValidator.None)); } if (delegateManager != null) { if (IsForConnectionValidator(requirement)) { requirement.TransportScheme = PeerStrings.Scheme; requirement.Properties[SecurityTokenRequirement.PeerAuthenticationMode] = SecurityMode.Transport; } else { requirement.TransportScheme = PeerStrings.Scheme; requirement.Properties[SecurityTokenRequirement.PeerAuthenticationMode] = SecurityMode.Message; } return(delegateManager.CreateSecurityTokenAuthenticator(tokenRequirement, out outOfBandTokenResolver)); } else { X509CertificateValidator validator = null; if (IsForConnectionValidator(requirement)) { if (this.mode == PeerAuthenticationMode.MutualCertificate) { if (!this.credential.PeerAuthentication.TryGetCertificateValidator(out validator)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.SecurityTokenManagerCannotCreateProviderForRequirement, requirement))); } } else { validator = X509CertificateValidator.None; } } else { if (!this.credential.MessageSenderAuthentication.TryGetCertificateValidator(out validator)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.SecurityTokenManagerCannotCreateProviderForRequirement, requirement))); } } return(new X509SecurityTokenAuthenticator(validator)); } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("tokenRequirement"); } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenRequirement"); } }