Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recreate masterkey for hsm #128

Merged
merged 1 commit into from May 30, 2019
Merged

Conversation

sharidas
Copy link
Contributor

Fix recreate masterkey for hsm

Signed-off-by: Sujith H sharidasan@owncloud.com

@sharidas sharidas added this to the development milestone May 27, 2019
@sharidas sharidas self-assigned this May 27, 2019
@sharidas
Copy link
Contributor Author

Description

When masterkey is enabled with hsm, the recreate mastekey command was failing. The reason for this was Crypt was pointing to wrong class. Meaning instead of CryptHSM, it was pointing to Crypt. This caused the keys to be generated in the oC instance and hence things were not working. Once the app is re-enabled, the keymanager requires to be pointed to CryptHSM if hsm is enabled. The switch to the Crypt is decided here https://github.com/owncloud/encryption/blob/master/lib/AppInfo/Application.php#L136-L149. This pr tries to address this issue.

Issue

#125

Test done

  • Enable encryption with hsm
  • Login as admin user
  • Verify the OC_DEFAULT_MODULE as shown below:
 sujith@sujith-ownCloud  ~/test/owncloud3   master ●  ls -lt data/files_encryption/OC_DEFAULT_MODULE
total 16
-rw-r--r-- 1 sujith sujith 189 May 27 12:35 master_4d9273b1.privateKey
-rw-r--r-- 1 sujith sujith 451 May 27 12:35 master_4d9273b1.publicKey
-rw-rw-r-- 1 sujith sujith 189 May 27 12:35 pubShare_4d9273b1.privateKey
-rw-rw-r-- 1 sujith sujith 451 May 27 12:35 pubShare_4d9273b1.publicKey
 sujith@sujith-ownCloud  ~/test/owncloud3   master ● 
  • Execute the recreate master key command:
✘ sujith@sujith-ownCloud  ~/test/owncloud3   master ●  ./occ encryption:recreate-master-key -y
Cannot load Xdebug - it was already loaded
Decryption started

    1 [->--------------------------]prepare encryption modules...
 done.


 decrypt files for user admin (1 of 1): /admin/files/welcome.txt 
 [-->-------------------------]

 starting to decrypt files... finished 
 [============================]


all files could be decrypted successfully!
    1 [============================]
Decryption completed

Encryption started

Waiting for creating new masterkey

New masterkey created successfully



Encrypt all files with the Default encryption module
====================================================


Use master key to encrypt all files.


Start to encrypt users files
----------------------------



 all files encrypted 
 [============================]


Encryption completed successfully


Note: All users are required to relogin.

 sujith@sujith-ownCloud  ~/test/owncloud3   master ● 
  • Verify the keys have been updated
sujith@sujith-ownCloud  ~/test/owncloud3   master ●  ls -lt data/files_encryption/OC_DEFAULT_MODULE
total 16
-rw-rw-r-- 1 sujith sujith 189 May 27 12:36 master_51aea79b.privateKey
-rw-rw-r-- 1 sujith sujith 451 May 27 12:36 master_51aea79b.publicKey
-rw-rw-r-- 1 sujith sujith 189 May 27 12:36 pubShare_51aea79b.privateKey
-rw-rw-r-- 1 sujith sujith 451 May 27 12:36 pubShare_51aea79b.publicKey
 sujith@sujith-ownCloud  ~/test/owncloud3   master ● 
  • Verified that files are accessible
  • Re-run the recreate masterkey command
 sujith@sujith-ownCloud  ~/test/owncloud3   master ●  ./occ encryption:recreate-master-key -y
Cannot load Xdebug - it was already loaded
Decryption started

    1 [->--------------------------]prepare encryption modules...
 done.


 decrypt files for user admin (1 of 1): /admin/files/welcome.txt 
 [-->-------------------------]

 starting to decrypt files... finished 
 [============================]


all files could be decrypted successfully!
    1 [============================]
Decryption completed

Encryption started

Waiting for creating new masterkey

New masterkey created successfully



Encrypt all files with the Default encryption module
====================================================


Use master key to encrypt all files.


Start to encrypt users files
----------------------------



 all files encrypted 
 [============================]


Encryption completed successfully


Note: All users are required to relogin.

 sujith@sujith-ownCloud  ~/test/owncloud3   master ● 
  • Verified the file welcome.txt was accesible
  • Verified the new keys have been generated:
 sujith@sujith-ownCloud  ~/test/owncloud3   master ●  ls -lt data/files_encryption/OC_DEFAULT_MODULE
total 16
-rw-rw-r-- 1 sujith sujith 189 May 27 12:36 master_293b1f5e.privateKey
-rw-rw-r-- 1 sujith sujith 451 May 27 12:36 master_293b1f5e.publicKey
-rw-rw-r-- 1 sujith sujith 189 May 27 12:36 pubShare_293b1f5e.privateKey
-rw-rw-r-- 1 sujith sujith 451 May 27 12:36 pubShare_293b1f5e.publicKey
 sujith@sujith-ownCloud  ~/test/owncloud3   master ● 

@jvillafanez
Copy link
Member

There are several things to fix in the class, indirectly related with the work in this PR. I don't know if we can fix them in the PR or not.

  • The commands depends on 16 components. This is bad, specially when only 6-8 are directly used by this class. The rest of the components are being passed through. This has several related consequences:
    • The command creates several components by itself. Those components won't be mocked, so unit tests are impossible to do. The tests currently made are more in the direction of integration tests.
    • The more components the command relies on, the more probable is that a bug happens. In addition, even if the command itself is simple (in the sense of "I just call this method is we're done"), having more components raises the complexity unnecessarily
  • The command overwrites one of the injected components. While the command can be easy to follow, in general we can expect to use the same dependency across the class. It's quite easy to have surprises when you're injecting an object but then you're using a different object.

I'd need to dig into the code to come up with refactor plan, and I'm not sure how much time it could take. For now, I'd recommend to check the possiblity of using at least one factory class to take care of whatever the command needs to create

@sharidas sharidas force-pushed the fix-recreate-masterkey-hsm branch 2 times, most recently from c53bdec to 3f0254d Compare May 29, 2019 06:48
lib/Command/RecreateMasterKey.php Outdated Show resolved Hide resolved
lib/Command/RecreateMasterKey.php Show resolved Hide resolved
lib/Crypto/EncryptAll.php Outdated Show resolved Hide resolved
lib/Crypto/EncryptAll.php Outdated Show resolved Hide resolved
lib/Factory/EncDecAllFactory.php Outdated Show resolved Hide resolved
@sharidas sharidas force-pushed the fix-recreate-masterkey-hsm branch from 3f0254d to 84db7bc Compare May 29, 2019 08:22
@codecov
Copy link

codecov bot commented May 29, 2019

Codecov Report

Merging #128 into master will increase coverage by 0.87%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #128      +/-   ##
============================================
+ Coverage     69.79%   70.67%   +0.87%     
- Complexity      620      627       +7     
============================================
  Files            34       35       +1     
  Lines          2291     2312      +21     
============================================
+ Hits           1599     1634      +35     
+ Misses          692      678      -14
Impacted Files Coverage Δ Complexity Δ
lib/Util.php 81.03% <100%> (+2.6%) 17 <1> (+1) ⬆️
lib/Command/RecreateMasterKey.php 98.24% <100%> (+12.16%) 9 <1> (-1) ⬇️
lib/Crypto/EncryptAll.php 52.77% <100%> (+1.11%) 48 <2> (+2) ⬆️
lib/Factory/EncDecAllFactory.php 100% <100%> (ø) 5 <5> (?)
lib/KeyManager.php 78.77% <0%> (+1.63%) 83% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e68099...b41566c. Read the comment docs.

@codecov
Copy link

codecov bot commented May 29, 2019

Codecov Report

Merging #128 into master will increase coverage by 0.47%.
The diff coverage is 83.92%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #128      +/-   ##
============================================
+ Coverage     69.79%   70.27%   +0.47%     
- Complexity      620      627       +7     
============================================
  Files            34       35       +1     
  Lines          2291     2311      +20     
============================================
+ Hits           1599     1624      +25     
+ Misses          692      687       -5
Impacted Files Coverage Δ Complexity Δ
lib/Crypto/EncryptAll.php 49.77% <0%> (-1.89%) 48 <2> (+2)
lib/Util.php 81.03% <100%> (+2.6%) 17 <1> (+1) ⬆️
lib/Factory/EncDecAllFactory.php 100% <100%> (ø) 5 <5> (?)
lib/Command/RecreateMasterKey.php 96.29% <90.9%> (+10.22%) 9 <1> (-1) ⬇️
lib/KeyManager.php 78.77% <0%> (+1.63%) 83% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f18bdc...84db7bc. Read the comment docs.

@sharidas sharidas force-pushed the fix-recreate-masterkey-hsm branch from 84db7bc to 5f6a8ab Compare May 29, 2019 08:50
lib/Command/RecreateMasterKey.php Outdated Show resolved Hide resolved
lib/Crypto/EncryptAll.php Outdated Show resolved Hide resolved
lib/Factory/EncDecAllFactory.php Show resolved Hide resolved
tests/unit/Command/RecreateMasterKeyTest.php Outdated Show resolved Hide resolved
@sharidas sharidas force-pushed the fix-recreate-masterkey-hsm branch 2 times, most recently from ec1c9c0 to 2bde139 Compare May 29, 2019 11:38
lib/Command/RecreateMasterKey.php Outdated Show resolved Hide resolved
tests/unit/Command/RecreateMasterKeyTest.php Outdated Show resolved Hide resolved
@sharidas sharidas force-pushed the fix-recreate-masterkey-hsm branch 5 times, most recently from 10162f3 to 9ba6bab Compare May 29, 2019 15:28
Fix recreate masterkey for hsm

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@sharidas sharidas force-pushed the fix-recreate-masterkey-hsm branch from 9ba6bab to b41566c Compare May 29, 2019 15:31
@sharidas sharidas merged commit 454e80b into master May 30, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix-recreate-masterkey-hsm branch May 30, 2019 08:35
@sharidas
Copy link
Contributor Author

Backport PR owncloud/core#35380

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants