2011-08-30 4 views
1

응용 프로그램의 경우 WCF 서비스 용 SSL 인증서가 있어야합니다.엔터프라이즈 CA를 사용하는 WCF SSL 인증서

그래서 설치했습니다. 웹 브라우저 물마루 https가있는 인터넷 브라우저를 사용하는 경우 문제가 발생하지 않으며 아무런 경고도 표시되지 않습니다. 따라서이 인증서는 Windows에서 유효한 것으로 간주됩니다.

The X.509 certificate CN=myHostName, OU=tom, O=myDomainName, 

L=MyLocation, S=SO, C=CH chain building failed. The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. The revocation function was unable to check revocation because the revocation server was offline.

것은 무엇 잘못 될 수 있습니다

문제는 내가 내 WCF 서버에 연결을 시도하고있을 때, 나는이 오류를 가지고 있다는 것입니다? 체인의 어느 부분이 유효하지 않은지 어떻게 알 수 있습니까? 누락 된 부분이 무엇인지 알 수있는 방법이 있습니까? 여기

는 서버 내 코드 입니다 :

ServiceHost myHost = new ServiceHost(typeof(MyService)); 
WSHttpBinding binding = new WSHttpBinding 
{ 
    ReaderQuotas = { MaxStringContentLength = int.MaxValue, MaxArrayLength = int.MaxValue, MaxDepth = int.MaxValue, MaxBytesPerRead = int.MaxValue, MaxNameTableCharCount = int.MaxValue }, 
    MaxReceivedMessageSize = int.MaxValue 
}; 
TimeSpan timeoutSpan = TimeSpan.FromMilliseconds(timeout); 
binding.CloseTimeout = timeoutSpan; 
binding.OpenTimeout = timeoutSpan; 
binding.ReceiveTimeout = timeoutSpan; 
binding.SendTimeout = timeoutSpan; 
binding.ReliableSession.InactivityTimeout = timeoutSpan; 

binding.MaxBufferPoolSize = int.MaxValue; 

//we set the security type 
binding.Security.Mode = SecurityMode.Message; 
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; 
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 

//we set the server's certificate 
myHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, ConfigurationManager.AppSettings["Hostname"]); 
myHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
//we add the endPoint(and we indicate which methods are exposed through the interface 

myHost.AddServiceEndpoint(services[port], binding,     String.Format("http://localhost:{0}", port)); 




//Some services doesn't need an authentication 
if (!servicesWithoutAuth.Contains(services[port])) 
{ 
    //We set the authentifier: 
    myHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom; 
    myHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustomUserNameValidator(); 
    myHost.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.Custom; 


    //we set the AuthorizationPolicy 
    List<IAuthorizationPolicy> policies = new List<IAuthorizationPolicy> { new CustomAuthorizationPolicy() }; 
    myHost.Authorization.ExternalAuthorizationPolicies = policies.AsReadOnly(); 
} 
else 
{ 
    //We set the authentifier: 
    myHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom; 
    myHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new NoUserNamePasswordValidator(); 
} 

//We bypass the certificate verification(our certificate is only self signed) 
//HACK Only to desactivate the SSL check: 
ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate; 



//HACK: Remove when debug finished 
private static bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors) 
{ 
    return true; 
} 

내 클라이언트 측 :

// the remote adress is of the form "net.tcp://localhost:8000" 
string remoteAddress = String.Format("{0}://{1}:{2}", Tools.GetDescription(accessInfo.ServiceHost.Protocol), accessInfo.ServiceHost.HostName, accessInfo.PortNumber); 

// HACK: binding depends on protocol -> switch over accessInfo.ServiceHost.Protocol 

// avoid seralization/deserialization problems with large XML's 
WSHttpBinding binding = new WSHttpBinding(); 
binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; 
binding.ReaderQuotas.MaxArrayLength = int.MaxValue; 
binding.MaxReceivedMessageSize = int.MaxValue; 
binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; 
binding.ReaderQuotas.MaxArrayLength = int.MaxValue; 
binding.ReaderQuotas.MaxDepth = int.MaxValue; 
binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue; 
binding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue; 
TimeSpan timeoutSpan = DateTime.Now.AddMinutes(30) - DateTime.Now; 
binding.CloseTimeout = timeoutSpan; 
binding.OpenTimeout = timeoutSpan; 
binding.ReceiveTimeout = timeoutSpan; 
binding.SendTimeout = timeoutSpan; 
binding.ReliableSession.InactivityTimeout = timeoutSpan; 


//++ 
binding.MaxBufferPoolSize = int.MaxValue; 

//we set the security type 
binding.Security.Mode = SecurityMode.Message; 
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; 
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 

ChannelFactory<TService> channelFactory = new ChannelFactory<TService>(binding, remoteAddress); 

channelFactory.Credentials.UserName.UserName = ((UsernamePasswordAuthentication)authInfos).Username; 
channelFactory.Credentials.UserName.Password = ((UsernamePasswordAuthentication)authInfos).Password; 


//We set the maxItemsInObjectGraph 
foreach (OperationDescription op in channelFactory.Endpoint.Contract.Operations) 
{ 
    DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>(); 
    if (dataContractBehavior != null) 
    { 
     dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue; 
    } 
} 
SamlSecurityTokenAuthenticator authenticator = new SamlSecurityTokenAuthenticator(new List<SecurityTokenAuthenticator>(new SecurityTokenAuthenticator[] { new RsaSecurityTokenAuthenticator(), new X509SecurityTokenAuthenticator(X509CertificateValidator.None) }), TimeSpan.FromDays(5)); 

_service = channelFactory.CreateChannel(); 
당신이 그것을 키 스토어를 열어 볼 경우

답변

0

How can I know which part of the chain is unvalid? Is there any way to know what is the missing part?

음, 내 경험에서, 당신은해야 인증서가 명확하게 사슬을 형성하는 것을보십시오. 나는 당신이 당신의 키 스토어 (또는 당신이 윈도우 키 스토어를 사용하는 경우)를보기 위해 어떤 도구를 사용하는지 모르지만, 당신이 당신의 키를 볼 때 어떤 종류의 사슬을보아야한다. 체인이 올바르게 형성되면 체인이 올바르게 나타나고 누락 된 부품이없는 것입니다.

내 생각 엔 인증서 답장을 가져 왔을 때 어떤 이유로 든 체인을 형성하지 않았을 것입니다. 즉, 인증서가 키 체인에 "체인화되지 않은"공개 키로 존재합니다.