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

Defer unlock prompt until update is accepted #82

Merged
merged 1 commit into from
Jun 28, 2023
Merged
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
18 changes: 1 addition & 17 deletions src/app/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@
let mut system_version = String::new();

for table in crate::dmi::dmi() {
match table.header.kind {
1 => {
if let Ok(info) = dmi::SystemInfo::from_bytes(&table.data) {
let index = info.version;
if index > 0 {
if let Some(value) = table.strings.get((index - 1) as usize) {
system_version = value.trim().to_string();
}
}
}
}
_ => {}
}

Check warning on line 75 in src/app/ec.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for an equality check. Consider using `if`

warning: you seem to be trying to use `match` for an equality check. Consider using `if` --> src/app/ec.rs:63:17 | 63 | / match table.header.kind { 64 | | 1 => { 65 | | if let Ok(info) = dmi::SystemInfo::from_bytes(&table.data) { 66 | | let index = info.version; ... | 74 | | _ => {} 75 | | } | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `#[warn(clippy::single_match)]` on by default help: try this | 63 ~ if table.header.kind == 1 { 64 + if let Ok(info) = dmi::SystemInfo::from_bytes(&table.data) { 65 + let index = info.version; 66 + if index > 0 { 67 + if let Some(value) = table.strings.get((index - 1) as usize) { 68 + system_version = value.trim().to_string(); 69 + } 70 + } 71 + } 72 + } |
}

if system_version == "pang12" {
Expand Down Expand Up @@ -142,7 +142,7 @@
match self {
EcKind::Pang12(pmc) => {
let mut hms = [0u8; 3];
for i in 0..hms.len() {

Check warning on line 145 in src/app/ec.rs

View workflow job for this annotation

GitHub Actions / clippy

the loop variable `i` is used to index `hms`

warning: the loop variable `i` is used to index `hms` --> src/app/ec.rs:145:26 | 145 | for i in 0..hms.len() { | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop = note: `#[warn(clippy::needless_range_loop)]` on by default help: consider using an iterator | 145 | for (i, <item>) in hms.iter_mut().enumerate() { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
match pmc.acpi_read(0x08 + i as u8) {
Ok(value) => hms[i] = value,
Err(err) => {
Expand All @@ -153,7 +153,7 @@
}

let mut ymd = [0u8; 3];
for i in 0..ymd.len() {

Check warning on line 156 in src/app/ec.rs

View workflow job for this annotation

GitHub Actions / clippy

the loop variable `i` is used to index `ymd`

warning: the loop variable `i` is used to index `ymd` --> src/app/ec.rs:156:26 | 156 | for i in 0..ymd.len() { | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop help: consider using an iterator | 156 | for (i, <item>) in ymd.iter_mut().enumerate() { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
match pmc.acpi_read(0x0C + i as u8) {
Ok(value) => ymd[i] = value,
Err(err) => {
Expand Down Expand Up @@ -224,13 +224,13 @@

pub fn validate_data(&self, data: Vec<u8>) -> bool {
// Special case for pang12
match &self.ec {
EcKind::Pang12(_pmc) => {
return data.len() == 128 * 1024
&& &data[0x50 ..= 0x05F] == b"ITE EC-V14.6 \0";
},
_ => (),
}

Check warning on line 233 in src/app/ec.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/app/ec.rs:227:9 | 227 | / match &self.ec { 228 | | EcKind::Pang12(_pmc) => { 229 | | return data.len() == 128 * 1024 230 | | && &data[0x50 ..= 0x05F] == b"ITE EC-V14.6 \0"; 231 | | }, 232 | | _ => (), 233 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match help: try this | 227 ~ if let EcKind::Pang12(_pmc) = &self.ec { 228 + return data.len() == 128 * 1024 229 + && &data[0x50 ..= 0x05F] == b"ITE EC-V14.6 \0"; 230 + } |

let normalize_model = |model: &str| -> String {
match model {
Expand Down Expand Up @@ -448,7 +448,7 @@
Ok(())
}

unsafe fn security_unlock() -> core::result::Result<(), ectool::Error> {
pub unsafe fn security_unlock() -> core::result::Result<(), ectool::Error> {
let access = AccessLpcDirect::new(UefiTimeout::new(100_000))?;
let mut ec = ectool::Ec::new(access)?;

Expand Down Expand Up @@ -690,22 +690,6 @@
}

fn validate(&self) -> Result<bool> {
// If EC tag does not exist
if find(ECTAG).is_err() {
match &self.ec {
// Make sure EC is unlocked if running System76 EC
EcKind::System76(_, _) => match unsafe { security_unlock() } {
Ok(()) => (),
Err(err) => {
println!("{} Failed to unlock: {:?}", self.name(), err);
return Err(Error::DeviceError);
}
},
// Assume EC is unlocked if not running System76 EC
_ => (),
}
}

let data = load(self.path())?;
Ok(self.validate_data(data))
}
Expand All @@ -725,10 +709,10 @@
EcKind::Pang12(_pmc) => {
find(FIRMWARENSH)?;
let command = if self.master { "ec" } else { "ec2" };
let status = shell(&format!(
"{} {} {} flash",
FIRMWARENSH, FIRMWAREDIR, command
))?;

Check warning on line 715 in src/app/ec.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/app/ec.rs:712:37 | 712 | let status = shell(&format!( | _____________________________________^ 713 | | "{} {} {} flash", 714 | | FIRMWARENSH, FIRMWAREDIR, command 715 | | ))?; | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
if status == 0 {
Ok(())
} else {
Expand Down Expand Up @@ -762,10 +746,10 @@
} else {
find(FIRMWARENSH)?;
let command = if self.master { "ec" } else { "ec2" };
let status = shell(&format!(
"{} {} {} flash",
FIRMWARENSH, FIRMWAREDIR, command
))?;

Check warning on line 752 in src/app/ec.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/app/ec.rs:749:41 | 749 | let status = shell(&format!( | _________________________________________^ 750 | | "{} {} {} flash", 751 | | FIRMWARENSH, FIRMWAREDIR, command 752 | | ))?; | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
if status == 0 {
Ok(())
} else {
Expand Down
20 changes: 20 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,26 @@

if c == '\n' || c == '\r' {
success = true;

{
let ec_kind = unsafe { EcKind::new(true) };
// If EC tag does not exist, unlock the firmware
if find(ECTAG).is_err() {
match ec_kind {
// Make sure EC is unlocked if running System76 EC
EcKind::System76(_, _) => match unsafe { ec::security_unlock() } {
Ok(()) => (),
Err(err) => {
println!("Failed to unlock firmware: {:?}", err);
return Err(Error::DeviceError);
}
},
// Assume EC is unlocked if not running System76 EC
_ => (),
}

Check warning on line 287 in src/app/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/app/mod.rs:276:21 | 276 | / match ec_kind { 277 | | // Make sure EC is unlocked if running System76 EC 278 | | EcKind::System76(_, _) => match unsafe { ec::security_unlock() } { 279 | | Ok(()) => (), ... | 286 | | _ => (), 287 | | } | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match help: try this | 276 ~ if let EcKind::System76(_, _) = ec_kind { match unsafe { ec::security_unlock() } { 277 + Ok(()) => (), 278 + Err(err) => { 279 + println!("Failed to unlock firmware: {:?}", err); 280 + return Err(Error::DeviceError); 281 + } 282 + } } |
}
}

for (component, validation) in components.iter().zip(validations.iter()) {
if *validation == ValidateKind::Found {
// Only shutdown if components are flashed
Expand Down
Loading