From d2d0c69f17edc78f08e501a4c4e2801750f3dc20 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 21 Nov 2018 13:00:26 +0100 Subject: [PATCH] benchmark certificate issuing --- transport/internet/tls/config_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/transport/internet/tls/config_test.go b/transport/internet/tls/config_test.go index 15fe59514..2c2fdefac 100644 --- a/transport/internet/tls/config_test.go +++ b/transport/internet/tls/config_test.go @@ -73,3 +73,27 @@ func TestInsecureCertificates(t *testing.T) { t.Fatal("Unexpected tls cipher suites list: ", tlsConfig.CipherSuites) } } + +func BenchmarkCertificateIssuing(b *testing.B) { + certificate := ParseCertificate(cert.MustGenerate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageCertSign))) + certificate.Usage = Certificate_AUTHORITY_ISSUE + + c := &Config{ + Certificate: []*Certificate{ + certificate, + }, + } + + tlsConfig := c.GetTLSConfig() + lenCerts := len(tlsConfig.Certificates) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + _, _ = tlsConfig.GetCertificate(&gotls.ClientHelloInfo{ + ServerName: "www.v2ray.com", + }) + delete(tlsConfig.NameToCertificate, "www.v2ray.com") + tlsConfig.Certificates = tlsConfig.Certificates[:lenCerts] + } +}