Last active
April 21, 2017 15:14
-
-
Save Mardaneus86/0a4cc5a65f2186fef4dbd5e629290fbb to your computer and use it in GitHub Desktop.
Code examples for the App security: SSL and certificate pinning blogpost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ServicePointManager.ServerCertificateValidationCallback += | |
(sender, certificate, chain, sslPolicyErrors) => { | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// validkeys should be a list of strings containing the trusted public keys | |
ServicePointManager.ServerCertificateValidationCallback += | |
(sender, certificate, chain, sslPolicyErrors) => { | |
return validkeys.Contains(certificate?.GetPublicKeyString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ServicePointManager.ServerCertificateValidationCallback += | |
(sender, certificate, chain, sslPolicyErrors) => { | |
if (certificate == null) | |
{ | |
return false; | |
} | |
foreach (var cert in chain.ChainPolicy.ExtraStore) | |
{ | |
if (cert.Subject == certificate?.Issuer) | |
{ | |
return validkeys.Contains(cert.GetPublicKeyString()); | |
} | |
} | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ServicePointManager.ServerCertificateValidationCallback += | |
(sender, certificate, chain, sslPolicyErrors) => { | |
return false; // this effectively disables all certificate checks, never use this approach in production code! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment