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

More options for pervasive encryption #1398

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/lib/y2partitioner/actions/controllers/encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def secure_key
#
# @return [Array<Y2Storage::EncryptionProcesses::Apqn>]
def online_apqns
@online_apqns ||= Y2Storage::EncryptionProcesses::Apqn.online
@online_apqns ||= Y2Storage::EncryptionProcesses::Apqn.online.select(&:master_key_pattern)
end

# Finds an online APQN by its name
Expand Down Expand Up @@ -234,9 +234,29 @@ def initial_pbkdf
# Currently used APQNs when the device is encrypted with pervasive encryption
#
# @return [Array<Y2Storage::EncryptionProcesses::Apqn>]
def initial_apqns
def initial_pervasive_key
process = encryption&.encryption_process

master_key = process_pervasive_key(process) if process
return master_key if master_key

pervasive_keys.first
end

def process_pervasive_key(process)
return nil unless process.respond_to?(:apqns)

apqn = process.apqns.first
return nil unless apqn

apqn.master_key_pattern
end

# Currently used APQNs when the device is encrypted with pervasive encryption
#
# @return [Array<Y2Storage::EncryptionProcesses::Apqn>]
def initial_apqns
process = encryption&.encryption_process
return [] unless process.respond_to?(:apqns)

process.apqns
Expand Down
125 changes: 92 additions & 33 deletions src/lib/y2partitioner/widgets/apqn_selector.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2020] SUSE LLC
# Copyright (c) [2020-2024] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -17,68 +17,127 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast2/popup"
require "yast"
require "cwm"
require "y2partitioner/actions/controllers/encryption"
require "yast2/popup"
require "y2partitioner/widgets/encrypt_password"
require "y2partitioner/widgets/encrypt_label"
require "y2partitioner/widgets/pbkdf_selector"
require "y2partitioner/widgets/apqn_selector"

module Y2Partitioner
module Widgets
# Widget to select APQNs for generating a new secure key for pervasive encryption
class ApqnSelector < CWM::MultiSelectionBox
# Widget to select the APQNs for pervasive encryption
class ApqnSelector < CWM::ReplacePoint
# Internal widget used when there are several candidate APQNs for the given key
class ApqnMultiSelector < CWM::MultiSelectionBox
# Constructor
def initialize(id, all_apqns, selected_apqns)
super()
textdomain "storage"

self.widget_id = id
@apqns = all_apqns
@selected_apqns = selected_apqns
end

# @return [String]
def label
_("Available APQNs:")
end

# @return [Array<String, String>]
def items
@apqns.map { |a| [a, a] }
end

def init
self.value = @selected_apqns
end
end

# Constructor
#
# @param controller [Actions::Controllers::Encryption]
# @param enable [Boolean] whether the widget should be enabled on init
def initialize(controller, enable: true)
super()
def initialize(apqns_by_key, initial_key, initial_apqns, enable: true)
textdomain "storage"

@controller = controller
@apqns_by_key = apqns_by_key
@initial_key = initial_key
@initial_apqns = initial_apqns
@enable_on_init = enable
end

# @return [String]
def label
_("Available APQNs:")
super(id: "apqn_selector", widget: widgets_by_key[initial_key])
end

# @macro seeAbstractWidget
def init
super
enable_on_init ? enable : disable
self.value = controller.apqns
end

# @return [Array<String, String>]
def items
controller.online_apqns.map { |d| [d.name, d.name] }
# @macro seeAbstractWidget
#
# Note its internal widget needs to be enabled.
def enable
super

widgets_by_key.each_value { |w| w.enable if w.respond_to?(:enable) }
end

# All selected APQNs
# @macro seeAbstractWidget
#
# @return [Array<Y2Storage::EncryptionProcesses::Apqn>]
def value
super.map { |d| controller.find_apqn(d) }.compact
# Note its internal widget needs to be disabled.
def disable
super

all_widgets.each_value { |w| w.disable if w.respond_to?(:disable) }
end

# Sets selected APQNs
# Redraws the widget to show the options for given master key
#
# @param apqns [Array<Y2Storage::EncryptionProcesses::Apqn>]
def value=(apqns)
super(apqns.map(&:name))
# @param key [String]
def refresh(key)
replace(widgets_by_key[key])
end

# Saves the selected APQNs into the controller
def store
controller.apqns = value
# All selected APQNs, if there are several possible ones
#
# @return [Array<Y2Storage::EncryptionProcesses::Apqn>, nil] nil if there is only one possible APQN
def value
return unless @widget.respond_to?(:value)

@widget.value
end

private

# @return [Actions::Controllers::Encryption]
attr_reader :controller

# @return [Boolean]
attr_reader :enable_on_init

# @return [Hash] list of possible APQNs for each configured master key
attr_reader :apqns_by_key

# @return [Hash{String => CWM::AbstractWidget}]
def widgets_by_key
return @widgets_by_key if @widgets_by_key

@widgets_by_key = {}
apqns_by_key.each do |key, apqns|
selected = key == @initial_key ? @initial_apqns : apqns
@widgets_by_key[key] = widget_for(key, apqns, selected)
end

@widgets_by_key
end

# Returns either a selector or an empty widget (if there is only one possible APQN)
def widget_for(key, apqns, selected)
widget_id = "Details#{key}"
if apqns.size > 1
ApqnMultiSelector.new(widget_id, apqns.map(&:name), selected.map(&:name))
else
CWM::Empty.new(widget_id)
end
end
end
end
end
Loading
Loading