[FEATURE] Fix truststore path

This commit is contained in:
Gravita 2025-01-27 20:20:27 +07:00
parent 1d63fbbd93
commit 907332ff06
No known key found for this signature in database
GPG key ID: 543A8F335C9CD633
2 changed files with 7 additions and 1 deletions

View file

@ -63,7 +63,7 @@ public static void main(String[] args) throws Exception {
directories.collect(); directories.collect();
CertificateManager certificateManager = new CertificateManager(); CertificateManager certificateManager = new CertificateManager();
try { try {
certificateManager.readTrustStore(dir.resolve("truststore")); certificateManager.readTrustStore(directories.trustStore);
} catch (CertificateException e) { } catch (CertificateException e) {
throw new IOException(e); throw new IOException(e);
} }

View file

@ -29,6 +29,7 @@
public class CertificateManager { public class CertificateManager {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
public LauncherTrustManager trustManager; public LauncherTrustManager trustManager;
private Path truststorePath;
public void writePrivateKey(Path file, PrivateKey privateKey) throws IOException { public void writePrivateKey(Path file, PrivateKey privateKey) throws IOException {
writePrivateKey(IOHelper.newWriter(file), privateKey); writePrivateKey(IOHelper.newWriter(file), privateKey);
@ -91,6 +92,7 @@ public X509CertificateHolder readCertificate(Reader reader) throws IOException {
} }
public void readTrustStore(Path dir) throws IOException, CertificateException { public void readTrustStore(Path dir) throws IOException, CertificateException {
this.truststorePath = dir;
if (!IOHelper.isDir(dir)) { if (!IOHelper.isDir(dir)) {
Files.createDirectories(dir); Files.createDirectories(dir);
try { try {
@ -131,4 +133,8 @@ public LauncherTrustManager.CheckClassResult checkClass(Class<?> clazz) {
X509Certificate[] certificates = JVMHelper.getCertificates(clazz); X509Certificate[] certificates = JVMHelper.getCertificates(clazz);
return trustManager.checkCertificates(certificates, trustManager::stdCertificateChecker); return trustManager.checkCertificates(certificates, trustManager::stdCertificateChecker);
} }
public Path getTruststorePath() {
return truststorePath;
}
} }