如果没有像SecureBlackbox这样的商业库,我如何在Windows Phone 8.0中进行证书固定? 我可以为Windows Phone 8.1做到这一点,但它不适用于WP8.0。
WP8.1代码
private async Task<bool> GetPublicKeysFromServer(string serverUrl)
{
//clear old cers
serverPublicKyes = new List<string>();
Uri serverUri = new Uri(serverUrl);
HttpClient httpClient = new HttpClient();
string responseData = string.Empty;
HttpResponseMessage response = new HttpResponseMessage();
response = await httpClient.GetAsync(serverUri);
List<Certificate> listCerts = new List<Certificate>();
listCerts.Add(response.RequestMessage.TransportInformation.ServerCertificate);
foreach (Certificate aCertificate in listCerts)
{
IBuffer buffer = aCertificate.GetCertificateBlob();
byte[] bCert = buffer.ToArray();
string scert = BitConverter.ToString(bCert);
byte[] rsaOID = EncodeOID("1.2.840.113549.1.1.1");//1.2.840.113549.1.1.1
string sOID = BitConverter.ToString(rsaOID);
int length;
int index = FindX509PubKeyIndex(bCert, rsaOID, out length);
// Found X509PublicKey in certificate so copy it.
if (index > -1)
{
byte[] X509PublicKey = new byte[length];
Array.Copy(bCert, index, X509PublicKey, 0, length);
string URLCertPublicKey = BitConverter.ToString(X509PublicKey);
serverPublicKyes.Add(URLCertPublicKey);
Debug.WriteLine("Site Cert: " + URLCertPublicKey);
}
}
return true;
}
WP8.0 API不支持:
Windows.Security.Cryptography 和 HttpRequestMessage.TransportInformation
感谢。
答案 0 :(得分:-1)
对于Windows Phone 8 / 8.1:Certificate pinning on windows phone 8/8.1
我不认为你可以不使用你提到的商业图书馆。你应该试一试。如果没有,那么我在这里找到Stack Overflow本身的一些内容(Read SSL Certificate Details on WP8):
对于WP8,您可以使用StreamSocket类,它具有 UpgradeToSslAsync()方法将为您执行TLS握手 异步操作。完成后,您可以使用 .Information.ServerCertificate属性检查你得到了 你期待的服务器证书。