-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IssuerAuth, MdocAuth, ReaderAuth checks (#75)
This PR adds support for the mdoc holder to validate the ReaderAuth, and the mdoc reader to validate the mdoc auth and issuer auth. Remaining outstanding work items: * Check CRL of DS and IACA certificates. * Check CRL/OCSP for reader and reader CA certificates. * Add support for producing ReaderAuth secured document requests. * Add support for key curves other than P-256. * Perform validation of particular mDL attributes (e.g. country name matches certificate). --------- Co-authored-by: Jacob <[email protected]>
- Loading branch information
1 parent
72d8f61
commit b3a0317
Showing
48 changed files
with
2,939 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use std::{collections::BTreeMap, fs::File, io::Read, path::PathBuf}; | ||
|
||
use anyhow::{Context, Error, Ok}; | ||
use clap::Parser; | ||
use clap_stdin::MaybeStdin; | ||
use isomdl::presentation::{device::Document, Stringify}; | ||
|
||
mod x509; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Args { | ||
#[command(subcommand)] | ||
action: Action, | ||
} | ||
|
||
#[derive(Debug, clap::Subcommand)] | ||
enum Action { | ||
/// Print the namespaces and element identifiers used in an mDL. | ||
GetNamespaces { | ||
/// Base64 encoded mDL in the format used in the issuance module of this crate. | ||
mdl: MaybeStdin<String>, | ||
}, | ||
/// Validate a document signer cert against a possible root certificate. | ||
ValidateCerts { | ||
/// Validation rule set. | ||
rules: RuleSet, | ||
/// Path to PEM-encoded document signer cert. | ||
ds: PathBuf, | ||
/// Path to PEM-encoded IACA root cert. | ||
root: PathBuf, | ||
}, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, clap::ValueEnum)] | ||
enum RuleSet { | ||
Iaca, | ||
Aamva, | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
match Args::parse().action { | ||
Action::GetNamespaces { mdl } => print_namespaces(mdl.to_string()), | ||
Action::ValidateCerts { rules, ds, root } => validate_certs(rules, ds, root), | ||
} | ||
} | ||
|
||
fn print_namespaces(mdl: String) -> Result<(), Error> { | ||
let claims = Document::parse(mdl) | ||
.context("could not parse mdl")? | ||
.namespaces | ||
.into_inner() | ||
.into_iter() | ||
.map(|(ns, inner)| (ns, inner.into_inner().into_keys().collect())) | ||
.collect::<BTreeMap<String, Vec<String>>>(); | ||
println!("{}", serde_json::to_string_pretty(&claims)?); | ||
Ok(()) | ||
} | ||
|
||
fn validate_certs(rules: RuleSet, ds: PathBuf, root: PathBuf) -> Result<(), Error> { | ||
let mut ds_bytes = vec![]; | ||
File::open(ds)?.read_to_end(&mut ds_bytes)?; | ||
let mut root_bytes = vec![]; | ||
File::open(root)?.read_to_end(&mut root_bytes)?; | ||
let validation_errors = x509::validate(rules, &ds_bytes, &root_bytes)?; | ||
if validation_errors.is_empty() { | ||
println!("Validated!"); | ||
} else { | ||
println!( | ||
"Validation errors:\n{}", | ||
serde_json::to_string_pretty(&validation_errors)? | ||
) | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn print_namespaces() { | ||
super::print_namespaces(include_str!("../../test/stringified-mdl.txt").to_string()).unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use der::DecodePem; | ||
use isomdl::definitions::x509::{ | ||
trust_anchor::{TrustAnchor, TrustAnchorRegistry, TrustPurpose}, | ||
validation::ValidationRuleset, | ||
X5Chain, | ||
}; | ||
use x509_cert::Certificate; | ||
|
||
use crate::RuleSet; | ||
|
||
pub fn validate(rules: RuleSet, signer: &[u8], root: &[u8]) -> Result<Vec<String>, anyhow::Error> { | ||
let root = Certificate::from_pem(root)?; | ||
|
||
let trust_anchor = TrustAnchor { | ||
certificate: root, | ||
purpose: TrustPurpose::Iaca, | ||
}; | ||
|
||
let trust_anchor_registry = TrustAnchorRegistry { | ||
anchors: vec![trust_anchor], | ||
}; | ||
|
||
let x5chain = X5Chain::builder().with_pem_certificate(signer)?.build()?; | ||
|
||
let outcome = match rules { | ||
RuleSet::Iaca => ValidationRuleset::Mdl, | ||
RuleSet::Aamva => ValidationRuleset::AamvaMdl, | ||
} | ||
.validate(&x5chain, &trust_anchor_registry); | ||
|
||
Ok(outcome.errors) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.