public bool Check(string hostname, X509Certificate2 certificate) { // Get pins if (!_pins.TryGetValue(hostname, out var pins)) { _logger?.LogDebug($"No certificate pin found for {hostname}"); return(true); } // Compute spki fingerprint var spkiFingerprint = SpkiFingerprint.Compute(certificate); // Check pin var match = Array.IndexOf(pins, spkiFingerprint) > -1; if (match) { _logger?.LogDebug($"Certificate pin is ok for {hostname}"); } else { _logger?.LogInformation($"Certificate pin error for {hostname}: found {spkiFingerprint}, expected {string.Join("|", pins)}"); } return(match); }
public bool Check(string hostname, byte[] certificate) { // Get pins string[] pins; if (!_pins.TryGetValue(hostname, out pins)) { Debug.WriteLine($"No certificate pin found for {hostname}"); return(true); } // Compute spki fingerprint var spkiFingerprint = SpkiFingerprint.Compute(certificate); // Check pin var match = Array.IndexOf(pins, spkiFingerprint) > -1; Debug.WriteLine(match ? $"Certificate pin is ok for {hostname}" : $"Certificate pin error for {hostname}: found {spkiFingerprint}, expected {string.Join("|", pins)}"); return(match); }