WSE2.0中X509安全令牌的使用
2007-08-14 11:36
351 查看
wse2.0发布了,大家都来一起研究吧,我先来抛砖引玉:
调用webservice时有的时候安全性要求比较高,wse提供了客户端证书来调用webservice,好我们就来看看怎么弄。
调用webservice当然有客户端和webservice端了,我们先来看看
客户端:
usingMicrosoft.Web.Services2.Security;
usingMicrosoft.Web.Services2.Security.Tokens;
usingMicrosoft.Web.Services2.Security.X509;
1。//?在个人证书存储区获取证书
X509CertificateStorestore=X509CertificateStore.CurrentUserStore(X509CertificateStore.MyStore);
store.OpenRead()
//读取证书的keyid
X509CertificateCollectioncerts=store.FindCertificateByKeyIdentifier(Convert.FromBase64String(keyIdentifier));
X509SecurityTokentoken=null;
if(certs.Count>0)
{
?????//?得到证书存储区的第一个个人证书
?????token=newX509SecurityToken(((X509Certificate)certs[0]));
}?
2。//把token加入到soap中
ServiceWseserviceProxy=newServiceWse();//远程webservice代理
serviceProxy.RequestSoapContext.Security.Tokens.Add(token);
?serviceProxy.RequestSoapContext.Security.Elements.Add(newMessageSignature(token));
3。调用webservice的方法:
。。。和普通调用webservice的方法一样,我这里就不说了:)
WebService端:
1。配置web.config
在configuration节点下加:
???
?表示引用的是wse2.0
在下加:
?????
???????
?????
???
在configuration节点下加:
?????
???
?
这个wse2.0中规定的xml节点。
2。验证客户端提交上来的证书
//获取客户端提交上来的证书
X509SecurityTokenx509Token=GetSigningToken(RequestSoapContext.Current)asX509SecurityToken;
publicSecurityTokenGetSigningToken(SoapContextcontext)
???????{
???????????foreach(ISecurityElementelementincontext.Security.Elements)
???????????{
???????????????if(elementisMessageSignature)
???????????????{
???????????????????//ThegivencontextcontainsaSignatureelement.
???????????????????MessageSignaturesig=elementasMessageSignature;
???????????????????if(CheckSignature(context,sig))
???????????????????{
???????????????????????//TheSOAPBodyissigned.
???????????????????????returnsig.SigningToken;
???????????????????}
???????????????}
???????????}???????????
returnnull;
??}
//判断证书是否合法
//根据证书的keyid来判断
//这个就是证书的keyid,
x509Token.KeyIdentifier.Value
。。。
如果和你颁发的证书keyid不一致的话,你可以抛给他一个错误:
thrownewSecurityFault(SecurityFault.FailedAuthenticationMessage,SecurityFault.FailedAuthenticationCode);
如果正确,执行webservice中的代码。
?
?
相关文章推荐
- WSE2.0中X509安全令牌的使用
- WSE2.0中X509安全令牌的使用
- WSE2.0中X509安全令牌的使用
- 使用 WSE 2.0 确保 Username 标记的安全
- [收藏]使用 WSE 2.0 从 WS-Routing 转移到 WS-Addressing
- [收藏]使用 WSE 2.0 从 WS-Routing 转移到 WS-Addressing
- 使用WSE实现Web Service安全
- 使用安全令牌保护 RTMP 流
- 使用WSE实现Web Service安全
- MVC使用ASP.NET Identity 2.0实现用户身份安全相关功能,比如通过短信或邮件发送安全码,账户锁定等
- 使用.net和x509证书实现安全
- 使用安全令牌保护 RTMP 流
- 使用WSE2.0发送附件(如图片等)
- [转载]使用 Microsoft SOAP Toolkit 2.0 建立安全 Web 服务
- Web Service Client使用Microsoft WSE 2.0
- wse2.0实现webservice安全(转)
- 使用 Microsoft SOAP Toolkit 2.0 建立安全 Web 服务
- 使用WSE2.0发送附件(如图片等)
- [收藏]使用 WSE 2.0 从 WS-Routing 转移到 WS-Addressing
- [收藏]使用 WSE 2.0 从 WS-Routing 转移到 WS-Addressing