Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing high memory consumption #155

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/tlsx/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,25 +312,29 @@ func IsMisMatchedCert(host string, alternativeNames []string) bool {
}

// IsTLSRevoked returns true if the certificate has been revoked or failed to parse
func IsTLSRevoked(cert *x509.Certificate) bool {
func IsTLSRevoked(options *Options, cert *x509.Certificate) bool {
zcert, err := zx509.ParseCertificate(cert.Raw)
if err != nil {
return true
} else {
return IsZTLSRevoked(zcert)
return IsZTLSRevoked(options, zcert)
}
}

// IsZTLSRevoked returns true if the certificate has been revoked
func IsZTLSRevoked(cert *zx509.Certificate) bool {
func IsZTLSRevoked(options *Options, cert *zx509.Certificate) bool {
var OCSPisRevoked bool = false
var OCSPerr error
// TODO : Verify Upstream Patch and remove extra condition when fixed
if len(cert.IssuingCertificateURL) > 0 && len(cert.OCSPServer) > 0 {
OCSPisRevoked, _, OCSPerr = zverifier.CheckOCSP(context.TODO(), cert, nil)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(options.Timeout)*time.Second)
defer cancel()
OCSPisRevoked, _, OCSPerr = zverifier.CheckOCSP(ctx, cert, nil)
}
if len(cert.CRLDistributionPoints) != 0 {
CRLisRevoked, _, CRLerr := zverifier.CheckCRL(context.TODO(), cert, nil)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(options.Timeout)*time.Second)
defer cancel()
CRLisRevoked, _, CRLerr := zverifier.CheckCRL(ctx, cert, nil)

if CRLerr == nil {
if OCSPerr == nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/tlsx/clients/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/x509"
)

func Convertx509toResponse(hostname string, cert *x509.Certificate, showcert bool) *CertificateResponse {
func Convertx509toResponse(options *Options, hostname string, cert *x509.Certificate, showcert bool) *CertificateResponse {
response := &CertificateResponse{
SubjectAN: cert.DNSNames,
Emails: cert.EmailAddresses,
Expand All @@ -13,7 +13,7 @@ func Convertx509toResponse(hostname string, cert *x509.Certificate, showcert boo
Expired: IsExpired(cert.NotAfter),
SelfSigned: IsSelfSigned(cert.AuthorityKeyId, cert.SubjectKeyId),
MisMatched: IsMisMatchedCert(hostname, append(cert.DNSNames, cert.Subject.CommonName)),
Revoked: IsTLSRevoked(cert),
Revoked: IsTLSRevoked(options, cert),
WildCardCert: IsWildCardCert(append(cert.DNSNames, cert.Subject.CommonName)),
IssuerCN: cert.Issuer.CommonName,
IssuerOrg: cert.Issuer.Organization,
Expand Down
4 changes: 2 additions & 2 deletions pkg/tlsx/openssl/openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C
ProbeStatus: true,
Port: port,
Version: resp.Session.getTLSVersion(),
CertificateResponse: clients.Convertx509toResponse(hostname, resp.AllCerts[0], c.options.Cert),
CertificateResponse: clients.Convertx509toResponse(c.options, hostname, resp.AllCerts[0], c.options.Cert),
Cipher: resp.Session.Cipher,
TLSConnection: "openssl",
ServerName: opensslOptions.ServerName,
Expand All @@ -107,7 +107,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C
responses := []*clients.CertificateResponse{}
certs := getCertChain(ctx, opensslOptions)
for _, v := range certs {
responses = append(responses, clients.Convertx509toResponse(hostname, v, c.options.Cert))
responses = append(responses, clients.Convertx509toResponse(c.options, hostname, v, c.options.Cert))
}
response.Chain = responses
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/tlsx/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C
Version: tlsVersion,
Cipher: tlsCipher,
TLSConnection: "ctls",
CertificateResponse: clients.Convertx509toResponse(hostname, leafCertificate, c.options.Cert),
CertificateResponse: clients.Convertx509toResponse(c.options, hostname, leafCertificate, c.options.Cert),
ServerName: config.ServerName,
}
if c.options.TLSChain {
for _, cert := range certificateChain {
response.Chain = append(response.Chain, clients.Convertx509toResponse(hostname, cert, c.options.Cert))
response.Chain = append(response.Chain, clients.Convertx509toResponse(c.options, hostname, cert, c.options.Cert))
}
}
return response, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/tlsx/ztls/ztls.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func ConvertCertificateToResponse(options *clients.Options, hostname string, cer
Expired: clients.IsExpired(cert.NotAfter),
SelfSigned: clients.IsSelfSigned(cert.AuthorityKeyId, cert.SubjectKeyId),
MisMatched: clients.IsMisMatchedCert(hostname, append(cert.DNSNames, cert.Subject.CommonName)),
Revoked: clients.IsZTLSRevoked(cert),
Revoked: clients.IsZTLSRevoked(options, cert),
WildCardCert: clients.IsWildCardCert(append(cert.DNSNames, cert.Subject.CommonName)),
IssuerDN: cert.Issuer.String(),
IssuerCN: cert.Issuer.CommonName,
Expand Down