diff options
author | Vitaly Takmazov | 2022-04-07 20:15:28 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-04-08 15:17:01 +0300 |
commit | a77884b98032bde77cb3667da03809b2b9858de6 (patch) | |
tree | 1d3e0fe2e6815dd544d64f2f8d405b1ba9281ce9 /src/main/java/com | |
parent | 94d52e4e4022678bce895c4a567d1c9c9d01560a (diff) |
ActivityPub: handle public key issues
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/juick/KeystoreManager.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/SignatureManager.java | 40 |
2 files changed, 23 insertions, 19 deletions
diff --git a/src/main/java/com/juick/KeystoreManager.java b/src/main/java/com/juick/KeystoreManager.java index 32596170..e6979a5c 100644 --- a/src/main/java/com/juick/KeystoreManager.java +++ b/src/main/java/com/juick/KeystoreManager.java @@ -85,7 +85,7 @@ public class KeystoreManager { return kf.generatePublic(X509publicKey); } catch(Exception e){ - e.printStackTrace(); + logger.error("Public key error", e); } return null; } diff --git a/src/main/java/com/juick/SignatureManager.java b/src/main/java/com/juick/SignatureManager.java index 0c6acb4a..49c8c7dd 100644 --- a/src/main/java/com/juick/SignatureManager.java +++ b/src/main/java/com/juick/SignatureManager.java @@ -129,26 +129,30 @@ public class SignatureManager { if (context.isPresent() && context.get() instanceof Actor) { Actor actor = (Actor) context.get(); Key key = KeystoreManager.publicKeyOf(actor); - - Verifier verifier = new Verifier(key, signature); - try { - boolean result = verifier.verify(method, path, headers); - if (result) { - User user = new User(); - user.setUri(URI.create(actor.getId())); - if (key.equals(keystoreManager.getPublicKey())) { - return userService.getUserByName(actor.getName()); - } - if (actor.isSuspended()) { - logger.info("{} is suspended, deleting", actor.getId()); - applicationEventPublisher.publishEvent(new DeleteUserEvent(this, actor.getId())); + if (key != null) { + Verifier verifier = new Verifier(key, signature); + try { + boolean result = verifier.verify(method, path, headers); + if (result) { + User user = new User(); + user.setUri(URI.create(actor.getId())); + if (key.equals(keystoreManager.getPublicKey())) { + return userService.getUserByName(actor.getName()); + } + if (actor.isSuspended()) { + logger.info("{} is suspended, deleting", actor.getId()); + applicationEventPublisher.publishEvent(new DeleteUserEvent(this, actor.getId())); + } + return user; + } else { + return AnonymousUser.INSTANCE; } - return user; - } else { - return AnonymousUser.INSTANCE; + } catch (NoSuchAlgorithmException | SignatureException | MissingRequiredHeaderException + | IOException e) { + logger.warn("Invalid signature {}: {}", signatureString, e.getMessage()); } - } catch (NoSuchAlgorithmException | SignatureException | MissingRequiredHeaderException | IOException e) { - logger.warn("Invalid signature {}: {}", signatureString, e.getMessage()); + } else { + logger.warn("Unknown actor"); } } else { logger.warn("Unknown keyId"); |