나는 SecurityMode.Message를 사용하여 통신을 암호화하는 여러 WCF 서비스를 시작하는 응용 프로그램을 개발했습니다.WCF 인증을위한 SSL Cert
SSL 인증서를 생성하여 특정 저장소, 서버 및 클라이언트에 넣어야하기 때문에 매우 복잡합니다.
- 사실 (도메인에 있지, 서버가 확실히 도메인에있을 것입니다,하지만 클라이언트
- 은하지 않습니다
문제는 프로그램을 사용하는 고객이 있다는 것입니다
그래서 내 최선을 무엇? 난 단지 데이터를 암호화 할 필요가 인증서를 사고 싶어, 내가 올바른 호스트에 연결하고있어 수 있도록 할 필요가 없습니다.
을 나는 '알 ~ 안에 없다. 가장 좋은 경우이지만 일부 특정 사용자가 응용 프로그램을 사용할 것입니다.
서버 측 :
ServiceHost host = new ServiceHost(typeof(MyServiceType))
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;
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, ConfigurationManager.AppSettings["Hostname"]);
host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
host
.AddServiceEndpoint(services[port], binding, String.Format("http://localhost:{0}", port));
클라이언트 측 :
string remoteAddress = String.Format("{0}://{1}:{2}", Tools.GetDescription(accessInfo.ServiceHost.Protocol), accessInfo.ServiceHost.HostName, accessInfo.PortNumber);
// 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);
_service = channelFactory.CreateChannel();
유의하시기 바랍니다 난을 제거하는 것이 여기에
연결을 만드는 내 코드의 일부이다 내 사용자 정의 인증과 관련된 부분이 더 깨끗한 코드
좋아요, 제가 생각한 것입니다.고객이 암호화를 원하지 않고 인증서를 설치/지불 할 필요가 없다면 어떻게해야합니까? (권장 할 해결책은 아니지만 알 필요가 있습니다) 그리고 : 인증서를 구입하면 무엇을해야합니까? 내가 여기서 확인 할까? 일부 인증서는 http만으로 작동한다고 가정합니다. – J4N
SSL 서버 인증서가 작동합니다. 자신 만의 맞춤 솔루션을 만들고 싶다면 그것은 당신에게 달려 있습니다. 전달하기 전에 메시지 내용을 암호화하고 메시지 내용을받은 후에 해독해야합니다. 아마도 사용자 지정 메시지 관리자 나 사용자 지정 채널/인코더가이를 수행합니다. 암호화를 위해 안전하게 키를 저장하는 방법을 찾아야합니다 (이것은 정확히 어떤 인증서가 무엇입니까). –
고맙습니다. 고객 네트워크에서만 서버에 액세스 할 수 있다면 어떻습니까? 내 말은, 신뢰할 수있는 게시자의 경우? 내부 네트워크 이름 또는 개인 IP에 대해 적법한 SSL 인증서를 얻을 수 있습니까? – J4N