commit 77e40f9d4a7a614b7ba62b4d13701479fbb6a35d Author: Stephen McQuay (smcquay) Date: Tue Dec 12 11:53:53 2017 -0800 init diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..340187d --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +MIT License +Copyright (c) 2017 Stephen McQuay + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..43ebfd2 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# certexp + +report certificate expiry for a collection of servers, which yields equivalent +information to: + +```bash +$ echo | openssl s_client -connect $hostname:$port 2> /dev/null | openssl x509 -noout -dates | grep notAfter +``` + +## example usage + +```bash +$ cat sites.txt +apple.com +google.com +amazon.com +imap.gmail.com:993 +$ cat sites.txt | certexp +apple.com 2018-10-31 23:59:59 +0000 UTC +google.com 2018-02-13 15:19:00 +0000 UTC +amazon.com 2018-09-21 23:59:59 +0000 UTC +imap.gmail.com 2018-02-27 09:29:00 +0000 UTC +``` diff --git a/main.go b/main.go new file mode 100644 index 0000000..e93cbb9 --- /dev/null +++ b/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "bufio" + "crypto/tls" + "fmt" + "log" + "net" + "os" +) + +func main() { + s := bufio.NewScanner(os.Stdin) + for s.Scan() { + line := s.Text() + if line == "" { + continue + } + + host, port := line, "443" + if h, p, err := net.SplitHostPort(line); err == nil { + host, port = h, p + } + + c, err := tls.Dial("tcp", fmt.Sprintf("%v:%v", host, port), nil) + if err != nil { + log.Fatalf("dial: %v", err) + } + if err := c.Handshake(); err != nil { + log.Fatalf("handshake: %v", err) + } + if err := c.Close(); err != nil { + log.Fatalf("close: %v", err) + } + + for _, chain := range c.ConnectionState().VerifiedChains { + for _, cert := range chain { + if cert.DNSNames != nil { + fmt.Printf("%-24v %v\n", host, cert.NotAfter) + } + } + } + } +}