Fatal error 'Unable to read cipher data for 0' when linking to BitBucket Server repo.
Asked by James:

Hi, when I attempt to link to a BitBucket Server repository with Bamboo 6.9.0 I get a fatal error 'Unable to read cipher data for 0'.

This is a brand-new install of Bamboo. It has been linked with our existing instance of BitBucket Server and the link has been configured on both instances. Each link shows a green 'connected' status.

Attempting to link a repository in the Admin console under Linked Repositories results in the same error:

![browser_error.PNG](/t5/image/serverpage/image-id/56516i4405C63062E44DAD/image-size/large?v=v2&px=999 "browser_error.PNG")

Bamboo version: 6.9.0 build 60909 running on CentOS 7.6.1810  
BitBucket Server: v5.6.2 running on CentOS 7.4.1708

Log file extract:

\`\`\`

2019-06-04 15:05:07,967 WARN \[http-nio-8085-exec-22\] \[CacheAwareness\] Inheriting disabledCaches:\[com.atlassian.bamboo.ANY\]  
2019-06-04 15:05:08,544 FATAL \[http-nio-8085-exec-22\] \[InstanceSecretStorage\] Cipher initialisation vector is unavailable  
2019-06-04 15:05:08,547 ERROR \[http-nio-8085-exec-22\] \[BambooActionSupport\] java.lang.IllegalArgumentException: Unable to read cipher data for 0  
java.lang.IllegalArgumentException: Unable to read cipher data for 0  
at com.atlassian.bamboo.crypto.instance.InstanceSecretStorage.readKeyAndIv(InstanceSecretStorage.java:59)  
at com.atlassian.bamboo.crypto.instance.InstanceSecretStorage.getOrCreateCipherData(InstanceSecretStorage.java:108)  
at com.atlassian.bamboo.crypto.instance.InstanceSecretStorage.getCipherData(InstanceSecretStorage.java:99)  
at com.atlassian.bamboo.crypto.instance.InstanceSecretStorage.getKeyAndIv(InstanceSecretStorage.java:84)  
at com.atlassian.bamboo.crypto.instance.InstanceCipherProvider.getKeyAndIv(InstanceCipherProvider.java:64)  
at com.atlassian.bamboo.crypto.instance.InstanceCipherProvider.getCipher(InstanceCipherProvider.java:50)  
at com.atlassian.bamboo.crypto.instance.InstanceCipherProvider.getEncryptor(InstanceCipherProvider.java:37)  
at com.atlassian.bamboo.crypto.instance.SecretEncryptionServiceInternalImpl.encrypt(SecretEncryptionServiceInternalImpl.java:130)  
at com.atlassian.bamboo.crypto.instance.SecretEncryptionServiceInternalImpl.encrypt(SecretEncryptionServiceInternalImpl.java:119)

\`\`\`

Troubleshooting:

1. I am able to create a plan without linking to a repository.  
2. I get the same error if I make myself administrator on both Bamboo and BitBucket.  
3. Removing and recreating the link between Bamboo and BitBucket does not solve the issue.  
4. Bamboo is running has the 'bamboo' user. This user has drwx access on the 'cipher' directory and rw access on the file cipher.key_0 inside that directory.  
5. I've looked at the questions linked but they don't fix my issue:  
\* <https://community.atlassian.com/t5/Jira-Service-Desk-questions/not-able-to-link-repository-to-bamboo-Unable-to-read-cipher-data/qaq-p/1048092>

6. I have \*not\* tried a reinstallation with a new home directory and database. If I'm unable to resolve here that's my next step.


Answers:
author: Haythem Benizid
body: hi,

I get the **same error** while linking to a repository

\[BambooActionSupport\] java.lang.IllegalArgumentException: Unable to read cipher data for 0

Bamboo version 6.9.1 build 60910 (Centos 7)

comments: author: It Manager
body: Hey, I lodged a support request with Atlassian about my issue and they helped me through resolving it.

The issue was an incomplete key generation, and the solution was to remove the partially-generated key from both the database and the filesystem to force regeneration.

These are the steps to resolve I was provided (paraphrased):

The database should have two rows, the *com.atlassian.restricted.instance.cipher.key_0* and *com.atlassian.restricted.instance.cipher.iv_0.*They can be selected with:

```
select * from BANDANA where BANDANA_KEY like '%cipher%';
```

To regenerate the cipher:

1. Shutdown Bamboo.
2. Remove the *com.atlassian.restricted.instance.cipher.key_0* and/or *com.atlassian.restricted.instance.cipher.iv_0* row from the database (found in the select query above).
3. Remove the cipher directory (under *\<bamboo-home\>/xml-data/configuration*)
4. Start Bamboo.
5. Before configuring anything else, create a Repository first. This will re-generate the cipher.

Hope this helps!


author: Al Lines
body: We have the same issue. Question is how did this occur? And can it happen again.

Next step - to look to follow this and regenerate the cipher....


author: Foong
body: Do not use the suggestion to delete and regenerate the cipher key. It is suggested depending on certain situation. Using this suggestion might cause an even severe problem without solution at the end.

Report the issue to Atlassian Support so that the logs can be analysed and a different solution might be suggested.


author: Al Lines
body: ... which we had and did. And spent 2 weeks troubleshooting with them. Watch out for a blog post soon on how to really do this - now Atlassian know from experience the possible variants!


Tags: bitbucket

bitbucket-server

server