@Test public void updateOutlookFolderCreatorPasswords() throws Exception { AcmOutlookFolderCreator first = buildOutlookFolderCreator(500L, "jgarcia@dead.net", "MD5"); String firstMd5Password = first.getSystemPassword(); AcmOutlookFolderCreator second = buildOutlookFolderCreator(600L, "bweir@dead.net", "SHA256"); List<AcmOutlookFolderCreator> found = Arrays.asList(first); expect(mockEntityManager.createQuery("SELECT e FROM AcmOutlookFolderCreator e", AcmOutlookFolderCreator.class)) .andReturn(mockQuery); expect(mockQuery.getResultList()).andReturn(found); expect(mockEntityManager.merge(first)).andReturn(first); replayAll(); unit.updateOutlookFolderCreatorPasswords(); verifyAll(); String firstSha256Password = first.getSystemPassword(); assertNotEquals(firstMd5Password, firstSha256Password); byte[] decryptedNewPassword = cryptoUtils.decryptData( encryptionProperties.getSymmetricKey(), Base64.getDecoder().decode(firstSha256Password), encryptionProperties.getPropertiesEncryptionKeySize(), encryptionProperties.getPropertiesEncryptionIVSize(), encryptionProperties.getPropertiesEncryptionMagicSize(), encryptionProperties.getPropertiesEncryptionSaltSize(), encryptionProperties.getPropertiesEncryptionPassPhraseIterations(), encryptionProperties.getPropertiesEncryptionPassPhraseHashAlgorithm(), encryptionProperties.getPropertiesEncryptionAlgorithm(), encryptionProperties.getPropertiesEncryptionBlockCipherMode(), encryptionProperties.getPropertiesEncryptionPadding()); String decrypted = new String(decryptedNewPassword); assertEquals("test-password", decrypted); }
public void updateOutlookFolderCreatorPasswords() { List<AcmOutlookFolderCreator> folderCreators = getEntityManager() .createQuery("SELECT e FROM AcmOutlookFolderCreator e", AcmOutlookFolderCreator.class).getResultList(); log.info("{} folder creators to check", folderCreators.size()); for (AcmOutlookFolderCreator folderCreator : folderCreators) { log.debug("checking folder creator {}", folderCreator.getSystemEmailAddress()); try { byte[] decrypted = getCryptoUtils().decryptData( getCryptoProperties().getSymmetricKey(), Base64.getDecoder().decode(folderCreator.getSystemPassword()), getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), "MD5", getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); log.debug("{} password is MD5-hashed, proceeding with update", folderCreator.getSystemEmailAddress()); byte[] encrypted = getCryptoUtils().encryptData( getCryptoProperties().getSymmetricKey(), decrypted, getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), getCryptoProperties().getPropertiesEncryptionPassPhraseHashAlgorithm(), getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); String encryptedBase64 = Base64.getEncoder().encodeToString(encrypted); folderCreator.setSystemPassword(encryptedBase64); getEntityManager().merge(folderCreator); } catch (AcmEncryptionException ace) { log.debug("{} password is not MD5-hashed, no need to update it", folderCreator.getSystemEmailAddress()); } } log.info("Done checking {} folder creators", folderCreators.size()); }
OutlookFolderCreatorPasswordMd5ToSha256UpdateExecutor implements AcmDataUpdateExecutor { public void updateOutlookFolderCreatorPasswords() { List<AcmOutlookFolderCreator> folderCreators = getEntityManager() .createQuery("SELECT e FROM AcmOutlookFolderCreator e", AcmOutlookFolderCreator.class).getResultList(); log.info("{} folder creators to check", folderCreators.size()); for (AcmOutlookFolderCreator folderCreator : folderCreators) { log.debug("checking folder creator {}", folderCreator.getSystemEmailAddress()); try { byte[] decrypted = getCryptoUtils().decryptData( getCryptoProperties().getSymmetricKey(), Base64.getDecoder().decode(folderCreator.getSystemPassword()), getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), "MD5", getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); log.debug("{} password is MD5-hashed, proceeding with update", folderCreator.getSystemEmailAddress()); byte[] encrypted = getCryptoUtils().encryptData( getCryptoProperties().getSymmetricKey(), decrypted, getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), getCryptoProperties().getPropertiesEncryptionPassPhraseHashAlgorithm(), getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); String encryptedBase64 = Base64.getEncoder().encodeToString(encrypted); folderCreator.setSystemPassword(encryptedBase64); getEntityManager().merge(folderCreator); } catch (AcmEncryptionException ace) { log.debug("{} password is not MD5-hashed, no need to update it", folderCreator.getSystemEmailAddress()); } } log.info("Done checking {} folder creators", folderCreators.size()); } }
OutlookFolderCreatorPasswordMd5ToSha256UpdateExecutor implements AcmDataUpdateExecutor { public void updateOutlookFolderCreatorPasswords() { List<AcmOutlookFolderCreator> folderCreators = getEntityManager() .createQuery("SELECT e FROM AcmOutlookFolderCreator e", AcmOutlookFolderCreator.class).getResultList(); log.info("{} folder creators to check", folderCreators.size()); for (AcmOutlookFolderCreator folderCreator : folderCreators) { log.debug("checking folder creator {}", folderCreator.getSystemEmailAddress()); try { byte[] decrypted = getCryptoUtils().decryptData( getCryptoProperties().getSymmetricKey(), Base64.getDecoder().decode(folderCreator.getSystemPassword()), getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), "MD5", getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); log.debug("{} password is MD5-hashed, proceeding with update", folderCreator.getSystemEmailAddress()); byte[] encrypted = getCryptoUtils().encryptData( getCryptoProperties().getSymmetricKey(), decrypted, getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), getCryptoProperties().getPropertiesEncryptionPassPhraseHashAlgorithm(), getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); String encryptedBase64 = Base64.getEncoder().encodeToString(encrypted); folderCreator.setSystemPassword(encryptedBase64); getEntityManager().merge(folderCreator); } catch (AcmEncryptionException ace) { log.debug("{} password is not MD5-hashed, no need to update it", folderCreator.getSystemEmailAddress()); } } log.info("Done checking {} folder creators", folderCreators.size()); }  }
OutlookFolderCreatorPasswordMd5ToSha256UpdateExecutor implements AcmDataUpdateExecutor { public void updateOutlookFolderCreatorPasswords() { List<AcmOutlookFolderCreator> folderCreators = getEntityManager() .createQuery("SELECT e FROM AcmOutlookFolderCreator e", AcmOutlookFolderCreator.class).getResultList(); log.info("{} folder creators to check", folderCreators.size()); for (AcmOutlookFolderCreator folderCreator : folderCreators) { log.debug("checking folder creator {}", folderCreator.getSystemEmailAddress()); try { byte[] decrypted = getCryptoUtils().decryptData( getCryptoProperties().getSymmetricKey(), Base64.getDecoder().decode(folderCreator.getSystemPassword()), getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), "MD5", getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); log.debug("{} password is MD5-hashed, proceeding with update", folderCreator.getSystemEmailAddress()); byte[] encrypted = getCryptoUtils().encryptData( getCryptoProperties().getSymmetricKey(), decrypted, getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), getCryptoProperties().getPropertiesEncryptionPassPhraseHashAlgorithm(), getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); String encryptedBase64 = Base64.getEncoder().encodeToString(encrypted); folderCreator.setSystemPassword(encryptedBase64); getEntityManager().merge(folderCreator); } catch (AcmEncryptionException ace) { log.debug("{} password is not MD5-hashed, no need to update it", folderCreator.getSystemEmailAddress()); } } log.info("Done checking {} folder creators", folderCreators.size()); }  @Override String getUpdateId(); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void execute(); void updateOutlookFolderCreatorPasswords(); AcmCryptoUtils getCryptoUtils(); void setCryptoUtils(AcmCryptoUtils cryptoUtils); AcmEncryptablePropertyEncryptionProperties getCryptoProperties(); void setCryptoProperties(AcmEncryptablePropertyEncryptionProperties cryptoProperties); EntityManager getEntityManager(); void setEntityManager(EntityManager entityManager); }
OutlookFolderCreatorPasswordMd5ToSha256UpdateExecutor implements AcmDataUpdateExecutor { public void updateOutlookFolderCreatorPasswords() { List<AcmOutlookFolderCreator> folderCreators = getEntityManager() .createQuery("SELECT e FROM AcmOutlookFolderCreator e", AcmOutlookFolderCreator.class).getResultList(); log.info("{} folder creators to check", folderCreators.size()); for (AcmOutlookFolderCreator folderCreator : folderCreators) { log.debug("checking folder creator {}", folderCreator.getSystemEmailAddress()); try { byte[] decrypted = getCryptoUtils().decryptData( getCryptoProperties().getSymmetricKey(), Base64.getDecoder().decode(folderCreator.getSystemPassword()), getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), "MD5", getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); log.debug("{} password is MD5-hashed, proceeding with update", folderCreator.getSystemEmailAddress()); byte[] encrypted = getCryptoUtils().encryptData( getCryptoProperties().getSymmetricKey(), decrypted, getCryptoProperties().getPropertiesEncryptionKeySize(), getCryptoProperties().getPropertiesEncryptionIVSize(), getCryptoProperties().getPropertiesEncryptionMagicSize(), getCryptoProperties().getPropertiesEncryptionSaltSize(), getCryptoProperties().getPropertiesEncryptionPassPhraseIterations(), getCryptoProperties().getPropertiesEncryptionPassPhraseHashAlgorithm(), getCryptoProperties().getPropertiesEncryptionAlgorithm(), getCryptoProperties().getPropertiesEncryptionBlockCipherMode(), getCryptoProperties().getPropertiesEncryptionPadding()); String encryptedBase64 = Base64.getEncoder().encodeToString(encrypted); folderCreator.setSystemPassword(encryptedBase64); getEntityManager().merge(folderCreator); } catch (AcmEncryptionException ace) { log.debug("{} password is not MD5-hashed, no need to update it", folderCreator.getSystemEmailAddress()); } } log.info("Done checking {} folder creators", folderCreators.size()); }  @Override String getUpdateId(); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void execute(); void updateOutlookFolderCreatorPasswords(); AcmCryptoUtils getCryptoUtils(); void setCryptoUtils(AcmCryptoUtils cryptoUtils); AcmEncryptablePropertyEncryptionProperties getCryptoProperties(); void setCryptoProperties(AcmEncryptablePropertyEncryptionProperties cryptoProperties); EntityManager getEntityManager(); void setEntityManager(EntityManager entityManager);  }