.NET Remoting Security使用小结 – TcpChannel
来源:互联网 发布:烟袋斜街10号网络剧 编辑:程序博客网 时间:2024/05/29 12:20
.NET Remoting Security使用小结 – TcpChannel
1. Authentication:防止非法用户的调用。
2. Authorization:防止合法但权限不够的用户调用。
3. Encryption:防止数据在传输过程中被窃取。
4. Sign:防止数据在传输过程被篡改。
下面就谈谈.NET Remoting是如何满足上面四个方面要求的。.NET Remoting有三种Channel可供选择:HttpChannel、TcpChannel和IpcChannel。它们实现Security的方式不完全相同。这次只谈TcpChannel是如何实现的。基本来说就是对该Channel一系列属性的设置。.NET Remoting属性设置有两种方式,为了都说明到,下面对Server端的设置采用代码方式,对Client端采用配置文件方式。
1. Server端:
1) 首先将secure属性设置为true。这样缺省情况下在Server端和Client端传输的数据就是经过认证、加密且签名的。
2) 如果觉得上面的缺省行为有点过度保护,影响了数据传输的性能。可以设置protectionLevel属性来调整。该属性有None、Sign和EncryptAndSign三个可选值。在secure属性设置为true时,它的缺省值是EncryptAndSign。可以将该值设为其它两种之一。需要注意的是该值的设定,在Client端一定要与Server端相同或至少包含Server端的设定(如Server端设Sign,Client设EncryptAndSign),否则会报错“A remote side security requirement was not fulfilled during authentication. Try increasing the ProtectionLevel and/or ImpersonationLevel.”,
3) 通过设置authorizationModule属性来对用户授权,即验证了用户的合法性后,决定是否允许该用户调用远程对象提供的函数。该属性的值比较复杂,需要提供一个实现了IAuthorizeRemotingConnection接口的类名和该类所在的Assembly名。通过实现该接口的IsConnectingIdentityAuthorized()函数决定允许哪些用户可以调用调用远程对象提供的函数。
4) 如果希望以Client提供的用户的名义来调用远程对象提供的函数,可以将impersonate属性设置为true。
5) 通过ChannelServices.RegisterChannel()注册端口时,第二个参数传true。
2. Client端:
1) 将secure和protectionLevel属性设置为与Server端一样。
2) 如果Server端将impersonate属性设置为true,相应的Client端需要将tokenImpersonationLevel属性设置为impersonation。注意这个属性在两边的名字和值是不完全一样的。
3) 缺省情况下Client端的用户就是运行该进程的用户。如果希望用其它的用户去接受Security检查,需要设置domain、username和password属性。
4) 通过RemotingConfiguration.Configure()应用配置文件中的设置时,第二个参数传true。
3. 示例代码:
1) Server端:
a.实现IAuthorizeRemotingConnection接口:
classAuthorizationModule : IAuthorizeRemotingConnection
{
publicbool IsConnectingIdentityAuthorized(System.Security.Principal.IIdentity identity)
{
Console.WriteLine(identity.Name + " Called!");
Console.WriteLine("Is Authenticated? " + identity.IsAuthenticated);
returntrue;
}
}
b.设置Channel属性:
Dictionary<string,string> properties = newDictionary<string,string>();
properties["secure"] ="true";
properties["port"] ="8001";
properties["impersonate"] ="true";
properties["protectionLevel"] ="Sign";
properties["authorizationModule"] ="Spacer_Robot.RemotingTest.AuthorizationModule,HelloServer";
TcpServerChannel tcpChannel = new TcpServerChannel(properties, null);
ChannelServices.RegisterChannel(tcpChannel,true);
2) Client端:
a.在App.config中的配置:
<?xml version="1.0"encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channelref="tcp"
secure="true"
tokenImpersonationLevel="impersonation"
protectionLevel="Sign"
domain="xxxx"
username="xxxx"
password="xxxx"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
b.应用该配置的代码:
RemotingConfiguration.Configure("HelloClient.exe.config",true);
- .NET Remoting Security使用小结 – TcpChannel
- C# Remoting TcpChannel
- .net Remoting小结1
- .net Remoting小结2
- .net Remoting小结3
- .net Remoting小结4
- .net Remoting小结5
- .net Remoting小结6
- .net remoting 小结(一)
- .NET Remoting 使用总结
- .NET Remoting 使用总结
- 。net remoting 使用详解
- 。net remoting 使用详解
- .NET Remoting 使用总结
- .NET Remoting 使用总结
- .NET Remoting 使用总结
- .NET Remoting 使用总结
- [Remoting] 一:.NET Remoting
- C++四种类型转换总结
- Fck发布文章错误
- 在linux中关于cpu的函数
- C语言声明
- .Net Remoting基础篇
- .NET Remoting Security使用小结 – TcpChannel
- 【追加】J2EE三大框架配置文件管理示例--加入hibernate
- dtree使用手册以及简单的例子
- 向另一个应用程序发送键击
- 用 MS ScriptControl 在 C# 中执行 javascript 代码
- javascript变量的类型检查
- P2P点播系统性能优化(3): Tracker服务器选择最优节点
- Android Socket编程
- uva 701 考古学家的烦恼( log)