public static CertificateQueryResult Query(UInt160 hash) { lock (results) { if (results.ContainsKey(hash)) { return(results[hash]); } results[hash] = new CertificateQueryResult { Type = CertificateQueryResultType.Querying }; } string address = Wallet.ToAddress(hash); string path = Path.Combine(Settings.Default.CertCachePath, $"{address}.cer"); if (File.Exists(path)) { lock (results) { UpdateResultFromFile(hash); } } else { string url = $"http://cert.onchain.com/antshares/{address}.cer"; web.DownloadDataAsync(new Uri(url), hash); } return(results[hash]); }
public static CertificateQueryResult Query(ECPoint pubkey) { if (pubkey.Equals(Blockchain.AntShare.Issuer) || pubkey.Equals(Blockchain.AntCoin.Issuer)) return new CertificateQueryResult { Type = CertificateQueryResultType.System }; Directory.CreateDirectory(Settings.Default.CertCachePath); string path = Path.Combine(Settings.Default.CertCachePath, $"{pubkey}.cer"); if (!File.Exists(path)) { //TODO: 本地缓存中找不到证书的情况下,去公共服务器上查询 } if (!File.Exists(path)) return new CertificateQueryResult { Type = CertificateQueryResultType.Missing }; X509Certificate2 cert; try { cert = new X509Certificate2(path); } catch (CryptographicException) { return new CertificateQueryResult { Type = CertificateQueryResultType.Missing }; } if (cert.PublicKey.Oid.Value != "1.2.840.10045.2.1") return new CertificateQueryResult { Type = CertificateQueryResultType.Missing }; if (!pubkey.Equals(ECPoint.DecodePoint(cert.PublicKey.EncodedKeyValue.RawData, ECCurve.Secp256r1))) return new CertificateQueryResult { Type = CertificateQueryResultType.Missing }; using (X509Chain chain = new X509Chain()) { CertificateQueryResult result = new CertificateQueryResult { Certificate = cert }; if (chain.Build(cert)) { result.Type = CertificateQueryResultType.Good; } else if (chain.ChainStatus.Length == 1 && chain.ChainStatus[0].Status == X509ChainStatusFlags.NotTimeValid) { result.Type = CertificateQueryResultType.Expired; } else { result.Type = CertificateQueryResultType.Invalid; } return result; } }
public static CertificateQueryResult Query(ECPoint pubkey, string url) { if (pubkey.Equals(Blockchain.AntShare.Issuer) || pubkey.Equals(Blockchain.AntCoin.Issuer)) { return new CertificateQueryResult { Type = CertificateQueryResultType.System } } ; Directory.CreateDirectory(Settings.Default.CertCachePath); string path = Path.Combine(Settings.Default.CertCachePath, $"{pubkey}.cer"); if (!File.Exists(path)) { if (string.IsNullOrEmpty(url)) { url = $"http://cert.onchain.com/antshares/{pubkey}.cer"; } using (WebClient web = new WebClient()) { try { web.DownloadFile(url, path); } catch (WebException) { } } } if (!File.Exists(path)) { return new CertificateQueryResult { Type = CertificateQueryResultType.Missing } } ; X509Certificate2 cert; try { cert = new X509Certificate2(path); } catch (CryptographicException) { return(new CertificateQueryResult { Type = CertificateQueryResultType.Missing }); } if (cert.PublicKey.Oid.Value != "1.2.840.10045.2.1") { return new CertificateQueryResult { Type = CertificateQueryResultType.Missing } } ; if (!pubkey.Equals(ECPoint.DecodePoint(cert.PublicKey.EncodedKeyValue.RawData, ECCurve.Secp256r1))) { return new CertificateQueryResult { Type = CertificateQueryResultType.Missing } } ; using (X509Chain chain = new X509Chain()) { CertificateQueryResult result = new CertificateQueryResult { Certificate = cert }; if (chain.Build(cert)) { result.Type = CertificateQueryResultType.Good; } else if (chain.ChainStatus.Length == 1 && chain.ChainStatus[0].Status == X509ChainStatusFlags.NotTimeValid) { result.Type = CertificateQueryResultType.Expired; } else { result.Type = CertificateQueryResultType.Invalid; } return(result); } } } }
public static CertificateQueryResult Query(ECPoint pubkey) { if (pubkey.Equals(Blockchain.AntShare.Issuer) || pubkey.Equals(Blockchain.AntCoin.Issuer)) { return new CertificateQueryResult { Type = CertificateQueryResultType.System } } ; Directory.CreateDirectory(Settings.Default.CertCachePath); string path = Path.Combine(Settings.Default.CertCachePath, $"{pubkey}.cer"); if (!File.Exists(path)) { //TODO: 本地缓存中找不到证书的情况下,去公共服务器上查询 } if (!File.Exists(path)) { return new CertificateQueryResult { Type = CertificateQueryResultType.Missing } } ; X509Certificate2 cert; try { cert = new X509Certificate2(path); } catch (CryptographicException) { return(new CertificateQueryResult { Type = CertificateQueryResultType.Missing }); } if (cert.PublicKey.Oid.Value != "1.2.840.10045.2.1") { return new CertificateQueryResult { Type = CertificateQueryResultType.Missing } } ; if (!pubkey.Equals(ECPoint.DecodePoint(cert.PublicKey.EncodedKeyValue.RawData, ECCurve.Secp256r1))) { return new CertificateQueryResult { Type = CertificateQueryResultType.Missing } } ; using (X509Chain chain = new X509Chain()) { CertificateQueryResult result = new CertificateQueryResult { Certificate = cert }; if (chain.Build(cert)) { result.Type = CertificateQueryResultType.Good; } else if (chain.ChainStatus.Length == 1 && chain.ChainStatus[0].Status == X509ChainStatusFlags.NotTimeValid) { result.Type = CertificateQueryResultType.Expired; } else { result.Type = CertificateQueryResultType.Invalid; } return(result); } } } }