Skip to content

Commit

Permalink
completed first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
encbladexp committed Sep 30, 2024
1 parent 7eef2bc commit 5897ea9
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"encoding/csv"
"errors"
"fmt"
"os"
"strings"
"time"
)

Expand All @@ -20,6 +22,12 @@ const (
CERT_CN
)

const (
OUTPUT_EXPIRED = "CRITICAL: already expired"
OUTPUT_EXPIRES_30D = "WARNING: expires in < 30d"
OUTPUT_EXPIRES_90D = "INFO: expires in < 90d"
)

var TIME_90D = time.Now().Add(90 * 24 * time.Hour)
var TIME_30D = time.Now().Add(30 * 24 * time.Hour)
var TIME_NOW = time.Now()
Expand Down Expand Up @@ -77,15 +85,38 @@ func (c *Certificates) process_line(line []string) {
}
}

func (c *Certificate) get_certificate_cn() (*string, error) {
t := strings.Split(*c.CN, "/")
for _, item := range t {
if strings.HasPrefix(item, "CN=") {
cn := strings.TrimPrefix(item, "CN=")
return &cn, nil
}
}
return nil, errors.New("No CN found!")
}

func (c *Certificates) print_expired() {
for _, cert := range c.Certificates {
var cn *string
var err error
var expired string
if cert.Expired.Before(TIME_NOW) {
fmt.Println("That certificate is already expired!")
cn, err = cert.get_certificate_cn()
expired = OUTPUT_EXPIRED
} else if cert.Expired.Before(TIME_30D) {
fmt.Println("This certificate will expire in <= 30d")
cn, err = cert.get_certificate_cn()
expired = OUTPUT_EXPIRES_30D
} else if cert.Expired.Before(TIME_90D) {
fmt.Println("This certificate will expire in <= 90d")
cn, err = cert.get_certificate_cn()
expired = OUTPUT_EXPIRES_90D
} else {
continue
}
if err != nil {
panic(err)
}
fmt.Println("Expiry Date:", cert.Expired.Format(time.DateOnly), "CN:", *cn, "SN:", *cert.Serial, expired)
}
}

Expand Down

0 comments on commit 5897ea9

Please sign in to comment.