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

Adds support for YubiHSM Auth #459

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ jobs:
- uses: actions/checkout@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.71.0 # pinned to prevent CI breakages
toolchain: 1.81.0 # pinned to prevent CI breakages
components: clippy
- run: sudo apt-get install libpcsclite-dev
- uses: actions-rs/cargo@v1
with:
command: clippy
Expand Down
105 changes: 105 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pbkdf2 = { version = "0.12", optional = true, default-features = false, features
serde_json = { version = "1", optional = true }
rusb = { version = "0.9.4", optional = true }
tiny_http = { version = "0.12", optional = true }
yubikey = { git = "https://github.com/baloo/yubikey.rs", branch = "baloo/yubihsm-auth", optional = true }

[dev-dependencies]
ed25519-dalek = "2"
Expand All @@ -68,6 +69,7 @@ secp256k1 = ["k256"]
setup = ["passwords", "serde_json", "uuid/serde"]
untested = []
usb = ["rusb"]
yubihsm-auth = ["yubikey"]

[package.metadata.docs.rs]
all-features = true
Expand Down
4 changes: 2 additions & 2 deletions src/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'de> Deserialize<'de> for AuditOption {
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<AuditOption, D::Error> {
struct AuditOptionVisitor;

impl<'de> de::Visitor<'de> for AuditOptionVisitor {
impl de::Visitor<'_> for AuditOptionVisitor {
type Value = AuditOption;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<'de> Deserialize<'de> for AuditTag {
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<AuditTag, D::Error> {
struct AuditTagVisitor;

impl<'de> de::Visitor<'de> for AuditTagVisitor {
impl de::Visitor<'_> for AuditTagVisitor {
type Value = AuditTag;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'de> Deserialize<'de> for Capability {
{
struct CapabilityVisitor;

impl<'de> Visitor<'de> for CapabilityVisitor {
impl Visitor<'_> for CapabilityVisitor {
type Value = Capability;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
29 changes: 29 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ use std::{
#[cfg(feature = "passwords")]
use std::{thread, time::SystemTime};

#[cfg(feature = "yubihsm-auth")]
use crate::session::PendingSession;

#[cfg(feature = "untested")]
use crate::{
algorithm::Algorithm,
Expand Down Expand Up @@ -103,6 +106,20 @@ impl Client {
Ok(client)
}

/// Open session with YubiHSM Auth scheme
#[cfg(feature = "yubihsm-auth")]
pub fn yubihsm_auth(
connector: Connector,
authentication_key_id: object::Id,
host_challenge: session::securechannel::Challenge,
) -> Result<PendingSession, Error> {
let timeout = session::Timeout::default();

let session =
PendingSession::new(connector, timeout, authentication_key_id, host_challenge)?;
Ok(session)
}

/// Borrow this client's YubiHSM connector (which is `Clone`able)
pub fn connector(&self) -> &Connector {
&self.connector
Expand Down Expand Up @@ -1169,3 +1186,15 @@ impl Client {
.0)
}
}

impl From<Session> for Client {
fn from(session: Session) -> Self {
let connector = session.connector();
let session = Arc::new(Mutex::new(Some(session)));
Self {
connector,
session,
credentials: None,
}
}
}
2 changes: 1 addition & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) trait Command: Serialize + DeserializeOwned + Sized {
const COMMAND_CODE: Code = Self::ResponseType::COMMAND_CODE;
}

impl<'c, C: Command> From<&'c C> for Message {
impl<C: Command> From<&C> for Message {
fn from(command: &C) -> Message {
Self::create(C::COMMAND_CODE, serialize(command).unwrap()).unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion src/connector/http/client/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Display for PathBuf {
}
}

impl<'a> From<&'a str> for PathBuf {
impl From<&str> for PathBuf {
fn from(path: &str) -> Self {
Self::from_str(path).unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'de> Deserialize<'de> for Domain {
{
struct DomainVisitor;

impl<'de> de::Visitor<'de> for DomainVisitor {
impl de::Visitor<'_> for DomainVisitor {
type Value = Domain;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion src/object/origins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'de> Deserialize<'de> for Origin {
{
struct OriginVisitor;

impl<'de> de::Visitor<'de> for OriginVisitor {
impl de::Visitor<'_> for OriginVisitor {
type Value = Origin;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion src/object/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<'de> Deserialize<'de> for Type {
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Type, D::Error> {
struct TypeVisitor;

impl<'de> de::Visitor<'de> for TypeVisitor {
impl de::Visitor<'_> for TypeVisitor {
type Value = Type;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
8 changes: 4 additions & 4 deletions src/serialization/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<R: Read> Deserializer<R> {
}
}

impl<'de, 'a, R: Read> serde::Deserializer<'de> for &'a mut Deserializer<R> {
impl<'de, R: Read> serde::Deserializer<'de> for &mut Deserializer<R> {
type Error = Error;

#[inline]
Expand Down Expand Up @@ -184,7 +184,7 @@ impl<'de, 'a, R: Read> serde::Deserializer<'de> for &'a mut Deserializer<R> {
len: usize,
}

impl<'de, 'a, 'b: 'a, R: Read> SeqAccess<'de> for Access<'a, R> {
impl<'de, R: Read> SeqAccess<'de> for Access<'_, R> {
type Error = Error;

fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Error>
Expand Down Expand Up @@ -227,7 +227,7 @@ impl<'de, 'a, R: Read> serde::Deserializer<'de> for &'a mut Deserializer<R> {
deserializer: &'a mut Deserializer<R>,
}

impl<'de, 'a, 'b: 'a, R: Read> SeqAccess<'de> for Access<'a, R> {
impl<'de, R: Read> SeqAccess<'de> for Access<'_, R> {
type Error = Error;

fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Error>
Expand Down Expand Up @@ -309,7 +309,7 @@ impl<'de, 'a, R: Read> serde::Deserializer<'de> for &'a mut Deserializer<R> {
}
}

impl<'de, 'a, R: Read> serde::de::VariantAccess<'de> for &'a mut Deserializer<R> {
impl<'de, R: Read> serde::de::VariantAccess<'de> for &mut Deserializer<R> {
type Error = Error;

fn unit_variant(self) -> Result<(), Error> {
Expand Down
Loading
Loading