Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
Georg Bramm committed May 18, 2024
2 parents acca069 + d4a242d commit 718d2f8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ target
.project
rabe.iml
Cargo.lock
**/.DS_Store
2 changes: 1 addition & 1 deletion rabe-console/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rabe-console"
version = "0.4.0"
version = "0.4.1"
description = "Console App for the ABE Schemes implemented in rabe."
authors = [
"Schanzenbach, Martin <[email protected]>",
Expand Down
22 changes: 18 additions & 4 deletions rabe-console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ In order to compile and test:
- compile using `cargo build --release` and afterwards run executable `./target/release/rabe`

## Example calls using executable
- Setup a AC17 KP-ABE scheme
- Setup a AC17 CP-ABE scheme
* ```bash
$ rabe --s AC17CP setup
```
* This generates msk.key and pk.key
- Generate a new key with attributes "A" and "B"
- Generate a new key with **attributes** "A" and "B"
* ```bash
$ rabe --s AC17CP keygen --a 'A B'
```
$ rabe --s AC17CP keygen --a 'A and B'
```
* This generates a new key with **attributes** "A" and "B" and saves it to sk.key
- Encrypt a message with the HUMAN or JSON language **policy** "A" and "B"
* ```bash
$ rabe --s AC17CP --l HUMAN encrypt message.txt '"A" and "B"'
OR
rabe --s AC17CP --l JSON encrypt message.txt '{"name":"and","children":[{"name":"B"},{"name":"A"}]}'
```
* This generates a ciphertext and saves it to message.txt.ct

- Decrypt a ciphertext with sk.key
* ```bash
$ rabe --s AC17CP decrypt message.txt.ct
```
* This decrypts the ciphertext and saves it to message.txt
102 changes: 60 additions & 42 deletions rabe-console/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ fn main() {
arg_enum! {
#[derive(Debug)]
enum Lang {
Human,
Json,
HUMAN,
JSON,
}
}
// Default file names
Expand Down Expand Up @@ -331,6 +331,18 @@ fn main() {
.about(
"encrypts a file using attributes (kp-schemes) or a policy (cp-schemes).",
)
.arg(
Arg::with_name(FILE)
.required(true)
.takes_value(true)
.help("the file to encrypt."),
)
.arg(
Arg::with_name(POLICY)
.required(false)
.takes_value(true)
.help("the policy to use."),
)
.arg(
Arg::with_name(GP_FILE)
.required(false)
Expand All @@ -342,7 +354,7 @@ fn main() {
Arg::with_name(PK_FILE)
.required(false)
.takes_value(true)
.multiple(true)
//.multiple(true)
.default_value(&_pk_default)
.help("public key file(s)."),
)
Expand All @@ -352,24 +364,18 @@ fn main() {
.takes_value(true)
.multiple(true)
.help("the attribute(s) to use."),
)
.arg(
Arg::with_name(POLICY)
.required(false)
.takes_value(true)
.help("the policy to use."),
)
.arg(
Arg::with_name(FILE)
.required(true)
.takes_value(true)
.help("the file to encrypt."),
),
)
.subcommand(
// Decrypt
SubCommand::with_name(CMD_DECRYPT)
.about("decrypts a file using a key.")
.arg(
Arg::with_name(FILE)
.required(true)
.takes_value(true)
.help("file to use."),
)
.arg(
Arg::with_name(GP_FILE)
.required(false)
Expand All @@ -390,12 +396,6 @@ fn main() {
.takes_value(true)
.default_value(&_sk_default)
.help("user key file."),
)
.arg(
Arg::with_name(FILE)
.required(true)
.takes_value(true)
.help("file to use."),
),
)
.subcommand(
Expand Down Expand Up @@ -489,7 +489,7 @@ fn main() {
let mut _lang;
if let Some(_l) = argument_matches.value_of(LANG) {
_lang = match _l {
"json" => PolicyLanguage::JsonPolicy,
"JSON" => PolicyLanguage::JsonPolicy,
_ => PolicyLanguage::HumanPolicy,
};
} else {
Expand Down Expand Up @@ -1095,11 +1095,15 @@ fn main() {
Ok(parsed) => parsed,
Err(e) => return Err(e)
};
let _ct = ac17::cp_encrypt(&_pk, &_policy, &buffer, _lang);
write_file(
Path::new(&_ct_file),
ser_enc(_ct, CT_BEGIN, CT_END)
);
match ac17::cp_encrypt(&_pk, &_policy, &buffer, _lang){
Ok(_ct) => {
write_file(
Path::new(&_ct_file),
ser_enc(_ct, CT_BEGIN, CT_END)
);
},
Err(e) => return Err(e)
}
} else {
return Err(RabeError::new(
"sorry, encryption using the AC17CP Scheme with zero or multiple PKs is not possible. ",
Expand All @@ -1113,11 +1117,15 @@ fn main() {
Ok(parsed) => parsed,
Err(e) => return Err(e)
};
let _ct = ac17::kp_encrypt(&_pk, &_attributes, &buffer);
write_file(
Path::new(&_ct_file),
ser_enc(_ct, CT_BEGIN, CT_END)
);
match ac17::kp_encrypt(&_pk, &_attributes, &buffer) {
Ok(_ct) => {
write_file(
Path::new(&_ct_file),
ser_enc(_ct, CT_BEGIN, CT_END)
);
},
Err(e) => return Err(e)
}
} else {
return Err(RabeError::new(
"sorry, encryption using the AC17KP Scheme with zero or multiple PKs is not possible. ",
Expand Down Expand Up @@ -1226,11 +1234,15 @@ fn main() {
Ok(parsed) => parsed,
Err(e) => return Err(e)
};
let _ct = yct14::encrypt(&_pk, &_attributes, &buffer);
write_file(
Path::new(&_ct_file),
ser_enc(_ct, CT_BEGIN, CT_END)
);
match yct14::encrypt(&_pk, &_attributes, &buffer) {
Ok(_ct) => {
write_file(
Path::new(&_ct_file),
ser_enc(_ct, CT_BEGIN, CT_END)
);
},
Err(e) => return Err(e)
}
} else {
return Err(RabeError::new(
"sorry, encryption using the LSW Scheme with zero or multiple PKs is not possible. ",
Expand Down Expand Up @@ -1280,10 +1292,11 @@ fn main() {
None => {}
Some(x) => _file = x.to_string(),
}
match arguments.value_of(POLICY) {
None => {}
Some(x) => _policy = x.to_string(),
}
// never used
// match arguments.value_of(POLICY) {
// None => {}
// Some(x) => _policy = x.to_string(),
// }
match _scheme {
Scheme::AC17CP => {
let _sk: ac17::Ac17CpSecretKey = match ser_dec(&_sk_file) {
Expand Down Expand Up @@ -1391,7 +1404,12 @@ fn main() {
return Err(e);
}
Ok(_pt_u) => {
write_from_vec(Path::new(&_file), &_pt_u);
let mut out_file = _file.clone();
out_file.pop();
out_file.pop();
out_file.pop();

write_from_vec(Path::new(&out_file), &_pt_u);
}
}
Ok(())
Expand Down
Binary file removed src/.DS_Store
Binary file not shown.
10 changes: 8 additions & 2 deletions src/utils/policy/pest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ pub fn parse(
use utils::policy::pest::json::Rule;
match JSONPolicyParser::parse(Rule::content, policy) {
Ok(mut result) => Ok(json::parse(result.next().unwrap())),
Err(e) => Err(e.into())
Err(e) => {
println!("error Json Parse: {}", e);
Err(e.into())
}
}
},
PolicyLanguage::HumanPolicy => {
use utils::policy::pest::human::Rule;
match HumanPolicyParser::parse(Rule::content, policy) {
Ok(mut result) => Ok(human::parse(result.next().unwrap())),
Err(e) => Err(e.into())
Err(e) => {
println!("error Human Parse: {}", e);
Err(e.into())
}
}
}
}
Expand Down

0 comments on commit 718d2f8

Please sign in to comment.