mirror of
https://gitlab.com/fabinfra/fabaccess/FabFire-Provisioning-Tool.git
synced 2025-03-12 23:01:53 +01:00
removed println clutter and added relevant output for the user
This commit is contained in:
parent
63349320e7
commit
2a74d54e2f
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -126,7 +126,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "desfire"
|
name = "desfire"
|
||||||
version = "0.1.0"
|
version = "0.2.0-alpha1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "83dddd3136b4dfc80f46dc6441cd3f16f99317e645bedc61eabc1452d24bfb3f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"block-modes",
|
"block-modes",
|
||||||
|
@ -3,9 +3,10 @@ FabFire Provisioning Tool
|
|||||||
# Usage
|
# Usage
|
||||||
## Provisioning
|
## Provisioning
|
||||||
```shell
|
```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.
|
You can supply your own keys and Application ID with the appropriate cmdline arguments, view `--help` for more information.
|
||||||
|
|
||||||
## Formating Card
|
## Formating Card
|
||||||
|
@ -65,7 +65,6 @@ impl CardTrait for PCSCCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn transmit(&self, apdu_cmd: APDUCommand) -> Result<APDUResponse, Error> {
|
fn transmit(&self, apdu_cmd: APDUCommand) -> Result<APDUResponse, Error> {
|
||||||
println!("{}", apdu_cmd);
|
|
||||||
let apdu = Vec::<u8>::try_from(apdu_cmd).unwrap();
|
let apdu = Vec::<u8>::try_from(apdu_cmd).unwrap();
|
||||||
let mut rapdu_buf = [0; MAX_BUFFER_SIZE];
|
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) {
|
let rapdu = match self.card.as_ref().as_ref().unwrap().transmit(apdu.as_slice(), &mut rapdu_buf) {
|
||||||
|
24
src/main.rs
24
src/main.rs
@ -50,7 +50,7 @@ struct Args {
|
|||||||
#[clap(short, long, required_unless_present = "format")]
|
#[clap(short, long, required_unless_present = "format")]
|
||||||
contact: Option<String>,
|
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)]
|
#[clap(short, long)]
|
||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
|
|
||||||
@ -61,7 +61,6 @@ struct Args {
|
|||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
println!("{:?}", args);
|
|
||||||
|
|
||||||
// connect to the card
|
// connect to the card
|
||||||
let mut card = PCSCCard::new()?;
|
let mut card = PCSCCard::new()?;
|
||||||
@ -93,6 +92,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
desfire.select_application(0x000000);
|
desfire.select_application(0x000000);
|
||||||
desfire.authenticate_iso_des(0x00, master_key.key.as_ref(), None)?;
|
desfire.authenticate_iso_des(0x00, master_key.key.as_ref(), None)?;
|
||||||
desfire.format_picc()?;
|
desfire.format_picc()?;
|
||||||
|
|
||||||
|
println!("Card formatted");
|
||||||
|
|
||||||
return Ok(())
|
return Ok(())
|
||||||
} else {
|
} else {
|
||||||
let space = match args.space {
|
let space = match args.space {
|
||||||
@ -113,17 +115,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// encode the space info
|
// encode the space info
|
||||||
let space_urn = UrnBuilder::new("fabaccess", &format!("lab:{}", urlencoding::encode(space)))
|
let space_urn = UrnBuilder::new("fabaccess", &format!("lab:{}", urlencoding::encode(space)))
|
||||||
.build()?;
|
.build()?;
|
||||||
println!("Space URN: {}", space_urn);
|
|
||||||
|
|
||||||
let instance_uri = URI::builder()
|
let instance_uri = URI::builder()
|
||||||
.with_scheme(Scheme::Unregistered(UnregisteredScheme::try_from("fabaccess")?))
|
.with_scheme(Scheme::Unregistered(UnregisteredScheme::try_from("fabaccess")?))
|
||||||
.with_authority(Some(Authority::try_from(instance.deref())?))
|
.with_authority(Some(Authority::try_from(instance.deref())?))
|
||||||
.with_path(Path::try_from("")?)
|
.with_path(Path::try_from("")?)
|
||||||
.build()?;
|
.build()?;
|
||||||
println!("Instance URI: {}", instance_uri);
|
|
||||||
|
|
||||||
let contact_uri = URI::try_from(contact.deref())?;
|
let contact_uri = URI::try_from(contact.deref())?;
|
||||||
println!("Contact URI: {}", contact_uri);
|
|
||||||
|
|
||||||
let token = match args.token {
|
let token = match args.token {
|
||||||
Some(token) => {
|
Some(token) => {
|
||||||
@ -136,7 +135,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Uuid::new_v4().to_string()
|
Uuid::new_v4().to_string()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!("Token: {}", token);
|
|
||||||
|
|
||||||
// authenticate against picc
|
// authenticate against picc
|
||||||
desfire.authenticate_iso_des(0x00, master_key.key.as_ref(), None)?;
|
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
|
// select the application
|
||||||
desfire.select_application(args.app_id);
|
desfire.select_application(args.app_id);
|
||||||
|
|
||||||
println!("generated application");
|
|
||||||
|
|
||||||
// change the application master key
|
// change the application master key
|
||||||
desfire.authenticate_iso_aes(0x00, CipherKey::new_empty(CipherType::AES)?.key.as_ref(), None)?;
|
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)?;
|
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
|
// authenticate with new application master key
|
||||||
desfire.authenticate_iso_aes(0x00, app_key.key.as_ref(), None)?;
|
desfire.authenticate_iso_aes(0x00, app_key.key.as_ref(), None)?;
|
||||||
|
|
||||||
println!("authenticated with new application master key");
|
|
||||||
|
|
||||||
// set the user authentication 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)?;
|
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
|
// create file with magic
|
||||||
let magic_accessrights = generate_file_access_rights(FileAccessRights::FREE as u8, 0x00, 0x00, 0x00)?;
|
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)?;
|
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())?;
|
desfire.write_data(0x01, 0x00, args.magic.as_bytes())?;
|
||||||
println!("wrote magic");
|
|
||||||
|
|
||||||
// create file with space info
|
// create file with space info
|
||||||
let space_accessrights = generate_file_access_rights(FileAccessRights::FREE as u8, 0x00, 0x00, 0x00)?;
|
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, 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 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())?;
|
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
|
// create file with token
|
||||||
let token_accessrights = generate_file_access_rights(FileAccessRights::FREE as u8, 0x00, 0x00, 0x00)?;
|
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.create_file_standard(0x03, FileCommunication::PLAIN, token_accessrights, MAX_BYTES_PER_TRANSACTION as u32)?; // Max
|
||||||
desfire.write_data(0x03, 0x00, token.as_bytes())?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user