Skip to content

Commit

Permalink
started work on Java Keystore support
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Oct 17, 2024
1 parent 6a79ea2 commit f236c43
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public DocGenerator(final boolean runExamples) {
"cargo-postgresql",
"installer", "mimetypes", "multipart", "images",
"tomcat", "jetty", "http-client", "http-client-j8",
"openai", "jtokkit",
"openai", "jtokkit", "keystores",
"jdbc-core", "jdbc-postgresql", "chinook-postgresql",
"ring", "ring-multipart", "ring-session", "ring-mw",
"ring-util", "server-side-events", "pretty-print"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public static boolean isValidModule(final VncKeyword module) {
"jetty",
"jsonl",
"jtokkit",
"keystores",
"kira",
"langchain",
"math",
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/com/github/jlangch/venice/util/ssl/Keystores.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* __ __ _
* \ \ / /__ _ __ (_) ___ ___
* \ \/ / _ \ '_ \| |/ __/ _ \
* \ / __/ | | | | (_| __/
* \/ \___|_| |_|_|\___\___|
*
*
* Copyright 2017-2024 Venice
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jlangch.venice.util.ssl;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.List;

import com.github.jlangch.venice.impl.util.CollectionUtil;


public class Keystores {

public static KeyStore load(
final InputStream is,
final String password
) throws KeyStoreException,
NoSuchAlgorithmException,
CertificateException,
IOException
{
final KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(is,password.toCharArray());

return keystore;
}

public static KeyStore load(
final byte[] ks,
final String password
) throws KeyStoreException,
NoSuchAlgorithmException,
CertificateException,
IOException {
try(ByteArrayInputStream is = new ByteArrayInputStream(ks)) {
return load(is, password);
}
}

public List<String> aliases(final KeyStore keystore) throws KeyStoreException {
return CollectionUtil.toList(keystore.aliases());
}

public Date expiryDate(final KeyStore keystore, final String alias) throws KeyStoreException {
return ((X509Certificate)keystore.getCertificate(alias)).getNotAfter();
}

public Date expiryDate(final KeyStore keystore) throws KeyStoreException {
Date expiryDate = null;

for(String alias: aliases(keystore)) {
expiryDate = ((X509Certificate)keystore.getCertificate(alias)).getNotAfter();
}

return expiryDate;
}

}
26 changes: 26 additions & 0 deletions src/main/resources/com/github/jlangch/venice/keystores.venice
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;;;; __ __ _
;;;; \ \ / /__ _ __ (_) ___ ___
;;;; \ \/ / _ \ '_ \| |/ __/ _ \
;;;; \ / __/ | | | | (_| __/
;;;; \/ \___|_| |_|_|\___\___|
;;;;
;;;;
;;;; Copyright 2017-2024 Venice
;;;;
;;;; Licensed under the Apache License, Version 2.0 (the "License");
;;;; you may not use this file except in compliance with the License.
;;;; You may obtain a copy of the License at
;;;;
;;;; http://www.apache.org/licenses/LICENSE-2.0
;;;;
;;;; Unless required by applicable law or agreed to in writing, software
;;;; distributed under the License is distributed on an "AS IS" BASIS,
;;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;;; See the License for the specific language governing permissions and
;;;; limitations under the License.

;;;; Venice Java Keystore functions


(ns keystores)

0 comments on commit f236c43

Please sign in to comment.