はい、なりすましを防ぐためにWCFチャネルを保護する必要があります。 WCFは、指示されたときに自動的に通信を暗号化できますが、認証部分を自分で処理する必要があります。
WCFでメッセージをセキュリティで保護する方法は2つあります(3つのメッセージを同時に使用することができます)。良いレベルの説明がありますhere。どちらの方法でを使用できるかは、のバインディングに依存しています(バインディングごとに異なるオプションがあります)。
さらに、サービスをセキュリティで保護する方法ごとに、認証資格情報の種類(各エンティティが別のエンドポイントにIDを証明する実際の手段)を選択できます。 これはバインディングとセキュリティメソッドにも依存します。
各バインディングのオプションを確認するには、Security
プロパティを確認してください。このプロパティは、各バインディングごとに異なるタイプです(例:NetTcpSecurity
)。 MSDNまたはIntelliSenseでこれを調べることができます。
ここでは、例として転送セキュリティを使用するNetTcpBinding
を使用します。
var binding = new NetTcpBinding { /* set props here */ };
// TLS security with X.509 certificates
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;
その後、上:例えば、サーバーとクライアントの両方の部分では、あなたが最初のチャネルを作成し、開く前に、セキュリティモードと認証タイプとの結合を設定する必要があり、セキュリティを設定するには
サーバ側(この例では、上記選択した内容に固有のものです):
// Load and set the server certificate
var serverCertificate = new X509Certificate2(/* parameters here */);
host.Credentials.ServiceCertificate.Certificate = serverCertificate;
// You can leave it at that and let Windows validate the client's certificate using
// the default method (which means that you either need to have added the client's
// certificate to the server machine's certificate store as "trusted", or rely on chain
// trust and have the client's certificate signed by a trusted authority.
// Or, you can use custom validation rules:
var authentication = host.Credentials.ClientCertificate.Authentication;
authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;
authentication.CustomCertificateValidator = new AcceptAnythingCertificateValidator();
とクライアント側(この例では、特定のある)上:
var clientCertificate = new X509Certificate2(/* parameters here */);
var factory = new ChannelFactory<IYourServiceInterface>(binding, endpoint);
factory.Credentials.ClientCertificate.Certificate = clientCertificate;
// You can leave it at that and let Windows validate the server's certificate using
// the default method (which means that you either need to have added the server's
// certificate to the client machine's certificate store as "trusted", or rely on chain
// trust and have the server's certificate signed by a trusted authority.
// Or, you can use custom validation rules:
var authentication = factory.Credentials.ServiceCertificate.Authentication;
authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;
authentication.CustomCertificateValidator = new AcceptAnythingCertificateValidator();
var channel = factory.CreateChannel();
// Your channel is now ready for use! You can also cast to to IClientChannel
// to expose some more properties.
出典
2010-11-25 14:51:01
Jon
あなたの素晴らしい答えをありがとう。 'MessageCredentialType.Windows'の使用に関するコメントはありますか?ネットワーク管理者がリモートコンピュータ上のサービスを制御できるようにするには、Windowsがユーザー/パスワードの問題に対処する最も簡単な方法は何ですか? –
Windowsセキュリティでは、ユーザーは既にドメイン内のWindowsユーザーアカウントにログインしている必要があり、追加のユーザー名とパスワードは必要ありません。このhttp://msdn.microsoft.com/en-us/library/ms734769.aspx(特にイントラネットサービスでのWindowsセキュリティの実装)およびhttp://msdn.microsoft.com/en-us/を参照してください。例については/library/ms730301.aspxを参照してください。 – Jon
ありがとうございます。方法を見つけ出し、これを見つけました:http://msdn.microsoft.com/en-us/library/ms734673.aspx今私はそれをテストする必要があります:) –