Zertifikatspinning eingebaut
This commit is contained in:
@@ -9,6 +9,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
@@ -54,8 +56,51 @@ namespace ChatController.HauptKlassen
|
||||
ChatDaten = chatDaten;
|
||||
ExceptionCallback = exceptionCallback;
|
||||
ThreadExceptionCallback = threadExceptionCallback;
|
||||
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
|
||||
PinCertificate();
|
||||
}
|
||||
|
||||
private void PinCertificate()
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = PinPublicKey;
|
||||
}
|
||||
|
||||
private static bool PinPublicKey(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(certificate == null || chain == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var chainContainsPk = false;
|
||||
|
||||
foreach(var element in chain.ChainElements)
|
||||
{
|
||||
var pk = element.Certificate.GetPublicKeyString();
|
||||
if(pk == PubKeyX3 || pk == PubKeyR3)
|
||||
{
|
||||
chainContainsPk = true;
|
||||
}
|
||||
}
|
||||
|
||||
var subjectAccepted = certificate.Subject.Trim().ToLower().EndsWith(".bewoplaner.de") || certificate.Subject.Trim().ToLower().EndsWith(".ownchat.de");
|
||||
|
||||
return chainContainsPk && subjectAccepted;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private const string PubKeyX3 = "3082010A02820101009CD30CF05AE52E47B7725D3783B3686330EAD735261925E1BDBE35F170922FB7B84B4105ABA99E350858ECB12AC468870BA3E375E4E6F3A76271BA7981601FD7919A9FF3D0786771C8690E9591CFFEE699E9603C48CC7ECA4D7712249D471B5AEBB9EC1E37001C9CAC7BA705EACE4AEBBD41E53698B9CBFD6D3C9668DF232A42900C867467C87FA59AB8526114133F65E98287CBDBFA0E56F68689F3853F9786AFB0DC1AEF6B0D95167DC42BA065B299043675806BAC4AF31B9049782FA2964F2A20252904C674C0D031CD8F31389516BAA833B843F1B11FC3307FA27931133D2D36F8E3FCF2336AB93931C5AFC48D0D1D641633AAFA8429B6D40BC0D87DC3930203010001";
|
||||
|
||||
private const string PubKeyR3 = "3082010A0282010100BB021528CCF6A094D30F12EC8D5592C3F882F199A67A4288A75D26AAB52BB9C54CB1AF8E6BF975C8A3D70F4794145535578C9EA8A23919F5823C42A94E6EF53BC32EDB8DC0B05CF35938E7EDCF69F05A0B1BBEC094242587FA3771B313E71CACE19BEFDBE43B45524596A9C153CE34C852EEB5AEED8FDE6070E2A554ABB66D0E97A540346B2BD3BC66EB66347CFA6B8B8F572999F830175DBA726FFB81C5ADD286583D17C7E709BBF12BF786DCC1DA715DD446E3CCAD25C188BC60677566B3F118F7A25CE653FF3A88B647A5FF1318EA9809773F9D53F9CF01E5F5A6701714AF63A4FF99B3939DDC53A706FE48851DA169AE2575BB13CC5203F5ED51A18BDB150203010001";
|
||||
|
||||
// WebRequest
|
||||
public List<Contact> AddContacts()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user