aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/KeystoreManager.java25
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java5
2 files changed, 8 insertions, 22 deletions
diff --git a/src/main/java/com/juick/KeystoreManager.java b/src/main/java/com/juick/KeystoreManager.java
index e6979a5c..5a2a98c1 100644
--- a/src/main/java/com/juick/KeystoreManager.java
+++ b/src/main/java/com/juick/KeystoreManager.java
@@ -22,6 +22,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.util.Base64Utils;
+import org.tomitribe.churchkey.Key;
+import org.tomitribe.churchkey.Keys;
import javax.net.ssl.KeyManagerFactory;
import java.io.IOException;
@@ -53,7 +55,7 @@ public class KeystoreManager {
}
private KeyPair getKeyPair() {
- Key privateKey;
+ java.security.Key privateKey;
try {
privateKey = ks.getKey("1", keystorePassword.toCharArray());
Certificate certificate = ks.getCertificate("1");
@@ -69,24 +71,13 @@ public class KeystoreManager {
public PublicKey getPublicKey() {
return getKeyPair().getPublic();
}
+
public String getPublicKeyPem() {
- String[] key = Base64Utils.encodeToString(getKeyPair().getPublic().getEncoded()).split("(?<=\\G.{64})");
- return String.format("-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
- String.join("\n", key));
+ return new String(Keys.of(getPublicKey()).encode(Key.Format.PEM));
}
- public static PublicKey publicKeyOf(Actor person) {
+
+ public static java.security.Key publicKeyOf(Actor person) {
String pubkeyPem = person.getPublicKey().getPublicKeyPem();
- String[] rawKey = pubkeyPem.split("\\n");
- String pubkeyData = String.join("", Arrays.asList(rawKey).subList(1, rawKey.length - 1));
- try{
- byte[] byteKey = Base64Utils.decodeFromString(pubkeyData);
- X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey);
- KeyFactory kf = KeyFactory.getInstance("RSA");
- return kf.generatePublic(X509publicKey);
- }
- catch(Exception e){
- logger.error("Public key error", e);
- }
- return null;
+ return Keys.decode(pubkeyPem.getBytes()).getKey();
}
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index a23c0a6f..d599bbea 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -60,8 +60,6 @@ import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
@@ -72,12 +70,9 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
-import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
-import java.security.PrivateKey;
-import java.security.Security;
import java.security.spec.InvalidKeySpecException;
import java.sql.Timestamp;
import java.time.Instant;