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

[Bug]: Multikey Encryption Breaks When Upgrading from NC26 to NC27 #45182

Open
5 of 8 tasks
derschiw opened this issue May 4, 2024 · 8 comments
Open
5 of 8 tasks

[Bug]: Multikey Encryption Breaks When Upgrading from NC26 to NC27 #45182

derschiw opened this issue May 4, 2024 · 8 comments
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 27-feedback bug feature: encryption (server-side) high

Comments

@derschiw
Copy link
Contributor

derschiw commented May 4, 2024

⚠️ This issue respects the following points: ⚠️

Bug description

Hi there

We are running a multikey encrypted NC instance with some hundreds of users. Recently we upgraded from NC26 to NC27. From then on multiple users reported, that they coud not open files anymore (console logging "Cannot decrypt this file, probably this is a shared file"). After doing quiet some research, we were able to track down the problem to this cause:

In the following issue openssl_seal and rc4 were removed (https://github.com/nextcloud/server/pull/37243/files). In this PR the so called fileKey used for RC4 was removed after re-encrypting a file (

$this->keyManager->deleteAllFileKeys($path);
). Additionally a legacy format was introduced to still beeing able to open old files. However we found out that under certain contidions (resharing or move operations), the fileKey gets deleted without re-encrypting the data, which leads to data loss.

In particular, we could observe that the files_encryption/key/files/[PATH]/OC_DEFAULT_MODULE directory of affected files did contain new [USERNAME].shareKey files and nofileKey anymore. We were then able to replace the content of this directory with the old share keys and the fileKey (that we restored from a backup). By doing this, we could open the file again (in the webbrowser), which leads to the conclusion that the file must have lost its keys without beeing reencrypted.

We were though not able to precisely find the precise code that causes the missing reencryption. We believe that the end or update method in apps/encryption/lib/Crypto/Encryption.php get called without re-encrypting the file.

Help is very much appreciated, as this currently breaks all of our users data and we can't do something against that problem besides informing our customers. Thanks you very much for your support!

Steps to reproduce

Install NC26 with User Key Encryption

  1. Install NC 26
  2. Enable the default encryption module
  3. occ encryption:list-modules to check that the app is enabled
  4. occ encryption:disable-master-key and accept the warning
  5. occ encryption:enable
  6. occ encryption:encrypt-all
  7. Log out and log in again.
  8. Go to personal settings -> security -> update password in security tab with the password from the CLI.

Create a Folder and Share

  1. Create a second user
  2. Create a directory, share the directory.
  3. Put some files into the directory (not .md - preferrably .jpg, .pdf or .zip). Now in the files_encryption directory are two [USERNAME].shareKey and a fileKey.

Update

  1. Update to NC27
  2. Create a new directory (for example foo).
  3. Move the directory into another directory (click on the three dots -> move or copy -> move to foo).
  4. Open the file. It will fail with a warning in the console ("Cannot decrypt...").

Expected behavior

The files should be re-encrypted before removing the fileKeys.

Installation method

None

Nextcloud Server version

27

Operating system

Debian/Ubuntu

PHP engine version

None

Web server

Nginx

Database engine version

PostgreSQL

Is this bug present after an update or on a fresh install?

Upgraded to a MAJOR version (26 to 27)

Are you using the Nextcloud Server Encryption module?

Encryption is Enabled

What user-backends are you using?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

{
    "system": {
        "memcache.local": "\\OC\\Memcache\\APCu",
        "apps_paths": [
            {
                "path": "\/var\/www\/html\/apps",
                "url": "\/apps",
                "writable": false
            },
            {
                "path": "\/var\/www\/html\/custom_apps",
                "url": "\/custom_apps",
                "writable": true
            }
        ],
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 6379
        },
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "cloud.wolke7.wtf"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "pgsql",
        "version": "27.1.9.1",
        "overwrite.cli.url": "https:\/\/cloud.wolke7.wtf",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "enabledPreviewProviders": [
            "OC\\Preview\\PNG",
            "OC\\Preview\\JPEG",
            "OC\\Preview\\GIF",
            "OC\\Preview\\HEIC",
            "OC\\Preview\\BMP",
            "OC\\Preview\\XBitmap",
            "OC\\Preview\\MP3"
        ],
        "preview_max_scale_factor": 2,
        "preview_max_x": 128,
        "preview_max_y": 128,
        "lost_password_link": "disabled",
        "allow_user_to_change_display_name": false,
        "skeletondirectory": "\/srv\/nextcloud-assets\/skeleton",
        "mail_smtpmode": "smtp",
        "mail_smtpauthtype": "LOGIN",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "mail_smtpsecure": "ssl",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauth": 1,
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "activity_expire_days": 60,
        "log_type": "file",
        "loglevel": 3,
        "logfile": "\/dev\/stdout",
        "maintenance": false,
        "theme": "",
        "app_install_overwrite": [
            "end_to_end_encryption"
        ],
        "simpleSignUpLink.shown": false,
        "mail_sendmailmode": "smtp",
        "encryption.legacy_format_support": true,
        "encryption.key_storage_migrated": false,
        "default_locale": "de_CH",
        "default_phone_region": "CH",
        "updater.server.url": "https:\/\/updates.nextcloud.com\/customers\/[KEY]",
        "auth.webauthn.enabled": false
    }
}

List of activated Apps

Enabled:
  - activity: 2.19.0
  - bruteforcesettings: 2.7.0
  - calendar: 4.7.1
  - cloud_federation_api: 1.10.0
  - contacts: 5.5.3
  - dav: 1.27.0
  - encryption: 2.15.0
  - external: 5.2.1
  - federatedfilesharing: 1.17.0
  - federation: 1.17.0
  - files: 1.22.0
  - files_pdfviewer: 2.8.0
  - files_reminders: 1.0.0
  - files_rightclick: 1.6.0
  - files_sharing: 1.19.0
  - files_trashbin: 1.17.0
  - files_versions: 1.20.0
  - firstrunwizard: 2.16.0
  - logreader: 2.12.0
  - lookup_server_connector: 1.15.0
  - nextcloud_announcements: 1.16.0
  - notes: 4.10.0
  - notifications: 2.15.0
  - oauth2: 1.15.2
  - password_policy: 1.17.0
  - photos: 2.3.0
  - privacy: 1.11.0
  - provisioning_api: 1.17.0
  - recommendations: 1.6.0
  - related_resources: 1.2.0
  - serverinfo: 1.17.0
  - settings: 1.9.0
  - sharebymail: 1.17.0
  - support: 1.10.1
  - text: 3.8.0
  - theming: 2.2.0
  - twofactor_backupcodes: 1.16.0
  - twofactor_totp: 9.0.0
  - twofactor_webauthn: 1.4.0
  - updatenotification: 1.17.0
  - viewer: 2.1.0
  - workflowengine: 2.9.0
Disabled:
  - admin_audit: 1.17.0
  - circles: 27.0.1 (installed 22.1.1)
  - comments: 1.17.0 (installed 1.10.0)
  - contactsinteraction: 1.8.0 (installed 1.3.0)
  - dashboard: 7.7.0 (installed 7.0.0)
  - end_to_end_encryption: 1.13.1 (installed 1.13.1)
  - files_external: 1.19.0
  - survey_client: 1.15.0 (installed 1.4.0)
  - suspicious_login: 5.0.0
  - systemtags: 1.17.0 (installed 1.10.0)
  - user_ldap: 1.17.0
  - user_status: 1.7.0 (installed 1.0.1)
  - weather_status: 1.7.0 (installed 1.0.0)

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

No response

Additional info

No response

@derschiw derschiw added 0. Needs triage Pending check for reproducibility or if it fits our roadmap bug labels May 4, 2024
@kesselb
Copy link
Contributor

kesselb commented May 4, 2024

fyi @AndyScherzinger @sorbaugh @come-nc

@kesselb
Copy link
Contributor

kesselb commented May 4, 2024

I cannot tell if related but noticed that end_to_end_encryption is listed in app_install_overwrite.

E2E and SSE are not compatible and cannot be used at the same time afaik, because they both use the encrypted column in oc_filecache.

@derschiw
Copy link
Contributor Author

derschiw commented May 4, 2024

@kesselb when starting the cloud we tried E2EE but then disabled the app (years ago) without having any problems so far. So i guess this is not related.

@AndyScherzinger
Copy link
Member

Also Looping in @artonge

@artonge
Copy link
Contributor

artonge commented May 6, 2024

I failed to reproduce.
@derschiw I tried to move a file out of the shared folder, both from the emitter and the recipient.
When doing it from the recipient account, the fileKey is deleted, but the file can still be opened. Anything I am missing?

@derschiw
Copy link
Contributor Author

derschiw commented May 8, 2024

Sorry for the late response.
Did you try it with an markdown / image file? We believe that some files are either in the cache or unencrypted thumbnails. But the timestamps in the key files and encrypted files differ. Also you will see that the download will fail.

However we just reproduced it with .mp4 and .pdf files locally in a fresh install. It breaks as expected.

Sorry we didn't realize that before... I updated the Steps to reproduce.

@m-vz
Copy link

m-vz commented May 8, 2024

I was just able to reproduce the error on a fresh instance with the updated steps @derschiw posted.

Moved all default files into a folder on NC26 and shared that. Upgrade to NC27. After moving the folder without editing the files, none of them can be opened anymore.

This seems like a serious problem to me...

@1H0
Copy link

1H0 commented May 9, 2024

I was also able to reproduce this issue with the steps provided by @derschiw.

I also moved all the preexisting files in a folder on NC26 and shared it with a user. I then upgraded to NC27 and added another user to that same folder, which then made files in it inacessible to all participants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 27-feedback bug feature: encryption (server-side) high
Projects
Status: 📄 To do (~10 entries)
Development

No branches or pull requests

7 participants