Skip to content

fix: [disk-encrypt] Can not decrypt disk by TPM. #2849

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

Merged

Conversation

GongHeng2017
Copy link
Contributor

@GongHeng2017 GongHeng2017 commented May 16, 2025

-- The libutpm2 not install, so add the depands.
-- Set the pcr to 0,7.
-- Optimizing the algo of obtaining for tpm.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-316269.html

Summary by Sourcery

Enable TPM-based disk decryption by properly managing PCR settings and algorithm parameters, with optional sourcing from DConfig to fix decryption failures.

New Features:

  • Support configurable PCR indices and bank values in TPM operations.
  • Allow algorithm parameters to be loaded from Deepin’s DConfig for dynamic TPM configuration.
  • Add helper functions to detect available TPM algorithms for both standard and SM suites.

Bug Fixes:

  • Fix disk decryption failure by correcting PCR/index handling and ensuring proper algorithm selection.

Enhancements:

  • Refactor getAlgorithm to include PCR parameters and drop ini-based persistence, centralizing parameters in token.json.
  • Simplify TPM passphrase generation and decryption logic by consolidating property maps.

Copy link

  • 检测到debian目录文件有变更: debian/control

@github-actions github-actions bot requested a review from liujianqiang-niu May 16, 2025 08:45
Copy link

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "debian/control": [
        {
            "line": "Homepage: http://www.deepin.org",
            "line_number": 52,
            "rule": "S35",
            "reason": "Url link | 6fe814dfb7"
        }
    ]
}

Copy link

sourcery-ai bot commented May 16, 2025

Reviewer's Guide

This PR refactors TPM-based disk encryption to support dynamic PCR parameters and configurable algorithms, replacing hard-coded defaults and ini-based persistence with JSON-based tokens and DConfig overrides.

File-Level Changes

Change Details Files
Expanded algorithm selection logic to include PCR parameters and config-based overrides
  • Extended getAlgorithm signature to output PCR and PCR bank
  • Added tpmSupportInterAlgo and tpmSupportSMAlgo helpers
  • Introduced config_utils::enableAlgoFromDConfig and tpmAlgoFromDConfig to load algos from DConfig
encryptutils.cpp
encryptutils.h
config_utils implementations
dfmplugin_disk_encrypt_global.h
Replaced ini-file persistence with JSON token parsing
  • Removed QSettings-based algo.ini reads and writes
  • Now parse all algos and PCR values from token.json before decryption
encryptutils.cpp
Integrated PCR and PCR bank into TPM operations
  • Removed hard-coded PCR="7" and bank values
  • Mapped dynamic pcr and pcrBank into passphrase gen/decrypt property maps
  • Updated JSON generation in disk encrypt menu for PCR fields
encryptutils.cpp
diskencryptmenuscene.cpp
Updated global constants and header definitions
  • Added kPcr, kTPMPcrBank, kTCMPcrBank constants
  • Added new config key constants for minor algos and PCR fields
  • Fixed typo in TPM enum constant name
dfmplugin_disk_encrypt_global.h
encryptutils.h
Cleaned up redundant GUI code and unneeded dependencies
  • Removed pre-check of getAlgorithm in GUI dialog
  • Added libutpm2 as package dependency (debian/control and assets configs)
encryptparamsinputdialog.cpp
debian/control

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @GongHeng2017 - I've reviewed your changes - here's some feedback:

  • The new config_utils functions mix deleteLater() and manual delete for DConfig – please standardize on a single ownership model or smart pointer to avoid inconsistent object lifetimes.
  • There’s a lot of repeated tpm_utils::isSupportAlgoByTPM calls in tpmSupportInterAlgo/tpmSupportSMAlgo – consider abstracting that pattern to reduce duplication and simplify future maintenance.
  • In getPassphraseFromTPM, when JSON fields are missing, it would be helpful to log exactly which keys are absent to aid debugging rather than a single generic message.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

-- The libutpm2 not install, so add the depands.
-- Set the pcr to 0,7.
-- Optimizing the algo of obtaining for tpm.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-316269.html
@GongHeng2017 GongHeng2017 force-pushed the 202505160926-master-fixDiskEncrypt branch from 7a42370 to 8fe2c0e Compare May 16, 2025 09:44
Copy link

  • 检测到debian目录文件有变更: debian/control

Copy link

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "debian/control": [
        {
            "line": "Homepage: http://www.deepin.org",
            "line_number": 52,
            "rule": "S35",
            "reason": "Url link | 6fe814dfb7"
        }
    ]
}

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, Johnson-zs, liujianqiang-niu

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@GongHeng2017
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented May 20, 2025

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit 2694eb8 into linuxdeepin:master May 20, 2025
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants