mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-12-06 19:39:20 +01:00
Implement auto detection of encrypted root devices (fix #21)
This commit is contained in:
@@ -2,10 +2,16 @@ use super::markers::BlockDevice;
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::process::CommandExt;
|
||||
use crate::tool::Tool;
|
||||
use failure::ResultExt;
|
||||
use log::{debug, warn};
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
use std::marker::PhantomData;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
static LUKS_MAGIC_1: &'static [u8] = &[0x4c, 0x55, 0x4b, 0x53, 0xba, 0xbe];
|
||||
static LUKS_MAGIC_2: &'static [u8] = &[0x53, 0x4b, 0x55, 0x4c, 0xba, 0xbe];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EncryptedDevice<'t, 'o> {
|
||||
cryptsetup: &'t Tool,
|
||||
@@ -78,3 +84,17 @@ impl<'t, 'o> BlockDevice for EncryptedDevice<'t, 'o> {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_encrypted_device(device: &BlockDevice) -> Result<bool, Error> {
|
||||
let mut f = fs::OpenOptions::new()
|
||||
.read(true)
|
||||
.write(false)
|
||||
.open(device.path())
|
||||
.context(ErrorKind::LuksDetection)?;
|
||||
|
||||
let mut buffer = [0; 6];
|
||||
f.read_exact(&mut buffer)
|
||||
.context(ErrorKind::LuksDetection)?;
|
||||
|
||||
Ok(buffer == LUKS_MAGIC_1 || buffer == LUKS_MAGIC_2)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ mod mount_stack;
|
||||
mod partition;
|
||||
mod storage_device;
|
||||
|
||||
pub use crypt::EncryptedDevice;
|
||||
pub use crypt::{is_encrypted_device, EncryptedDevice};
|
||||
pub use filesystem::{Filesystem, FilesystemType};
|
||||
pub use loop_device::LoopDevice;
|
||||
pub use markers::BlockDevice;
|
||||
|
||||
Reference in New Issue
Block a user