-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add mismatched filter option * Bump version * Update README sample output * More soft changes * Add recommended feature flag * Add .envrc
- Loading branch information
Showing
8 changed files
with
131 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
Cargo.lock | ||
.direnv | ||
.envrc | ||
target | ||
test.txt | ||
matching-edeks.txt | ||
|
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[package] | ||
name = "search-edeks" | ||
version = "1.1.0" | ||
version = "1.2.0" | ||
authors = ["IronCore Labs <[email protected]>"] | ||
categories = ["utilities"] | ||
description = "Tool to search EDEK's protobuf. Can be used to find EDEKs that need to be rekeyed from an old KMS config ID." | ||
description = "Tool to search IronCoreLabs Tenant Security Proxy EDEK's protobuf." | ||
edition = "2021" | ||
license = "AGPL-3.0-only" | ||
readme = "README.md" | ||
|
@@ -13,9 +13,14 @@ repository = "https://github.com/IronCoreLabs/search-edeks" | |
[dependencies] | ||
base64 = "~0.21" | ||
bytes = "1.4.0" | ||
clap = { version = "~3", features = ["cargo", "derive", "suggestions"] } | ||
clap = { version = "~4", features = [ | ||
"cargo", | ||
"derive", | ||
"suggestions", | ||
"wrap_help", | ||
] } | ||
hex = "0.4.3" | ||
protobuf = {version = "3.2", features = ["with-bytes"]} | ||
protobuf = { version = "3.2", features = ["with-bytes"] } | ||
ron = "0.8.0" | ||
serde = { version = "~1.0", features = ["derive"] } | ||
|
||
|
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 |
---|---|---|
|
@@ -16,28 +16,26 @@ Check out this repo and run `cargo b --release`. The binary will be at `target/r | |
|
||
```console | ||
search-edeks --help | ||
search-edeks 1.1.0 | ||
IronCore Labs <[email protected]> | ||
Tool to search EDEK's protobuf. Can be used to find EDEKs that need to be rekeyed from an old KMS | ||
config ID. | ||
|
||
USAGE: | ||
search-edeks [OPTIONS] --id <VALUE> --file <FILE> <--hex|--base64> | ||
|
||
OPTIONS: | ||
-b, --base64 Consume and output base64 formatted EDEKs | ||
-d, --debug Print extra debug information | ||
-f, --file <FILE> File with one `("identifier", "EDEK")` per line | ||
-h, --hex Consume and output hex formatted EDEKs | ||
--help Print help information | ||
-i, --id <VALUE> Sets the KMS config ID we're searching for | ||
-v, --verbose Output identifier and original EDEK (and error message if applicable). If | ||
not enabled, only identifiers will be output | ||
-V, --version Print version information | ||
Tool to search IronCoreLabs Tenant Security Proxy EDEK's protobuf. | ||
|
||
Usage: search-edeks [OPTIONS] --file <FILE> <--id <VALUE>|--mismatched> <--hex|--base64> | ||
|
||
Options: | ||
-i, --id <VALUE> Sets the KMS config ID we're searching for | ||
-m, --mismatched Searches for mismatches between the KMS config ID in the EDEK header and the leased key used to encrypt the EDEK. Resulting EDEKs must be rekeyed with TSP 4.11.1+ to repair. | ||
-f, --file <FILE> File with one `("identifier", "EDEK")` per line | ||
-h, --hex Consume and output hex formatted EDEKs | ||
-b, --base64 Consume and output base64 formatted EDEKs | ||
-d, --debug Print extra debug information | ||
-v, --verbose Output identifier and original EDEK (and error message if applicable). If not enabled, only identifiers will be output | ||
-h, --help Print help | ||
-V, --version Print version | ||
``` | ||
|
||
For example `search-edeks --file edeks.txt --id 1201 --hex` would search `edeks.txt` for any EDEKs that were created using KMS config ID `1201`. It would output `matching-edeks.txt` with the one identifier per line for each EDEK that matched. It would output `broken-edeks.txt` with one identifier per line for each EDEK that wasn't parsable as an EDEK. If `--verbose` was enabled, the output would be tuples of the required input form (with the broken EDEKs additonally containing an error message). | ||
|
||
If multiple search filters are included, all must be present for an EDEK to match. | ||
|
||
## Releasing | ||
|
||
* update the version in Cargo.toml according to semver before tagging for release | ||
|
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,30 @@ | ||
use crate::{proto::transform::EncryptedDek, util::edek_from_bytes}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub(crate) enum Filter { | ||
ConfigId(i32), | ||
Mismatched, | ||
} | ||
|
||
fn execute_config_id_filter( | ||
parsed_edek: &EncryptedDek, | ||
config_id_to_match: i32, | ||
) -> Result<bool, String> { | ||
Ok(parsed_edek.kmsConfigId == config_id_to_match) | ||
} | ||
fn execute_mismatched_filter(parsed_edek: &EncryptedDek) -> Result<bool, String> { | ||
if !parsed_edek.encryptedLeasedKeyData.is_empty() { | ||
match edek_from_bytes(&parsed_edek.encryptedLeasedKeyData) { | ||
Ok(lk_edek) => Ok(lk_edek.kmsConfigId != parsed_edek.kmsConfigId), | ||
Err(e) => Err(format!("Failed to parse leased key: {e}")), | ||
} | ||
} else { | ||
Ok(false) | ||
} | ||
} | ||
pub(crate) fn execute_filter(filter: &Filter, parsed_edek: &EncryptedDek) -> Result<bool, String> { | ||
match filter { | ||
Filter::ConfigId(config_id) => execute_config_id_filter(parsed_edek, *config_id), | ||
Filter::Mismatched => execute_mismatched_filter(parsed_edek), | ||
} | ||
} |
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