How to resolve the “Given final block not properly padded. Such issues can arise if a bad key is used during decryption” error

Daniel Poterman
2021-05-31 10:08

In some cases you may encounter the following error:[jfrt ] [ERROR] [4543429d2a8d1892] [ctoryContextConfigListener:126] [art-init            ] - Application could not be initialized: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
java.lang.reflect.InvocationTargetException: null

This error suggests that there is an issue with either the join.key or the master.key

In order to resolve this error you should follow this procedure:
1. Stop all Artifactory nodes
2. Change DB password to plain text in system.yaml which is placed under the path $JFROG_HOME/artifactory/var/etc (e.g.: /opt/jfrog/artifactory/var/etc)
3. Take a backup of the database schema using db dump for recovery purposes if needed.
4. Run the following PostgreSQL delete queries, which will delete all records related to the master key entries. By executing the below commands we are making sure there will be no entries for the master key in the database.  delete from access_configs where data LIKE 'JE%';
delete from access_users_custom_data where PROP_VALUE LIKE 'JE%';
delete from access_master_key_status where status = 'on';
delete from master_key_status where status = 'on';
delete from CONFIGS where data LIKE 'JE%';
5. Delete master.key and join.key from $JFROG_HOME/artifactory/var/etc/security folder from all nodes.
6. Delete access.admin.token file from $JFROG_HOME/artifactory/var/etc/artifactory/security/access folder from all nodes.
7. Go over the artifactory.config.latest.xml file which is located under $JFROG_HOME/artifactory/var/etc/artifactory folder and search all passwords containing either “JE” or “AM” strings within the file and replace them with clear text passwords. If you don't remember them, you can leave the <password> section empty.
8. Save the file and rename it to artifactory.config.import.xml.
9. Start Artifactory primary node. The master.key should be automatically generated at the startup/boot time and the artifactory.config.import.xml file will be renamed as artifactory.config.bootstrap.xml.
10. Copy the master.key from the primary node to the other nodes and start the Artifactory services.

Note: if you are using Artifactory single node, step #10 is not relevant.