- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在具有相互 SSL 身份验证的同一台机器上设置 WCF 服务和客户端。
我有:
为服务器和客户端创建证书并将它们放入 LocalMachine 证书库中。服务器和客户端私钥在“个人”存储中,而公钥在“受信任的人”存储中。
我已经配置了一个 WCF 服务和客户端,每个服务和客户端都从商店中指定了自己的证书引用,并且还设置了其他方的证书引用以使用
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="LocalMachine" />
注意:服务器证书颁发给Machine name,客户端调用的服务url为'https:\tokenservice\tokenservice.svc
使用此配置,我希望客户端安全地连接到服务,两端解析来自“受信任的人”存储的证书,但我收到以下错误,表明证书验证失败:
[AuthenticationException:根据验证程序,远程证书无效。]
所以这并没有像我预期的那样真正起作用。谁能指出任何错误?还是我的期望不正确?
WCF 配置如下:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="CertificateForClient">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CertificateBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust"
trustedStoreLocation="LocalMachine" />
</clientCertificate>
<serviceCertificate findValue="CN='ServerCertificate which is machine name'"
storeLocation="LocalMachine" storeName="My"
x509FindType="FindBySubjectDistinguishedName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="TokenService.TokenService" behaviorConfiguration="CertificateBehaviour">
<endpoint contract="TokenService.ITokenService"
binding="wsHttpBinding" />
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding" address="mex">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="https://tokenservice" />
</baseAddresses>
</host>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
客户端配置:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ClientBehaviour">
<clientCredentials>
<clientCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectDistinguishedName" findValue="CN=TokenClient"/>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="LocalMachine"></authentication>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="ClientBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://tokenservice/TokenService.svc"
behaviorConfiguration="ClientBehaviour"
binding="wsHttpBinding" bindingConfiguration="ClientBinding"
contract="TokenService.ITokenService" name="ToolClient">
<identity>
<dns value="MachineName" />
</identity>
</endpoint>
</client>
最佳答案
当使用双向 SSL 在传输层完成身份验证时,PeerTrust 和 ChainTrust 提供的内置授权不起作用。
老实说,PeerTrust 在很多情况下并不能控制所需的授权过程。
解决此问题的一种非常常见的方法是插入自定义 ServiceAuthorizationManager 并覆盖其 OnAccess 方法。
<behavior name="ServerCertificateBehavior">
<serviceCredentials>
<serviceCertificate .... />
</serviceCredentials>
<serviceAuthorization serviceAuthorizationManagerType="MyCustomCertificateAuthorizationManager, MyWCFExtensions.Security" />
</behavior>
ServiceAuthorizationManager 可以用几行代码完成,用于非常静态的简单证书检查或根据需要进行更复杂的检查。
这个简单的概念验证希望可以帮助您入门:
public class MyCustomCertificateAuthorizationManager : ServiceAuthorizationManager
{
public override bool CheckAccess(OperationContext operationContext, ref Message message)
{
base.CheckAccess(operationContext, ref message);
string action = operationContext.IncomingMessageHeaders.Action;
List<string> approvedActions = new List<string>
{
"http://kramerica.lan/namespace/MySpecialMethod",
"http://kramerica.lan/namespace/AnotherMethod"
};
List<string> approvedThumbprints = new List<string>
{
"1aaffe105b31b79b66c31de3389203d42351683a",
"f1bcfbc6383bcbfa736473bcaf109987bbc2121a"
};
//One way is do the authorization based on the action if the endpoint is used for more than one operation with different ACL needs
if (approvedActions.Contains(action))
{
foreach (ClaimSet claimSet in OperationContext.Current.ServiceSecurityContext.AuthorizationContext.ClaimSets)
{
X509CertificateClaimSet certificateClaimSet = claimSet as X509CertificateClaimSet;
if (certificateClaimSet != null)
{
//Get the actual certificate used by the client
X509Certificate2 certificate = certificateClaimSet.X509Certificate;
//Here a real validation of certificate issuer chain etc. could be made
if (certificate != null)
{
//This proof-of-concept does authorization based on a static list of thumbprints but about anything os possible here.
//One could easily check if this certificate
//is present in the TrustedPeople store or some database backend
if (approvedThumbprints.Contains(certificate.Thumbprint))
return true;
}
}
}
}
return false;
}
}
关于WCF:尝试使用自签名证书和 'PeerTrust' 设置双向双向 SSL 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11857039/
我得到了这个printHashKey函数,它运行良好。 fun printHashKey() { try { val info : PackageInfo = packageM
如何使用正确的签名 key 为我的 Android 应用包签名? 最佳答案 我尝试在此处和 this question 中使用多个答案, 但不知何故我收到了这个错误,因为我的 android/app/
我的 gradle 文件中有这个: android { signingConfigs { mySigningConfig { keyAlias 'the
请至少选择一个签名版本以在 Android Studio 2.3 中使用 现在在 Android Studio 中生成一个签名的 APK 时,它显示了两个选项(复选框),即 1. V1(Jar 签名)
我想表示一些标量值(例如整数或字符串)通过它的实际值或一些 NA 值,然后存储它们在集合中(例如列表)。目的是处理缺失值。 为此,我实现了一个签名 module type Scalar = sig
为什么这不完全有效? sum :: (Num a, Num b) => a -> b -> c sum a b = a + b 当然,错误消息与签名有关,但我仍然不明白原因。 Couldn't mat
谢谢帮助,我的问题是关于从下面的代码中收到的 ax 值? mov al,22h mov cl,0fdh imul cl 真机结果:ff9a 我的预期:00:9a(通过二进制相乘) 第一个数字是 22h
我有一个注释: import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.
我从对物体的思考中得出了一个术语。当我们扩展一个类时,扩展类将具有与父类相同的签名,因此术语 IS-A 来自...示例 class Foo{ } class Foo2 extends Foo{ } c
我需要在有符号整数和它们作为字节序列的内部表示之间进行转换。在 C 中,我使用的函数如下: unsigned char hibyte(unsigned short i) {return i>>8;}
我正在尝试使用给定的 RSA 参数对一些数据进行签名。 我给出了模数、指数、D、DP、DQ、P、Q 和 InverseQ。什么库或方法最容易使用来计算此签名。在 C# 中,一旦您提供参数,它们就会有一
这些签名之间有什么区别? T * f(T & identifier); T & f(T & identifier); T f(T & identifier); void f(T * identifie
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Where and why do I have to put the “template” and “typ
我有一个签名,我需要在签名旁边添加图片。但我不确定 css 的确切程度和内容。目前它显示在文字下方,我应该把图片放在哪里?在相同的 tr 或 td 中?
查看 LinkedHashMap 的 JDK 源代码,我注意到这个类被声明为: public class LinkedHashMap extends HashMap im
背景:我继承了一个基于 linux 的嵌入式系统,其中包含一个 SMTP 代理和一些我不得不忍受的古怪限制。它位于 SMTP 客户端和服务器之间。当 SMTP 客户端连接时,代理会打开与服务器的连接,
这是 C++17 形式的规则 ([basic.lval]/8),但它在其他标准中看起来很相似(在 C++98 中是“lvalue”而不是“glvalue”): 8 If a program attem
我有一个注释: import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.
我即将开展一个项目,希望使用电子签名板使用 C# 捕获客户的签名、在设备上显示文本等。 现在,在我开始做进一步的研究之前,我想向你们征求一些意见/建议,我应该使用哪些设备.. 我现在的要求非常笼统:我
呢喃自己在心中开始扩张地盘,仿佛制式地广播了三次。 漾起的涟绮,用谈不上精腻的手段。 拒绝天亮,却又贪恋着贪恋多情的日光。 川流不息的画面是他们,而我的落幕停在右脚,它渴望着下台,而我只剩自言
我是一名优秀的程序员,十分优秀!