Skip to content

Commit

Permalink
[chore]: print cert leaf to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ii64 committed Aug 30, 2023
1 parent 040638b commit a63c126
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/efakturtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/OpenPajak/efaktur-go/pkg/provider/web"
"github.com/ii64/go-binder/binder"
Expand Down Expand Up @@ -109,6 +110,27 @@ func Main(args []string) {
conf.CertificatePath,
err)
}

log.Printf("[CERT-LEAF] -----------------------------\n")
log.Printf("[CERT-LEAF] SN : %s\n", tlsCert.Leaf.SerialNumber)
log.Printf("[CERT-LEAF] ISS : %q\n", tlsCert.Leaf.Issuer)
log.Printf("[CERT-LEAF] SUB : %q\n", tlsCert.Leaf.Subject)

expiryDur := tlsCert.Leaf.NotAfter.Sub(time.Now().UTC())
log.Printf("[CERT-LEAF] NOT BEFORE: %q", tlsCert.Leaf.NotBefore)
log.Printf("[CERT-LEAF] EXP IN %s [%.2f day(s)] (on %q)",
expiryDur,
expiryDur.Hours()/24,
tlsCert.Leaf.NotAfter)
log.Printf("[CERT-LEAF] -----------------------------\n")

if expiryDur < (time.Hour * 24 * 7 * 2) {
log.Printf("[WARNING] LEAF CERTIFICATE IS ABOUT TO EXPIRED IN %.2f DAY(s) !!!\n",
expiryDur.Hours()/24)
} else if expiryDur < 0 {
log.Fatalf("Leaf certificate is expired\n")
}

client, err := web.NewClient(web.ClientOptions{
TLSCertificate: tlsCert,
})
Expand Down

0 comments on commit a63c126

Please sign in to comment.