@Test public void incorrectLengthSignatureShouldReturnFalse() throws Exception { assertThat(signatureHandler.verify(SOURCE, "c2lnbmF0dXJl")).isFalse(); }
@Override public boolean verify(String source, String signature) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(signature); try { Signature javaSignature = Signature.getInstance(ALGORITHM); javaSignature.initVerify(securityKeys.getPublicKey()); javaSignature.update(source.getBytes()); return javaSignature.verify(Base64.getDecoder().decode(signature)); } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new RuntimeException(e); } catch (SignatureException e) { LOGGER.warn("Attempt to use a malformed signature '{}' for source '{}'", signature, source, e); return false; } }
JamesSignatureHandler implements SignatureHandler { @Override public boolean verify(String source, String signature) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(signature); try { Signature javaSignature = Signature.getInstance(ALGORITHM); javaSignature.initVerify(securityKeys.getPublicKey()); javaSignature.update(source.getBytes()); return javaSignature.verify(Base64.getDecoder().decode(signature)); } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new RuntimeException(e); } catch (SignatureException e) { LOGGER.warn("Attempt to use a malformed signature '{}' for source '{}'", signature, source, e); return false; } } }
JamesSignatureHandler implements SignatureHandler { @Override public boolean verify(String source, String signature) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(signature); try { Signature javaSignature = Signature.getInstance(ALGORITHM); javaSignature.initVerify(securityKeys.getPublicKey()); javaSignature.update(source.getBytes()); return javaSignature.verify(Base64.getDecoder().decode(signature)); } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new RuntimeException(e); } catch (SignatureException e) { LOGGER.warn("Attempt to use a malformed signature '{}' for source '{}'", signature, source, e); return false; } } @Inject @VisibleForTesting  JamesSignatureHandler(SecurityKeyLoader keyLoader); }
JamesSignatureHandler implements SignatureHandler { @Override public boolean verify(String source, String signature) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(signature); try { Signature javaSignature = Signature.getInstance(ALGORITHM); javaSignature.initVerify(securityKeys.getPublicKey()); javaSignature.update(source.getBytes()); return javaSignature.verify(Base64.getDecoder().decode(signature)); } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new RuntimeException(e); } catch (SignatureException e) { LOGGER.warn("Attempt to use a malformed signature '{}' for source '{}'", signature, source, e); return false; } } @Inject @VisibleForTesting  JamesSignatureHandler(SecurityKeyLoader keyLoader); @Override void init(); @Override String sign(String source); @Override boolean verify(String source, String signature); }
JamesSignatureHandler implements SignatureHandler { @Override public boolean verify(String source, String signature) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(signature); try { Signature javaSignature = Signature.getInstance(ALGORITHM); javaSignature.initVerify(securityKeys.getPublicKey()); javaSignature.update(source.getBytes()); return javaSignature.verify(Base64.getDecoder().decode(signature)); } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new RuntimeException(e); } catch (SignatureException e) { LOGGER.warn("Attempt to use a malformed signature '{}' for source '{}'", signature, source, e); return false; } } @Inject @VisibleForTesting  JamesSignatureHandler(SecurityKeyLoader keyLoader); @Override void init(); @Override String sign(String source); @Override boolean verify(String source, String signature); static final String ALGORITHM; }