2016-01-20 16 views
11

Tôi đang làm việc để phát triển một ràng buộc mới cho dịch vụ Wcf được lưu trữ trong IIS, tôi nghĩ rằng tôi có mọi thứ hoạt động, nhưng hóa ra là máy khách chỉ hoạt động khi nó nhắm mục tiêu .Net framework 4.5, nếu tôi thay đổi nó để nhắm mục tiêu 4.6 sau đó tôi nhận được lỗi sau khi tôi cố gắng để mở một kết nối:WCF SslStreamSecurity Kiểm tra nhận dạng DNS không chỉ cho 4.6 khung công tác

System.ServiceModel.Security.MessageSecurityException occurred 
    HResult=-2146233087 
    Message=The Identity check failed for the outgoing message. The remote endpoint did not provide a domain name system (DNS) claim and therefore did not satisfied DNS identity 'xxx.domain.local'. This may be caused by lack of DNS or CN name in the remote endpoint X.509 certificate's distinguished name. 
    Source=System.ServiceModel 
    StackTrace: 
     at System.ServiceModel.Security.IdentityVerifier.EnsureIdentity(EndpointAddress serviceReference, AuthorizationContext authorizationContext, String errorString) 

Nếu tôi không làm gì khác hơn là thay đổi khuôn khổ mục tiêu trong mã thử nghiệm của tôi trở lại 4,5, sau đó nó hoạt động tốt. Điều này làm cho tôi nghĩ rằng nó có thể là một lỗi trong Net 4.6, tôi biết có Wcf ssl changes made in 4.6

Với trường hợp ngoại lệ cơ hội đầu tiên bật tôi thấy ngoại lệ sau đó được nâng lên trong nội bộ trong System.ServiceModel

System.ArgumentNullException occurred 
    HResult=-2147467261 
    Message=Value cannot be null. 
Parameter name: value 
    ParamName=value 
    Source=mscorlib 
    StackTrace: 
     at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult) 
    InnerException: 

    System.ServiceModel.dll!System.ServiceModel.Security.IssuanceTokenProviderBase<System.ServiceModel.Security.Tokens.IssuedSecurityTokenProvider.FederatedTokenProviderState>.DoNegotiation(System.TimeSpan timeout) Unknown  System.ServiceModel.dll!System.ServiceModel.Security.IssuanceTokenProviderBase<System.ServiceModel.Security.Tokens.IssuedSecurityTokenProvider.FederatedTokenProviderState>.GetTokenCore(System.TimeSpan timeout) Unknown 
    System.IdentityModel.dll!System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(System.TimeSpan timeout) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Security.Tokens.IssuedSecurityTokenProvider.GetTokenCore(System.TimeSpan timeout) Unknown 
    System.IdentityModel.dll!System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(System.TimeSpan timeout) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Security.SecurityProtocol.TryGetSupportingTokens(System.ServiceModel.Security.SecurityProtocolFactory factory, System.ServiceModel.EndpointAddress target, System.Uri via, System.ServiceModel.Channels.Message message, System.TimeSpan timeout, bool isBlockingCall, out System.Collections.Generic.IList<System.ServiceModel.Security.SupportingTokenSpecification> supportingTokens) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Security.TransportSecurityProtocol.SecureOutgoingMessageAtInitiator(ref System.ServiceModel.Channels.Message message, string actor, System.TimeSpan timeout) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Security.TransportSecurityProtocol.SecureOutgoingMessage(ref System.ServiceModel.Channels.Message message, System.TimeSpan timeout) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Security.SecurityProtocol.SecureOutgoingMessage(ref System.ServiceModel.Channels.Message message, System.TimeSpan timeout, System.ServiceModel.Security.SecurityProtocolCorrelationState correlationState) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Channels.SecurityChannelFactory<System.ServiceModel.Channels.IRequestChannel>.SecurityRequestChannel.Request(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Channels.TransactionRequestChannelGeneric<System.ServiceModel.Channels.IRequestChannel>.Request(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Dispatcher.RequestChannelBinder.Request(System.ServiceModel.Channels.Message message, System.TimeSpan timeout) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.Call(string action, bool oneway, System.ServiceModel.Dispatcher.ProxyOperationRuntime operation, object[] ins, object[] outs, System.TimeSpan timeout) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage methodCall, System.ServiceModel.Dispatcher.ProxyOperationRuntime operation) Unknown 
    System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage message) Unknown 
    mscorlib.dll!System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(ref System.Runtime.Remoting.Proxies.MessageData msgData, int type) Unknown 

Các dịch vụ wcf được truyền đạt đến là nhắm mục tiêu 4.6, và theo như tôi có thể nói tôi đang xác định danh tính dns, mà không tồn tại như một CN = trong chủ đề cert. Ràng buộc là một ràng buộc tùy chỉnh để tôi có thể thực hiện liên kết net.tcp, máy khách tạo mọi thứ trong mã và tôi không sử dụng tính năng Thêm dịch vụ tham chiếu trong studio trực quan, mã máy khách đang tạo liên kết:

var binding = new CustomBinding(new BindingElement[] { 
      new TransactionFlowBindingElement(), 
      security, 
      new SslStreamSecurityBindingElement(), 
      new BinaryMessageEncodingBindingElement() { 
       ReaderQuotas = { MaxDepth = maxReceivedSizeBytes, MaxStringContentLength = maxReceivedSizeBytes, MaxArrayLength = maxReceivedSizeBytes, MaxBytesPerRead = maxReceivedSizeBytes, MaxNameTableCharCount = maxReceivedSizeBytes }, 
      }, 
      new TcpTransportBindingElement { 
       TransferMode = TransferMode.StreamedResponse, 
       MaxReceivedMessageSize = maxReceivedSizeBytes, 
      }, 
     }) { 
    SendTimeout = sendTimeout, 
}; 

var channelFactory = new ChannelFactory<T>(binding, new EndpointAddress(new Uri(url), EndpointIdentity.CreateDnsIdentity("xxx.domain.local"), new AddressHeader[0])); 

Đây có phải là lỗi trong khung 4.6 gây ra hành vi khác không? Các bước tiếp theo sẽ chỉ cố gắng duyệt qua và gỡ lỗi mã khung để thử và tìm hiểu lý do 4.6 hoạt động khác nhau?

EDIT - Tôi tạo ra một small sample project that demonstrates the error, các bước repro là:

  • (Sử dụng VS 2015) Mở giải pháp WcfSelfHostedServer
  • Thêm cert IdentityFail.pfx đến Local Computer của bạn, lưu trữ cá nhân sử dụng mmc
  • Chạy dự án WcfSelfHostedServer (có khả năng nhấp vào tường lửa có cho phép cổng 30000)
  • Mở giải pháp WcfClient
  • Nhấp chuột phải vào project> tài sản, lưu ý rằng nó được nhắm mục tiêu 4.6.1
  • Chạy dự án, nó sẽ ném ngoại lệ mô tả ở trên
  • Bây giờ chuyển sang khách hàng để nhắm mục tiêu 4.5.2, nó sẽ chạy tốt với không lỗi

Update - tôi thấy thích hợp sau đây xuất hiện liên quan: https://support.microsoft.com/en-us/kb/3069494 https://msdn.microsoft.com/en-us/library/mt298998(v=vs.110).aspx

Nhưng xác định Tls12 tại máy chủ và máy khách không khắc phục được sự cố, và thậm chí thêm cờ DontEnableSchUseStrongCrypto = true không ảnh hưởng đến lỗi Kiểm tra Nhận dạng DNS mặc dù nó gặp lỗi nội bộ Enum.Parse rằng was being thrown from this line

Trả lời

18

Tôi cần xem Retargetting Changes in the .NET Framework 4.6.1, dưới dạng logic xác thực chứng chỉ đã thay đổi trong bản phát hành đó. (change in behavior for X509CertificateClaimSet.FindClaims đã gây ra sự cố của tôi)

Bản sửa lỗi đang chỉnh sửa ứng dụng của tôi.cấu hình để thêm:

<runtime> 
    <AppContextSwitchOverrides value="Switch.System.IdentityModel.DisableMultipleDNSEntriesInSANCertificate=true" /> 
</runtime> 

Bạn có thể xem changed code on referencesource, và tự nhiên makecert.exe không xuất hiện để hỗ trợ generating certificates with "Subject Alternative Name" fields

1

Brandon.

Dường như nếu cờ là 'sai' và chứng chỉ KHÔNG chứa mục nhập SAN, chúng tôi không thêm mục nhập dns.

4

Bạn có thể sửa mã bằng cách thêm một dòng.

như thế này.

 AppContext.SetSwitch("Switch.System.IdentityModel.DisableMultipleDNSEntriesInSANCertificate",true); 
+1

Vì một số lý do này hoạt động và thay đổi app.config không. – Jazaret

+1

Tôi đang trải qua điều tương tự. Tôi đặt công tắc trong phần 'runtime' của web.config, nhưng nó không được áp dụng. Đặt nó trong các công trình mã, mặc dù (và sửa chữa vấn đề cho tôi). Tôi không có một giải pháp cho điều này tại thời điểm này ... chỉ nghĩ rằng tôi muốn kêu vang. – erlingormar

1

Cài đặt .net 4.7 trên máy chủ đã giải quyết được sự cố cho tôi.

Các vấn đề liên quan