summaryrefslogtreecommitdiff
path: root/pkg/vpn/certs.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/vpn/certs.go')
-rw-r--r--pkg/vpn/certs.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/vpn/certs.go b/pkg/vpn/certs.go
new file mode 100644
index 0000000..300871e
--- /dev/null
+++ b/pkg/vpn/certs.go
@@ -0,0 +1,34 @@
+package vpn
+
+import (
+ "crypto/x509"
+ "encoding/pem"
+ "io/ioutil"
+ "log"
+ "time"
+)
+
+func isValidCert(path string) bool {
+ data, err := ioutil.ReadFile(path)
+ if err != nil {
+ return false
+ }
+ // skip private key, but there should be one
+ _, rest := pem.Decode(data)
+ certBlock, rest := pem.Decode(rest)
+ if len(rest) != 0 {
+ log.Println("ERROR bad cert data")
+ return false
+ }
+ cert, err := x509.ParseCertificate(certBlock.Bytes)
+ loc, _ := time.LoadLocation("UTC")
+ expires := cert.NotAfter
+ tomorrow := time.Now().In(loc).Add(24 * time.Hour)
+
+ if !expires.After(tomorrow) {
+ return false
+ } else {
+ log.Println("DEBUG We have a valid cert:", path)
+ return true
+ }
+}