private static bool CheckThumbprint(X509Certificate certificate) { var x509 = certificate as X509Certificate2; return(!String.IsNullOrEmpty(Thumbprint) && x509 != null && x509.Thumbprint.Equals(Thumbprint.Replace(":", ""), StringComparison.InvariantCultureIgnoreCase)); }
public bool Equals(CQPeer other) { var result = other != null && (ReferenceEquals(this, other) || Thumbprint?.Equals(other.Thumbprint) != false); return(result); }
public override int GetHashCode() { if (string.IsNullOrWhiteSpace(Thumbprint)) { throw new ArgumentException($"{nameof(Thumbprint)} cannot be null or whitespace."); } return(Thumbprint.GetHashCode()); }
private bool MatchesThumbprint(X509Certificate2 certificate) { var expectedThumbprint = Thumbprint.Replace(" ", "").ToLowerInvariant(); var actualThumbprint = certificate.Thumbprint.Replace(" ", "").ToLowerInvariant(); return(string.Equals(expectedThumbprint, actualThumbprint)); }
public override int GetHashCode() { unchecked { var hashCode = Subject?.GetHashCode() ?? 0; hashCode = (hashCode * 397) ^ (IssuedBy?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ NotBefore.GetHashCode(); hashCode = (hashCode * 397) ^ NotAfter.GetHashCode(); hashCode = (hashCode * 397) ^ (Thumbprint?.GetHashCode() ?? 0); return(hashCode); } }
public void LoadCertificate(HardwareCertificateUnlocker unlocker) { Certificate?.Dispose(); using (var store = new X509Store(StoreName, StoreLocation)) { store.Open(OpenFlags.ReadOnly); var certificates = store.Certificates.OfType <X509Certificate2>() .Where(c => Thumbprint.Equals(c.Thumbprint, StringComparison.InvariantCultureIgnoreCase)).ToArray(); if (certificates.Length == 0) { throw new CertificateNotFoundException($"No certificate with the thumbprint '{Thumbprint}' found"); } Certificate = certificates.FirstOrDefault(c => c.HasPrivateKey); if (Certificate == null) { throw new CertificateNotFoundException($"Certificate with thumbprint '{Thumbprint}' has no private key"); } // For SmartCards/Hardware dongles we create a new RSACryptoServiceProvider with the corresponding pin var rsa = (RSACryptoServiceProvider)Certificate.PrivateKey; if (rsa.CspKeyContainerInfo.HardwareDevice) { var keyPassword = new SecureString(); var decrypted = DataProtector.UnprotectData(TokenPin); foreach (var c in decrypted) { keyPassword.AppendChar(c); } var csp = new CspParameters(1 /*RSA*/, rsa.CspKeyContainerInfo.ProviderName, rsa.CspKeyContainerInfo.KeyContainerName, new System.Security.AccessControl.CryptoKeySecurity(), keyPassword); var oldCert = Certificate; Certificate = new X509Certificate2(oldCert.RawData) { PrivateKey = new RSACryptoServiceProvider(csp) }; oldCert.Dispose(); unlocker?.RegisterForUpdate(this); } } }
private async Task EnsureConnectedAsync() { if (stream != null) { return; } var tcpClient = new TcpClient(); await tcpClient.ConnectAsync(Host, Port); stream = new SslStream(tcpClient.GetStream(), false, (source, cert, chain, policy) => { return(Thumbprint.Equals(cert.GetCertHashString(), StringComparison.OrdinalIgnoreCase)); }); await stream.AuthenticateAsClientAsync("", new X509CertificateCollection(), SslProtocols.Tls, true); }
public async Task <int> ExecuteAsync() { HttpClient client = new HttpClient(); var userName = await client.GetStringAsync(new Uri($"{Program.Config.BaseUrl}cert/Thumbprint/{Thumbprint.ToUpperInvariant()}")).ConfigureAwait(true); client.Dispose(); if (userName != null) { Output.WriteInfo($"The certificate with thumbprint {Thumbprint.ToUpperInvariant()} is registered with user https://github.com/{userName}"); Output.WriteInfo($"\n Query the certificates of user '{userName}' by running:"); Output.WriteInfo($"ccc certs -u {userName}\n"); } else { Output.WriteWarning("Thumbprint not found"); } return(ReturnCode.Success); }
public bool Contains(string value) { return ( FriendlyName.Contains(value) || Subject.Contains(value) || Issuer.Contains(value) || SerialNumber.Contains(value) || Thumbprint.Contains(value) || KeyAlgorithm.Contains(value) || SignatureAlgorithm.Contains(value) || Version.Contains(value) || Format.Contains(value) || Extentions.Contains(value) || StoreLocation.Contains(value) || StoreName.Contains(value) || EffectiveDate.ToString().Contains(value) || ExpirationDate.ToString().Contains(value) ); }
public override int GetHashCode() { return(Timestamp.GetHashCode() ^ User.GetHashCode() ^ Status.GetHashCode() ^ Thumbprint.GetHashCode() ^ KeyPair.GetHashCode()); }