Compare commits

...

10 Commits

Author SHA1 Message Date
8811cff6d1 0.2.12
All checks were successful
continuous-integration/drone/tag Build is passing
2020-08-31 00:04:24 +02:00
99787b614c Merge branch 'pin_source' into master
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-08-31 00:00:42 +02:00
ee28f87148 always print the full error message
All checks were successful
continuous-integration/drone/push Build is passing
2020-08-30 17:09:57 +02:00
196356fe3b structopt does not allow for flags to be linked to env atm 2020-08-25 21:47:25 +02:00
3ff7e698bd add flag to read pin from alternate source
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-08-25 21:26:30 +02:00
04d0d60fb3 use ubuntu as base image
Some checks reported errors
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build was killed
2020-08-16 15:30:20 +02:00
e64f777c54 use sh to run password helper 2020-08-16 13:42:54 +02:00
8465949b44 spell promPt correctly 2020-08-16 13:42:35 +02:00
shimunn
06bed03e7b Merge pull request #13 from Andrew-Finn/master
Added documentation and tweaked readme
2020-08-14 12:40:02 +02:00
Andrew-Finn
36f82e7c3a Added and edited documentation 2020-08-14 11:36:25 +01:00
10 changed files with 77 additions and 41 deletions

View File

@@ -5,24 +5,24 @@ steps:
- name: fmt - name: fmt
image: rust:1.43.0 image: rust:1.43.0
commands: commands:
- rustup component add rustfmt - rustup component add rustfmt
- cargo fmt --all -- --check - cargo fmt --all -- --check
- name: test - name: test
image: rust:1.43.0 image: ubuntu:focal
commands:
- apt update && apt install -y libkeyutils-dev libclang-dev clang pkg-config
- echo 'deb http://http.us.debian.org/debian unstable main non-free contrib' >> /etc/apt/sources.list.d/unstable.list && apt update && apt install -y libcryptsetup-dev
- cargo test
- name: publish
image: rust:1.43.0
environment: environment:
DEBIAN_FRONTEND: noninteractive
commands:
- apt update && apt install -y cargo libkeyutils-dev libclang-dev clang pkg-config libcryptsetup-dev
- cargo test --locked
- name: publish
image: ubuntu:focal
environment:
DEBIAN_FRONTEND: noninteractive
CARGO_REGISTRY_TOKEN: CARGO_REGISTRY_TOKEN:
from_secret: cargo_tkn from_secret: cargo_tkn
commands: commands:
- grep -E 'version ?= ?"${DRONE_TAG}"' -i Cargo.toml || (printf "incorrect crate/tag version" && exit 1) - grep -E 'version ?= ?"${DRONE_TAG}"' -i Cargo.toml || (printf "incorrect crate/tag version" && exit 1)
- apt update && apt install -y libkeyutils-dev libclang-dev clang pkg-config - apt update && apt install -y cargo libkeyutils-dev libclang-dev clang pkg-config libcryptsetup-dev
- echo 'deb http://http.us.debian.org/debian unstable main non-free contrib' >> /etc/apt/sources.list.d/unstable.list && apt update && apt install -y libcryptsetup-dev
- cargo package --all-features - cargo package --all-features
- cargo publish --all-features - cargo publish --all-features
when: when:

2
Cargo.lock generated
View File

