我已经创建了我的自签名证书并将其安装到我客户的受信任的根目录中,并使用 .pfx [服务器端] 来确认证书和身份验证顺利进行,没有任何错误
但是有一个问题让我很困惑,黑客有什么办法可以伪造我的客户端的身份验证吗?用他的假证书和服务器?
示例:
我验证认证的代码是
private static bool OnCertificateValidation(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
{
if (CaVerify(chain) && ServerVerify(certificate)) return true;
}
return false;
}
public static bool CaVerify(X509Chain chain)
{
if (chain.ChainElements.Count > 0)
{
var certHash = chain.ChainElements[chain.ChainElements.Count - 1].Certificate.GetCertHash();
if (certHash.Length == ApiCertHash.Length)
{
for (var idx = 0; idx < certHash.Length; idx++)
{
if (certHash[idx] == ApiCertHash[idx])
{
return true;
}
}
}
}
return false;
}
public static bool ServerVerify(X509Certificate certificate)
{
var certHash = certificate.GetCertHash();
if (certHash.Length == ApiCertHash.Length)
{
for (var idx = 0; idx < certHash.Length; idx++)
{
if (certHash[idx] == ApiCertHash[idx])
{
return true;
}
}
}
return false;
}
那么有人可以创建一个伪造的 certification.pfx 并将其关联到他的伪造服务器并将我的客户端连接到他的伪造服务器吗?
最佳答案
SSL 证书的通用名称 (CN) 字段应该是您尝试连接的主机的 DNS 名称。您“信任”“Trusted 根证书颁发机构”,他们不会在未验证 CN 中列出的 DNS 名称所有权的情况下使用 CN 颁发证书。
您已通过手动将证书颁发机构 (CA) 添加到受信任列表来绕过此问题。因此计算机信任您的个人 CA,它从服务器收到的证书被授权用于证书上列出的任何 CN。
攻击者无法制作“假”证书,因为颁发未经授权证书的 CA 不是“受信任的”,因此验证失败。
这就是协作代理通常的工作方式。 IT 部门在工作站上安装 CA。当您发出 SSL 请求时,它会通过代理,当回复返回时,代理会拦截“CN=*.google.com
Signed by VeriSign”并发送到您的工作站“CN= *.google.com
,由 XYZ Corperate Proxy 签名”。因为 IT 预安装 受信任的根 CA,所以浏览器不会提示。
但是,如果您使用的浏览器不使用普通商店,或者没有安装 CA,您会收到证书错误,因为您的计算机会看到“由 XYZ Coperate Proxy 签名”证书,不知道那个 CA 是谁, 然后返回 RemoteCertificateChainErrors
在 sslPolicyErrors
参数上。
检查 CA 哈希的代码示例。
if (sslPolicyErrors == SslPolicyErrors.None)
{
var apiCertHash = new byte[] { 0x79, 0x04, 0x15, 0xC5, 0xC4, 0xF1, 0x6A, 0xA7, 0xC9, 0x12, 0xBB, 0x23, 0xED, 0x5A, 0x60, 0xA7, 0x92, 0xA8, 0xD5, 0x94 };
if(chain.ChainElements.Count > 0)
{
//Not 100% if the root is first or last in the array. Don't have the program running to check.
var certHash = chain.ChainElements[chain.ChainElements.Count - 1].Certificate.GetCertHash();
if (certHash.Length == apiCertHash.Length)
{
for (var idx = 0; idx < certHash.Length; idx++)
{
if (certHash[idx] == apiCertHash[idx])
{
return true;
}
}
}
}
}
关于c# - 任何人都可以制作假证书吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443047/