public T GetProperty <T>() where T : class { if (typeof(T) != typeof(ChannelParameterCollection)) { if (typeof(T) == typeof(IRequestChannel)) { return(this as T); } T property = base.GetProperty <T>(); if (property != null) { return(property); } return(default(T)); } if (base.State == CommunicationState.Created) { lock (base.ThisLock) { if (this.channelParameters == null) { this.channelParameters = new ChannelParameterCollection(); } } } return(this.channelParameters as T); }
private IRequestChannel CreateChannel(SecuritySessionOperation operation, EndpointAddress target, Uri via) { IRequestChannel channel; if ((operation != SecuritySessionOperation.Issue) && (operation != SecuritySessionOperation.Renew)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } IChannelFactory <IRequestChannel> rstChannelFactory = this.rstChannelFactory; if (via != null) { channel = rstChannelFactory.CreateChannel(target, via); } else { channel = rstChannelFactory.CreateChannel(target); } if (this.channelParameters != null) { this.channelParameters.PropagateChannelParameters(channel); } if (this.ownCredentialsHandle) { ChannelParameterCollection property = channel.GetProperty <ChannelParameterCollection>(); if (property != null) { property.Add(new SspiIssuanceChannelParameter(true, this.credentialsHandle)); } } return(channel); }
public void EndDisplayInitializationUI(IAsyncResult result) { string userName, password; IClientChannel clientChannel; ClientPasswordAsyncResult.End(result, out userName, out password, out clientChannel); ChannelParameterCollection coll = clientChannel.GetProperty <ChannelParameterCollection>(); coll.Add(new NetworkCredential(userName, password)); }
private void ReplaceSspiIssuanceChannelParameter(ChannelParameterCollection channelParameters, SspiIssuanceChannelParameter sicp) { if (channelParameters != null) { for (int i = 0; i < channelParameters.Count; i++) { if (channelParameters[i] is SspiIssuanceChannelParameter) { channelParameters.RemoveAt(i); } } channelParameters.Add(sicp); } }
protected override IRequestChannel CreateClientChannel(EndpointAddress target, Uri via) { IRequestChannel innerChannel = base.CreateClientChannel(target, via); if (this.channelParameters != null) { this.channelParameters.PropagateChannelParameters(innerChannel); } if (this.ownCredentialsHandle) { ChannelParameterCollection property = innerChannel.GetProperty <ChannelParameterCollection>(); if (property != null) { property.Add(new SspiIssuanceChannelParameter(true, this.credentialsHandle)); } } return(innerChannel); }
protected override IRequestChannel CreateClientChannel(EndpointAddress target, Uri via) { IRequestChannel result = this.channelFactory.CreateChannel(this.IssuerAddress); if (this.channelParameters != null) { this.channelParameters.PropagateChannelParameters(result); } if (this.ownCredentialsHandle) { ChannelParameterCollection newParameters = result.GetProperty <ChannelParameterCollection>(); if (newParameters != null) { newParameters.Add(new SspiIssuanceChannelParameter(true, this.credentialsHandle)); } } ReplaceSspiIssuanceChannelParameter(result.GetProperty <ChannelParameterCollection>(), new SspiIssuanceChannelParameter(true, this.credentialsHandle)); return(result); }
private void CallEnd(IAsyncResult result, out Exception exception) { try { SecurityToken token = this.credentials.GetInfoCardTokenCallback.EndInvoke(result); ChannelParameterCollection property = this.proxy.GetProperty <ChannelParameterCollection>(); if (property != null) { property.Add(new InfoCardChannelParameter(token, this.relyingPartyIssuer, this.requiresInfoCard)); } exception = null; } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } exception = exception2; } }
IRequestChannel CreateChannel(SecuritySessionOperation operation, EndpointAddress target, Uri via) { IChannelFactory <IRequestChannel> cf; if (operation == SecuritySessionOperation.Issue || operation == SecuritySessionOperation.Renew) { cf = this.rstChannelFactory; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } IRequestChannel channel; if (via != null) { channel = cf.CreateChannel(target, via); } else { channel = cf.CreateChannel(target); } if (this.channelParameters != null) { this.channelParameters.PropagateChannelParameters(channel); } if (this.ownCredentialsHandle) { ChannelParameterCollection newParameters = channel.GetProperty <ChannelParameterCollection>(); if (newParameters != null) { newParameters.Add(new SspiIssuanceChannelParameter(true, this.credentialsHandle)); } } return(channel); }
void CallEnd(IAsyncResult result, out Exception exception) { try { SecurityToken token = credentials.GetInfoCardTokenCallback.EndInvoke(result); ChannelParameterCollection channelParameters = proxy.GetProperty <ChannelParameterCollection>(); if (null != channelParameters) { channelParameters.Add(new InfoCardChannelParameter(token, relyingPartyIssuer, requiresInfoCard)); } exception = null; } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } exception = e; } }
/// <summary> /// Looks for the first FederatedClientCredentialsParameters object in the ChannelParameterCollection /// property on the tokenRequirement. /// </summary> internal FederatedClientCredentialsParameters FindFederatedChannelParameters(SecurityTokenRequirement tokenRequirement) { FederatedClientCredentialsParameters issuedTokenClientCredentialsParameters = null; ChannelParameterCollection channelParameterCollection = null; if (tokenRequirement.TryGetProperty <ChannelParameterCollection>( ServiceModelSecurityTokenRequirement.ChannelParametersCollectionProperty, out channelParameterCollection)) { if (channelParameterCollection != null) { foreach (object obj in channelParameterCollection) { issuedTokenClientCredentialsParameters = obj as FederatedClientCredentialsParameters; if (issuedTokenClientCredentialsParameters != null) { break; } } } } return(issuedTokenClientCredentialsParameters); }
protected internal override async Task OnOpenAsync(TimeSpan timeout) { TimeoutHelper helper = new TimeoutHelper(timeout); bool success = false; try { if (TD.WebSocketConnectionRequestSendStartIsEnabled()) { TD.WebSocketConnectionRequestSendStart( EventTraceActivity, RemoteAddress != null ? RemoteAddress.ToString() : string.Empty); } ChannelParameterCollection channelParameterCollection = new ChannelParameterCollection(); HttpsChannelFactory<IDuplexSessionChannel> httpsChannelFactory = _channelFactory as HttpsChannelFactory<IDuplexSessionChannel>; if (httpsChannelFactory != null && httpsChannelFactory.RequireClientCertificate) { SecurityTokenProvider certificateProvider = httpsChannelFactory.CreateAndOpenCertificateTokenProvider(RemoteAddress, Via, channelParameterCollection, helper.RemainingTime()); } try { WebSocket = await CreateWebSocketWithFactoryAsync(helper); } finally { if (WebSocket != null && _cleanupStarted) { WebSocket.Abort(); CommunicationObjectAbortedException communicationObjectAbortedException = new CommunicationObjectAbortedException( new WebSocketException(WebSocketError.ConnectionClosedPrematurely).Message); FxTrace.Exception.AsWarning(communicationObjectAbortedException); throw communicationObjectAbortedException; } } bool inputUseStreaming = TransferModeHelper.IsResponseStreamed(TransferMode); SetMessageSource(new WebSocketMessageSource( this, WebSocket, inputUseStreaming, this)); success = true; if (TD.WebSocketConnectionRequestSendStopIsEnabled()) { TD.WebSocketConnectionRequestSendStop( EventTraceActivity, WebSocket != null ? WebSocket.GetHashCode() : -1); } } catch (WebSocketException ex) { if (TD.WebSocketConnectionFailedIsEnabled()) { TD.WebSocketConnectionFailed(EventTraceActivity, ex.Message); } TryConvertAndThrow(ex); } finally { CleanupTokenProviders(); if (!success) { CleanupOnError(); } } }
HttpWebRequest CreateHttpWebRequest(TimeSpan timeout) { TimeoutHelper helper = new TimeoutHelper(timeout); ChannelParameterCollection channelParameterCollection = new ChannelParameterCollection(); HttpWebRequest request; if (HttpChannelFactory<IDuplexSessionChannel>.MapIdentity(this.RemoteAddress, this.channelFactory.AuthenticationScheme)) { lock (ThisLock) { this.cleanupIdentity = HttpTransportSecurityHelpers.AddIdentityMapping(Via, RemoteAddress); } } this.channelFactory.CreateAndOpenTokenProviders( this.RemoteAddress, this.Via, channelParameterCollection, helper.RemainingTime(), out this.webRequestTokenProvider, out this.webRequestProxyTokenProvider); SecurityTokenContainer clientCertificateToken = null; HttpsChannelFactory<IDuplexSessionChannel> httpsChannelFactory = this.channelFactory as HttpsChannelFactory<IDuplexSessionChannel>; if (httpsChannelFactory != null && httpsChannelFactory.RequireClientCertificate) { SecurityTokenProvider certificateProvider = httpsChannelFactory.CreateAndOpenCertificateTokenProvider(this.RemoteAddress, this.Via, channelParameterCollection, helper.RemainingTime()); clientCertificateToken = httpsChannelFactory.GetCertificateSecurityToken(certificateProvider, this.RemoteAddress, this.Via, channelParameterCollection, ref helper); } request = this.channelFactory.GetWebRequest(this.RemoteAddress, this.Via, this.webRequestTokenProvider, this.webRequestProxyTokenProvider, clientCertificateToken, helper.RemainingTime(), true); // If a web socket connection factory is specified (for example, when using web sockets on pre-Win8 OS), // we're going to use the protocol version from it. At the moment, on pre-Win8 OS, the HttpWebRequest // created above doesn't have the version header specified. if (this.connectionFactory != null) { this.UseWebSocketVersionFromFactory(request); } this.webSocketKey = request.Headers[WebSocketHelper.SecWebSocketKey]; this.ConfigureHttpWebRequestHeader(request); request.Timeout = (int)helper.RemainingTime().TotalMilliseconds; return request; }
private SecurityTokenProvider CreateSecureConversationSecurityTokenProvider(InitiatorServiceModelSecurityTokenRequirement initiatorRequirement) { EndpointAddress targetAddress = initiatorRequirement.TargetAddress; if (targetAddress == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.TokenRequirementDoesNotSpecifyTargetAddress, initiatorRequirement)); } SecurityBindingElement securityBindingElement = initiatorRequirement.SecurityBindingElement; if (securityBindingElement == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.TokenProviderRequiresSecurityBindingElement, initiatorRequirement)); } LocalClientSecuritySettings localClientSettings = securityBindingElement.LocalClientSettings; BindingContext issuerBindingContext = initiatorRequirement.GetProperty <BindingContext>(ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty); ChannelParameterCollection channelParameters = initiatorRequirement.GetPropertyOrDefault <ChannelParameterCollection>(ServiceModelSecurityTokenRequirement.ChannelParametersCollectionProperty, null); bool isSessionMode = initiatorRequirement.SupportSecurityContextCancellation; if (isSessionMode) { SecuritySessionSecurityTokenProvider sessionTokenProvider = new SecuritySessionSecurityTokenProvider(); sessionTokenProvider.BootstrapSecurityBindingElement = SecurityUtils.GetIssuerSecurityBindingElement(initiatorRequirement); sessionTokenProvider.IssuedSecurityTokenParameters = initiatorRequirement.GetProperty <SecurityTokenParameters>(ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty); sessionTokenProvider.IssuerBindingContext = issuerBindingContext; sessionTokenProvider.KeyEntropyMode = securityBindingElement.KeyEntropyMode; sessionTokenProvider.SecurityAlgorithmSuite = initiatorRequirement.SecurityAlgorithmSuite; sessionTokenProvider.StandardsManager = SecurityUtils.CreateSecurityStandardsManager(initiatorRequirement, this); sessionTokenProvider.TargetAddress = targetAddress; sessionTokenProvider.Via = initiatorRequirement.GetPropertyOrDefault <Uri>(InitiatorServiceModelSecurityTokenRequirement.ViaProperty, null); Uri privacyNoticeUri; if (initiatorRequirement.TryGetProperty(ServiceModelSecurityTokenRequirement.PrivacyNoticeUriProperty, out privacyNoticeUri)) { sessionTokenProvider.PrivacyNoticeUri = privacyNoticeUri; } int privacyNoticeVersion; if (initiatorRequirement.TryGetProperty(ServiceModelSecurityTokenRequirement.PrivacyNoticeVersionProperty, out privacyNoticeVersion)) { sessionTokenProvider.PrivacyNoticeVersion = privacyNoticeVersion; } EndpointAddress localAddress; if (initiatorRequirement.TryGetProperty(ServiceModelSecurityTokenRequirement.DuplexClientLocalAddressProperty, out localAddress)) { sessionTokenProvider.LocalAddress = localAddress; } sessionTokenProvider.ChannelParameters = channelParameters; sessionTokenProvider.WebHeaders = initiatorRequirement.WebHeaders; return(sessionTokenProvider); } else { AcceleratedTokenProvider acceleratedTokenProvider = new AcceleratedTokenProvider(); acceleratedTokenProvider.IssuerAddress = initiatorRequirement.IssuerAddress; acceleratedTokenProvider.BootstrapSecurityBindingElement = SecurityUtils.GetIssuerSecurityBindingElement(initiatorRequirement); acceleratedTokenProvider.CacheServiceTokens = localClientSettings.CacheCookies; acceleratedTokenProvider.IssuerBindingContext = issuerBindingContext; acceleratedTokenProvider.KeyEntropyMode = securityBindingElement.KeyEntropyMode; acceleratedTokenProvider.MaxServiceTokenCachingTime = localClientSettings.MaxCookieCachingTime; acceleratedTokenProvider.SecurityAlgorithmSuite = initiatorRequirement.SecurityAlgorithmSuite; acceleratedTokenProvider.ServiceTokenValidityThresholdPercentage = localClientSettings.CookieRenewalThresholdPercentage; acceleratedTokenProvider.StandardsManager = SecurityUtils.CreateSecurityStandardsManager(initiatorRequirement, this); acceleratedTokenProvider.TargetAddress = targetAddress; acceleratedTokenProvider.Via = initiatorRequirement.GetPropertyOrDefault <Uri>(InitiatorServiceModelSecurityTokenRequirement.ViaProperty, null); return(acceleratedTokenProvider); } }
private SecurityTokenProvider CreateSecureConversationSecurityTokenProvider(InitiatorServiceModelSecurityTokenRequirement initiatorRequirement) { Uri uri2; int num2; EndpointAddress targetAddress = initiatorRequirement.TargetAddress; if (targetAddress == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(System.ServiceModel.SR.GetString("TokenRequirementDoesNotSpecifyTargetAddress", new object[] { initiatorRequirement })); } SecurityBindingElement securityBindingElement = initiatorRequirement.SecurityBindingElement; if (securityBindingElement == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(System.ServiceModel.SR.GetString("TokenProviderRequiresSecurityBindingElement", new object[] { initiatorRequirement })); } LocalClientSecuritySettings localClientSettings = securityBindingElement.LocalClientSettings; BindingContext property = initiatorRequirement.GetProperty <BindingContext>(ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty); ChannelParameterCollection propertyOrDefault = initiatorRequirement.GetPropertyOrDefault <ChannelParameterCollection>(ServiceModelSecurityTokenRequirement.ChannelParametersCollectionProperty, null); if (initiatorRequirement.SupportSecurityContextCancellation) { Uri uri; int num; EndpointAddress address2; SecuritySessionSecurityTokenProvider provider = new SecuritySessionSecurityTokenProvider(this.GetCredentialsHandle(initiatorRequirement)) { BootstrapSecurityBindingElement = System.ServiceModel.Security.SecurityUtils.GetIssuerSecurityBindingElement(initiatorRequirement), IssuedSecurityTokenParameters = initiatorRequirement.GetProperty <SecurityTokenParameters>(ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty), IssuerBindingContext = property, KeyEntropyMode = securityBindingElement.KeyEntropyMode, SecurityAlgorithmSuite = initiatorRequirement.SecurityAlgorithmSuite, StandardsManager = System.ServiceModel.Security.SecurityUtils.CreateSecurityStandardsManager(initiatorRequirement, this), TargetAddress = targetAddress, Via = initiatorRequirement.GetPropertyOrDefault <Uri>(ServiceModelSecurityTokenRequirement.ViaProperty, null) }; if (initiatorRequirement.TryGetProperty <Uri>(ServiceModelSecurityTokenRequirement.PrivacyNoticeUriProperty, out uri)) { provider.PrivacyNoticeUri = uri; } if (initiatorRequirement.TryGetProperty <int>(ServiceModelSecurityTokenRequirement.PrivacyNoticeVersionProperty, out num)) { provider.PrivacyNoticeVersion = num; } if (initiatorRequirement.TryGetProperty <EndpointAddress>(ServiceModelSecurityTokenRequirement.DuplexClientLocalAddressProperty, out address2)) { provider.LocalAddress = address2; } provider.ChannelParameters = propertyOrDefault; return(provider); } AcceleratedTokenProvider provider2 = new AcceleratedTokenProvider(this.GetCredentialsHandle(initiatorRequirement)) { IssuerAddress = initiatorRequirement.IssuerAddress, BootstrapSecurityBindingElement = System.ServiceModel.Security.SecurityUtils.GetIssuerSecurityBindingElement(initiatorRequirement), CacheServiceTokens = localClientSettings.CacheCookies, IssuerBindingContext = property, KeyEntropyMode = securityBindingElement.KeyEntropyMode, MaxServiceTokenCachingTime = localClientSettings.MaxCookieCachingTime, SecurityAlgorithmSuite = initiatorRequirement.SecurityAlgorithmSuite, ServiceTokenValidityThresholdPercentage = localClientSettings.CookieRenewalThresholdPercentage, StandardsManager = System.ServiceModel.Security.SecurityUtils.CreateSecurityStandardsManager(initiatorRequirement, this), TargetAddress = targetAddress, Via = initiatorRequirement.GetPropertyOrDefault <Uri>(ServiceModelSecurityTokenRequirement.ViaProperty, null) }; if (initiatorRequirement.TryGetProperty <Uri>(ServiceModelSecurityTokenRequirement.PrivacyNoticeUriProperty, out uri2)) { provider2.PrivacyNoticeUri = uri2; } provider2.ChannelParameters = propertyOrDefault; if (initiatorRequirement.TryGetProperty <int>(ServiceModelSecurityTokenRequirement.PrivacyNoticeVersionProperty, out num2)) { provider2.PrivacyNoticeVersion = num2; } return(provider2); }