Merge pull request #1860 from projectdiscovery/issue-1858-fix-ztls-ctx-err

fix `ztls` context deadline error
This commit is contained in:
Mzack9999 2024-08-12 21:10:52 +02:00 committed by GitHub
commit f07cf4c288
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,7 @@
package httpx
import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
@ -62,7 +63,9 @@ func (h *HTTPX) ZTLSGrab(r *http.Response) *clients.Response {
}
// canonical net concatenation
host = net.JoinHostPort(hostname, fmt.Sprint(port))
tlsConn, err := h.Dialer.DialTLS(r.Request.Context(), "tcp", host)
ctx, cancel := context.WithTimeout(context.Background(), h.Options.Timeout)
defer cancel()
tlsConn, err := h.Dialer.DialTLS(ctx, "tcp", host)
if err != nil {
return nil
}
@ -106,6 +109,7 @@ func convertCertificateToResponse(hostname string, cert *x509.Certificate) *clie
SHA1: clients.SHA1Fingerprint(cert.Raw),
SHA256: clients.SHA256Fingerprint(cert.Raw),
},
Serial: clients.FormatToSerialNumber(cert.SerialNumber),
}
response.IssuerDN = clients.ParseASN1DNSequenceWithZpkixOrDefault(cert.RawIssuer, cert.Issuer.String())
response.SubjectDN = clients.ParseASN1DNSequenceWithZpkixOrDefault(cert.RawSubject, cert.Subject.String())