summaryrefslogtreecommitdiff
path: root/diff.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2017-02-06 18:10:18 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2017-02-06 18:10:18 -0500
commit92818dff6962495949da5c518732097d5e52a721 (patch)
treeda07c6269852a5e68d5db8855a8c53b78517c73b /diff.go
parent74fa9411545e30c64c75eae0b2b1dfccd8741a2f (diff)
Correctly deal with failing to get a cert (eg: because of a timeout)
Diffstat (limited to 'diff.go')
-rw-r--r--diff.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/diff.go b/diff.go
index 96947b6..da27a62 100644
--- a/diff.go
+++ b/diff.go
@@ -6,8 +6,10 @@ import (
"fmt"
"io"
"io/ioutil"
+ "net/url"
"os"
"sort"
+ "strings"
)
func handleErr(err error, str string, a ...interface{}) {
@@ -51,11 +53,19 @@ func readTLS(filename string) (map[string]Cert, error) {
certPem, data = pem.Decode(data)
certX509, err := x509.ParseCertificate(certPem.Bytes)
if err != nil {
- return nil, err
- }
- ret[certX509.Subject.CommonName] = Cert{
- Url: fmt.Sprintf("https://crt.sh/?serial=%036x", certX509.SerialNumber),
- X509: certX509,
+ url, err2 := url.Parse(certPem.Headers["X-Socket"])
+ if err2 != nil {
+ fmt.Fprintf(os.Stderr, "Could not get cert or even parse URL:\ncert: %v\nurl: %v\n", err, err2)
+ os.Exit(1)
+ }
+ ret[strings.Split(url.Host, ":")[0]] = Cert{
+ X509: new(x509.Certificate),
+ }
+ } else {
+ ret[certX509.Subject.CommonName] = Cert{
+ Url: fmt.Sprintf("https://crt.sh/?serial=%036x", certX509.SerialNumber),
+ X509: certX509,
+ }
}
}
return ret, nil