diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | certmon.go | 17 |
2 files changed, 15 insertions, 4 deletions
@@ -1,4 +1,4 @@ -# This file is part of certmon -*- nroff -*- +# This file is part of certmon # Copyright (C) 2019 Sergey Poznyakoff # # Certmon is free software; you can redistribute it and/or modify @@ -52,12 +52,23 @@ type CertResultList struct { Result []CertResult } +func CNMatch(pat, name string) bool { + pat = strings.ToLower(pat) + if (pat[0] == '*') { + return len(name) >= len(pat) && + strings.HasSuffix(name, pat[1:]) && + strings.Index(name[0:(len(name) - len(pat) + 1)], `.`) == -1 + } else { + return pat == name + } +} + func CertMatch(cert *x509.Certificate, cn string) bool { - if cn == `` || cert.Subject.CommonName == cn { + if cn == `` || CNMatch(cert.Subject.CommonName, cn) { return true } for _, name := range cert.DNSNames { - if cn == name { + if CNMatch(name, cn) { return true } } @@ -201,7 +212,7 @@ func (rl *CertResultList) Append(res CertResult) { } func (rl *CertResultList) Check(args *ArgList) { - cn := args.Next() + cn := strings.ToLower(args.Next()) addr := rl.Address; a := strings.Split(addr, `:`) switch (len(a)) { |