Skip to content

Commit

Permalink
refactoring keystores
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Oct 17, 2024
1 parent a8a078b commit 965cbd6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public DocSection section() {
certs.addItem(diBuilder.getDocItem("keystores/subject-dn", false));
certs.addItem(diBuilder.getDocItem("keystores/issuer-dn", false));
certs.addItem(diBuilder.getDocItem("keystores/expiry-date", false));
certs.addItem(diBuilder.getDocItem("keystores/expired", false));

return section;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public static String issuerDN(final KeyStore keystore, final String alias) throw
return certificate(keystore, alias).getIssuerDN().getName();
}

public static boolean hasExpired(final KeyStore keystore, final String alias) throws KeyStoreException {
return expiryDate(keystore, alias).isBefore(LocalDateTime.now());
}

public static LocalDateTime expiryDate(final KeyStore keystore, final String alias) throws KeyStoreException {
return toLocalDateTime(certificate(keystore, alias).getNotAfter());
}
Expand Down
45 changes: 39 additions & 6 deletions src/main/resources/com/github/jlangch/venice/keystores.venice
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"keystores/certificate",
"keystores/subject-dn",
"keystores/issuer-dn",
"keystores/expiry-date" ) }
"keystores/expiry-date"
"keystores/expired?" ) }

load [in password]

Expand Down Expand Up @@ -89,7 +90,8 @@
"keystores/certificate",
"keystores/subject-dn",
"keystores/issuer-dn",
"keystores/expiry-date" ) }
"keystores/expiry-date"
"keystores/expired?" ) }

aliases [keystore]

Expand All @@ -116,7 +118,8 @@
"keystores/aliases",
"keystores/subject-dn",
"keystores/issuer-dn",
"keystores/expiry-date" ) }
"keystores/expiry-date"
"keystores/expired?" ) }

certificate [keystore alias]

Expand All @@ -143,7 +146,8 @@
"keystores/aliases",
"keystores/certificate",
"keystores/issuer-dn",
"keystores/expiry-date" ) }
"keystores/expiry-date"
"keystores/expired?" ) }

subject-dn [keystore alias]

Expand All @@ -170,7 +174,8 @@
"keystores/aliases",
"keystores/certificate",
"keystores/subject-dn",
"keystores/expiry-date" ) }
"keystores/expiry-date"
"keystores/expired?" ) }

issuer-dn [keystore alias]

Expand All @@ -197,9 +202,37 @@
"keystores/aliases",
"keystores/certificate",
"keystores/subject-dn",
"keystores/issuer-dn" ) }
"keystores/issuer-dn"
"keystores/expired?" ) }

expiry-date [keystore alias]

{ :pre [(instance-of? :KeyStore keystore) (string? alias)] }
(. :Keystores :expiryDate keystore alias))


(defn
^{ :arglists '("(expired? keystore alias)")
:doc """
Returns true if the certificate with the given alias name in the
keystore has expired.
"""
:examples '(
"""
(do
(load-module :keystores)
(let [ks (keystores/load (io/file "cert.p12") "12345")
alias (first (keystores/aliases ks)]
(keystores/expired? ks alias)))
""")
:see-also '(
"keystores/load",
"keystores/aliases",
"keystores/certificate",
"keystores/subject-dn",
"keystores/issuer-dn" ) }

expired? [keystore alias]

{ :pre [(instance-of? :KeyStore keystore) (string? alias)] }
(. :Keystores :hasExpired keystore alias))

0 comments on commit 965cbd6

Please sign in to comment.