removed println clutter and added relevant output for the user

This commit is contained in:
Kai Jan Kriegel 2022-03-13 18:42:09 +01:00
parent 63349320e7
commit 2a74d54e2f
4 changed files with 12 additions and 22 deletions

4
Cargo.lock generated
View File

@ -126,7 +126,9 @@ dependencies = [
[[package]]
name = "desfire"
version = "0.1.0"
version = "0.2.0-alpha1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83dddd3136b4dfc80f46dc6441cd3f16f99317e645bedc61eabc1452d24bfb3f"
dependencies = [
"aes",
"block-modes",

View File

@ -3,9 +3,10 @@ FabFire Provisioning Tool
# Usage
## Provisioning
```shell
cargo run -- --space "innovisionlab" --instance fabaccess.innovisionlab.de --contact https://innovisionlab.de/lostandfound
cargo run -- --space "innovisionlab" --instance fabaccess.innovisionlab.de --contact https://innovisionlab.de/lostandfound --token "Testuser"
```
Replace `--space`, `--instance` and `--contact` with your own values.
1. Replace `--space`, `--instance` and `--contact` with your own values.
2. Set `--token` to the users username.
You can supply your own keys and Application ID with the appropriate cmdline arguments, view `--help` for more information.
## Formating Card

View File

@ -65,7 +65,6 @@ impl CardTrait for PCSCCard {
}
fn transmit(&self, apdu_cmd: APDUCommand) -> Result<APDUResponse, Error> {
println!("{}", apdu_cmd);
let apdu = Vec::<u8>::try_from(apdu_cmd).unwrap();
let mut rapdu_buf = [0; MAX_BUFFER_SIZE];
let rapdu = match self.card.as_ref().as_ref().unwrap().transmit(apdu.as_slice(), &mut rapdu_buf) {

View File

@ -50,7 +50,7 @@ struct Args {
#[clap(short, long, required_unless_present = "format")]
contact: Option<String>,
/// User token (will be generated for you if not given)
/// User token, currently this should be set to the Username (will be generated for you if not given)
#[clap(short, long)]
token: Option<String>,
@ -61,7 +61,6 @@ struct Args {
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
println!("{:?}", args);
// connect to the card
let mut card = PCSCCard::new()?;
@ -93,6 +92,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
desfire.select_application(0x000000);
desfire.authenticate_iso_des(0x00, master_key.key.as_ref(), None)?;
desfire.format_picc()?;
println!("Card formatted");
return Ok(())
} else {
let space = match args.space {
@ -113,17 +115,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// encode the space info
let space_urn = UrnBuilder::new("fabaccess", &format!("lab:{}", urlencoding::encode(space)))
.build()?;
println!("Space URN: {}", space_urn);
let instance_uri = URI::builder()
.with_scheme(Scheme::Unregistered(UnregisteredScheme::try_from("fabaccess")?))
.with_authority(Some(Authority::try_from(instance.deref())?))
.with_path(Path::try_from("")?)
.build()?;
println!("Instance URI: {}", instance_uri);
let contact_uri = URI::try_from(contact.deref())?;
println!("Contact URI: {}", contact_uri);
let token = match args.token {
Some(token) => {
@ -136,7 +135,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Uuid::new_v4().to_string()
}
};
println!("Token: {}", token);
// authenticate against picc
desfire.authenticate_iso_des(0x00, master_key.key.as_ref(), None)?;
@ -153,32 +151,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// select the application
desfire.select_application(args.app_id);
println!("generated application");
// change the application master key
desfire.authenticate_iso_aes(0x00, CipherKey::new_empty(CipherType::AES)?.key.as_ref(), None)?;
desfire.change_key_aes(0x00, app_key.key.as_ref(), app_key.key_version)?;
println!("changed application master key");
// authenticate with new application master key
desfire.authenticate_iso_aes(0x00, app_key.key.as_ref(), None)?;
println!("authenticated with new application master key");
// set the user authentication key
desfire.change_other_key_aes(0x01, user_key.key.as_ref(), CipherKey::new_empty(CipherType::AES)?.key.as_ref(), user_key.key_version)?;
println!("changed user authentication key");
println!("creating magic file with size {}", args.magic.len());
// create file with magic
let magic_accessrights = generate_file_access_rights(FileAccessRights::FREE as u8, 0x00, 0x00, 0x00)?;
desfire.create_file_standard(0x01, FileCommunication::PLAIN, magic_accessrights, args.magic.as_bytes().len() as u32)?;
println!("created magic file");
desfire.write_data(0x01, 0x00, args.magic.as_bytes())?;
println!("wrote magic");
// create file with space info
let space_accessrights = generate_file_access_rights(FileAccessRights::FREE as u8, 0x00, 0x00, 0x00)?;
@ -186,13 +174,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
desfire.write_data(0x02, 0x00, space_urn.as_bytes())?;
desfire.write_data(0x02, MAX_BYTES_PER_TRANSACTION as u32, instance_uri.to_string().as_bytes())?;
desfire.write_data(0x02, (MAX_BYTES_PER_TRANSACTION * 2) as u32, contact_uri.to_string().as_bytes())?;
println!("created space info file");
// create file with token
let token_accessrights = generate_file_access_rights(FileAccessRights::FREE as u8, 0x00, 0x00, 0x00)?;
desfire.create_file_standard(0x03, FileCommunication::PLAIN, token_accessrights, MAX_BYTES_PER_TRANSACTION as u32)?; // Max
desfire.write_data(0x03, 0x00, token.as_bytes())?;
println!("created token file");
println!("Card provisioned! Add the following to the users entry in 'users.toml': cardkey = \"{}\"", hex::encode(user_key.key));
Ok(())
}