@Override
protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
logger.debug("Starting to encrypt and put the user profile for user '{}'.", credentials.getUserId());
// consume the profile from the context
UserProfile userProfile = context.consumeUserProfile();
// encrypt user profile
SecretKey encryptionKey = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(),
credentials.getPin(), H2HConstants.KEYLENGTH_USER_PROFILE);
EncryptedNetworkContent encryptedProfile = null;
try {
encryptedProfile = H2HEncryptionUtil.encryptAES(userProfile, encryptionKey);
} catch (DataLengthException | IllegalStateException | InvalidCipherTextException | IOException e) {
throw new ProcessExecutionException("User profile could not be encrypted.");
}
try {
encryptedProfile.generateVersionKey();
} catch (IOException e) {
throw new ProcessExecutionException("User profile version key could not be generated.", e);
}
// assign ttl value
encryptedProfile.setTimeToLive(userProfile.getTimeToLive());
// put encrypted user profile
try {
put(credentials.getProfileLocationKey(), H2HConstants.USER_PROFILE, encryptedProfile,
userProfile.getProtectionKeys());
logger.debug("User profile successfully put for user {}.", credentials.getUserId());
} catch (PutFailedException e) {
throw new ProcessExecutionException(e);
}
}