@@ -377,7 +377,7 @@ dependencies = [
[[package]] [[package]]
name = "fido2luks" name = "fido2luks"
version = "0.2.10" version = "0.2.12"
dependencies = [ dependencies = [
"ctap_hmac", "ctap_hmac",
"failure", "failure",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "fido2luks" name = "fido2luks"
version = "0.2.10" version = "0.2.12"
authors = ["shimunn <shimun@shimun.net>"] authors = ["shimunn <shimun@shimun.net>"]
edition = "2018" edition = "2018"

View File

@@ -1,6 +1,6 @@
# fido2luks [![Crates.io Version](https://img.shields.io/crates/v/fido2luks.svg)](https://crates.io/crates/fido2luks) # fido2luks [![Crates.io Version](https://img.shields.io/crates/v/fido2luks.svg)](https://crates.io/crates/fido2luks)
This will allow you to unlock your luks encrypted disk with an fido2 compatible key This will allow you to unlock your LUKS encrypted disk with an FIDO2 compatible key.
Note: This has only been tested under Fedora 31, [Ubuntu 20.04](initramfs-tools/), [NixOS](https://nixos.org/nixos/manual/#sec-luks-file-systems-fido2) using a Solo Key, Trezor Model T Note: This has only been tested under Fedora 31, [Ubuntu 20.04](initramfs-tools/), [NixOS](https://nixos.org/nixos/manual/#sec-luks-file-systems-fido2) using a Solo Key, Trezor Model T
@@ -65,7 +65,7 @@ cp /usr/bin/fido2luks /boot/fido2luks/
cp /etc/fido2luks.conf /boot/fido2luks/ cp /etc/fido2luks.conf /boot/fido2luks/
``` ```
## Test ## Testing
Just reboot and see if it works, if that's the case you should remove your old less secure password from your LUKS header: Just reboot and see if it works, if that's the case you should remove your old less secure password from your LUKS header:
@@ -96,6 +96,13 @@ set -a
Then add the new secret to each device and update dracut afterwards `dracut -f` Then add the new secret to each device and update dracut afterwards `dracut -f`
### Multiple keys
Additional/backup keys are supported, Multiple fido2luks credentials can be added to your /etc/fido2luks.conf file. Credential tokens are comma separated.
```
FIDO2LUKS_CREDENTIAL_ID=<CREDENTIAL1>,<CREDENTIAL2>,<CREDENTIAL3>
```
## Removal ## Removal
Remove `rd.luks.2fa` from `GRUB_CMDLINE_LINUX` in /etc/default/grub Remove `rd.luks.2fa` from `GRUB_CMDLINE_LINUX` in /etc/default/grub

View File

@@ -1,13 +1,34 @@
## Initramfs-tools based systems(Ubuntu and derivatives) ## Initramfs-tools based systems(Ubuntu and derivatives)
After installation generate your credentials and add keys to your disk as described in the top-level README For easiest installation [download and install the precompiled deb from releases.](https://github.com/shimunn/fido2luks/releases). However it is possible to build from source via the instructions on the main readme.
then add `initramfs,keyscript=fido2luks` to your `/etc/crypttab`
Example:
```
sda6_crypt UUID=9793d81a-4cfb-4712-85f3-c7a8d715112c none luks,discard,initramfs,keyscript=fido2luks
``` ```
sudo -s
But don't forget to run `make install` which will install all necessary scripts and regenerate your intrid. # Insert FIDO key.
fido2luks credential
# Tap FIDO key
# Copy returned string <CREDENTIAL>
nano /etc/fido2luks.conf
# Insert <CREDENTIAL>
# FIDO2LUKS_CREDENTIAL_ID=<CREDENTIAL>
set -a
. /etc/fido2luks.conf
fido2luks -i add-key /dev/<LUKS PARTITION>
# Current password: <Any current LUKS password>
# Password: <Password used as FIDO challange>
# Tap FIDO key
nano /etc/crypttab
# Append to end ",discard,initramfs,keyscript=fido2luks"
# E.g. sda6_crypt UUID=XXXXXXXXXX none luks,discard,initramfs,keyscript=fido2luks
update-initramfs -u
```
[Recording showing part of the setup](https://shimun.net/fido2luks/setup.svg) [Recording showing part of the setup](https://shimun.net/fido2luks/setup.svg)

View File

@@ -1,3 +1,3 @@
FIDO2LUKS_SALT=Ask FIDO2LUKS_SALT=Ask
#FIDO2LUKS_PASSWORD_HELPER="/usr/bin/plymouth ask-for-password --promt 'FIDO2 password salt'" #FIDO2LUKS_PASSWORD_HELPER="/usr/bin/plymouth ask-for-password --prompt 'FIDO2 password salt'"
FIDO2LUKS_CREDENTIAL_ID= FIDO2LUKS_CREDENTIAL_ID=

View File

@@ -4,8 +4,7 @@ set -a
if [ -z "$FIDO2LUKS_PASSWORD_HELPER" ]; then if [ -z "$FIDO2LUKS_PASSWORD_HELPER" ]; then
MSG="FIDO2 password salt for $CRYPTTAB_NAME" MSG="FIDO2 password salt for $CRYPTTAB_NAME"
export FIDO2LUKS_PASSWORD_HELPER="plymouth ask-for-password --promt '$MSG'" export FIDO2LUKS_PASSWORD_HELPER="plymouth ask-for-password --prompt '$MSG'"
plymouth message --text "$MSG"
fi fi
fido2luks print-secret --bin fido2luks print-secret --bin

View File

@@ -7,7 +7,7 @@ use ctap::{FidoCredential, FidoErrorKind};
use failure::_core::fmt::{Display, Error, Formatter}; use failure::_core::fmt::{Display, Error, Formatter};
use failure::_core::str::FromStr; use failure::_core::str::FromStr;
use failure::_core::time::Duration; use failure::_core::time::Duration;
use std::io::Write; use std::io::{Read, Write};
use std::process::exit; use std::process::exit;
use std::thread; use std::thread;
@@ -15,6 +15,7 @@ use crate::luks::{Fido2LuksToken, LuksDevice};
use crate::util::sha256; use crate::util::sha256;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::HashSet; use std::collections::HashSet;
use std::fs::File;
use std::time::SystemTime; use std::time::SystemTime;
#[derive(Debug, Eq, PartialEq, Clone)] #[derive(Debug, Eq, PartialEq, Clone)]
@@ -77,6 +78,10 @@ pub struct AuthenticatorParameters {
#[structopt(short = "P", long = "pin")] #[structopt(short = "P", long = "pin")]
pub pin: bool, pub pin: bool,
/// Location to read PIN from
#[structopt(long = "pin-source", env = "FIDO2LUKS_PIN_SOURCE")]
pub pin_source: Option<PathBuf>,
/// Await for an authenticator to be connected, timeout after n seconds /// Await for an authenticator to be connected, timeout after n seconds
#[structopt( #[structopt(
long = "await-dev", long = "await-dev",
@@ -87,6 +92,18 @@ pub struct AuthenticatorParameters {
pub await_time: u64, pub await_time: u64,
} }
impl AuthenticatorParameters {
fn read_pin(&self) -> Fido2LuksResult<String> {
if let Some(src) = self.pin_source.as_ref() {
let mut pin = String::new();
File::open(src)?.read_to_string(&mut pin)?;
Ok(pin)
} else {
util::read_password("Authenticator PIN", false)
}
}
}
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
pub struct LuksParameters { pub struct LuksParameters {
#[structopt(env = "FIDO2LUKS_DEVICE")] #[structopt(env = "FIDO2LUKS_DEVICE")]
@@ -165,10 +182,6 @@ fn derive_secret(
Ok((sha256(&[salt, &unsalted[..]]), cred.clone())) Ok((sha256(&[salt, &unsalted[..]]), cred.clone()))
} }
fn read_pin() -> Fido2LuksResult<String> {
util::read_password("Authenticator PIN", false)
}
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
pub struct Args { pub struct Args {
/// Request passwords via Stdin instead of using the password helper /// Request passwords via Stdin instead of using the password helper
@@ -345,7 +358,7 @@ pub fn run_cli() -> Fido2LuksResult<()> {
} => { } => {
let pin_string; let pin_string;
let pin = if authenticator.pin { let pin = if authenticator.pin {
pin_string = read_pin()?; pin_string = authenticator.read_pin()?;
Some(pin_string.as_ref()) Some(pin_string.as_ref())
} else { } else {
None None
@@ -362,7 +375,7 @@ pub fn run_cli() -> Fido2LuksResult<()> {
} => { } => {
let pin_string; let pin_string;
let pin = if authenticator.pin { let pin = if authenticator.pin {
pin_string = read_pin()?; pin_string = authenticator.read_pin()?;
Some(pin_string.as_ref()) Some(pin_string.as_ref())
} else { } else {
None None
@@ -406,7 +419,7 @@ pub fn run_cli() -> Fido2LuksResult<()> {
.. ..
} => { } => {
let pin = if authenticator.pin { let pin = if authenticator.pin {
Some(read_pin()?) Some(authenticator.read_pin()?)
} else { } else {
None None
}; };
@@ -522,7 +535,7 @@ pub fn run_cli() -> Fido2LuksResult<()> {
} => { } => {
let pin_string; let pin_string;
let pin = if authenticator.pin { let pin = if authenticator.pin {
pin_string = read_pin()?; pin_string = authenticator.read_pin()?;
Some(pin_string.as_ref()) Some(pin_string.as_ref())
} else { } else {
None None

View File

@@ -135,10 +135,9 @@ impl PasswordHelper {
Systemd => unimplemented!(), Systemd => unimplemented!(),
Stdin => Ok(util::read_password("Password", true)?), Stdin => Ok(util::read_password("Password", true)?),
Script(password_helper) => { Script(password_helper) => {
let mut helper_parts = password_helper.split(' '); let password = Command::new("sh")
.arg("-c")
let password = Command::new((&mut helper_parts).next().unwrap()) .arg(&password_helper)
.args(helper_parts)
.output() .output()
.map_err(|e| Fido2LuksError::AskPassError { .map_err(|e| Fido2LuksError::AskPassError {
cause: error::AskPassError::IO(e), cause: error::AskPassError::IO(e),

View File

@@ -21,10 +21,7 @@ mod util;
fn main() -> Fido2LuksResult<()> { fn main() -> Fido2LuksResult<()> {
match run_cli() { match run_cli() {
Err(e) => { Err(e) => {
#[cfg(debug_assertions)]
eprintln!("{:?}", e); eprintln!("{:?}", e);
#[cfg(not(debug_assertions))]
eprintln!("{}", e);
exit(e.exit_code()) exit(e.exit_code())
} }
_ => exit(0), _ => exit(0),