From cd9b4c799f7aaa069fafe52270bb5452c7618f78 Mon Sep 17 00:00:00 2001 From: heqnx Date: Tue, 3 Jun 2025 23:07:00 +0300 Subject: added author --- main.go | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 8d9a57f..fd2d37b 100644 --- a/main.go +++ b/main.go @@ -117,9 +117,9 @@ func cloneCertificate(urlStr string) (certFilename, keyFilename string) { fmt.Fprintf(writer, "%s\t%s\t%s", host, certFilename, keyFilename) writer.Flush() fmt.Println() - fmt.Println() - fmt.Println("[inf] start an https server to test cloned certificate with:") - fmt.Printf("$ %s -cert %s -key %s -port 8000\n", os.Args[0], certFilename, keyFilename) + fmt.Println() + fmt.Println("[inf] start an https server to test cloned certificate with:") + fmt.Printf("$ %s -cert %s -key %s -port 8000\n", os.Args[0], certFilename, keyFilename) fmt.Println() fmt.Println("[inf] manually inspect and diff the original certificate and cloned certificate with:") fmt.Printf("$ openssl s_client -connect %s /dev/null | openssl x509 -noout -text > %s_original.txt\n", host, parsedURL.Host) @@ -133,12 +133,27 @@ func runHTTPSServer(certPath, keyPath string, portNumber string) { fmt.Fprintln(w, "Hello, world!") }) fmt.Printf("[inf] starting https server on https://127.0.0.1:%s\n", portNumber) - err := http.ListenAndServeTLS("127.0.0.1:"+portNumber, certPath, keyPath, nil) + err := http.ListenAndServeTLS("127.0.0.1:"+portNumber, certPath, keyPath, nil) if err != nil { log.Fatalf("[err] failed to start httpsserver: %v", err) } } +func init() { + const usageHeader = ` +tool designed to clone SSL/TLS certificates from a target server and create a new, self-signed look-alike certificate using its public key + +author: heqnx - https://heqnx.com + +` + flag.Usage = func() { + fmt.Fprint(os.Stderr, usageHeader) + fmt.Fprintf(os.Stderr, "usage of %s:\n", os.Args[0]) + flag.PrintDefaults() + } + flag.CommandLine.SetOutput(os.Stderr) +} + func main() { urlFlag := flag.String("url", "", "target https url to clone certificate from (e.g. https://google.com)") certFlag := flag.String("cert", "", "path to certificate file to use for a test https server") @@ -146,6 +161,11 @@ func main() { portFlag := flag.String("port", "8000", "port to use for a test https server") flag.Parse() + if flag.NFlag() == 0 && flag.NArg() == 0 { + flag.Usage() + os.Exit(1) + } + if *certFlag != "" || *keyFlag != "" { if *certFlag == "" || *keyFlag == "" { log.Fatal("[err] both -cert and -key must be supplied to run the HTTPS server") @@ -159,7 +179,6 @@ func main() { return } - flag.Usage() - os.Exit(1) + flag.Usage() + os.Exit(1) } - -- cgit v1.2.3