Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RheinSec (Network Key Storage) Pentest feedback implementation #18

Open
wants to merge 149 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
5e22bc2
Rhein_Sec NKS imported
May 13, 2024
ed1fd56
testfiles
May 13, 2024
214974f
changes to mod.rs's
May 13, 2024
a66ce84
updated gitignore
halrifai May 13, 2024
2f32b7b
added adress pub
May 13, 2024
ddf05d7
Upadated mod.rs, other changes
halrifai May 13, 2024
4bece45
Merge remote-tracking branch 'origin/main'
halrifai May 13, 2024
24eec44
added nks_token
halrifai May 13, 2024
c1ac32f
nksError fix
May 13, 2024
ece9cf6
added exiting methods, other changes
halrifai May 13, 2024
602edd8
added api and initialize_module
May 13, 2024
ba974d4
provider handle tests auf NksProvider angepasst.
May 13, 2024
6c2aaa4
added RSA encryption and signing
halrifai May 13, 2024
a074215
provider handle test fixes ->
May 14, 2024
e8e842a
provider handle test debug -> keine fehler mehr
May 14, 2024
7c379cf
key handle test debug -> ebenfalls keine fehler mehr
May 14, 2024
f146a17
load_key und create_key in nks hcvault provider implementiert
May 14, 2024
61c9b58
add current implementation of sign and verify
pl-CJump May 14, 2024
1af6768
Merge branch 'main' of https://github.com/halrifai/rust-crypto
pl-CJump May 14, 2024
d5627b2
fixed imports and other errors
halrifai May 15, 2024
56c1970
added errors, added ecc sodium crypto, deleted api.rs, fixed more log…
halrifai May 15, 2024
9864c01
minor changes
halrifai May 16, 2024
56e6f1b
minor changes 2
halrifai May 16, 2024
3534f2d
cfg in key_handle
pl-CJump May 16, 2024
76dd3b9
Merge branch 'main' of https://github.com/halrifai/rust-crypto
pl-CJump May 16, 2024
ad94b44
cfg in module_provider
pl-CJump May 16, 2024
f244c6e
fix delimiter in nks provider and delete unused modules in hcvault mod
pl-CJump May 16, 2024
a9358d1
minor changes 3
halrifai May 16, 2024
6a3f63b
fix some errors
pl-CJump May 16, 2024
8522a65
fix url address errors
pl-CJump May 16, 2024
747d216
comment out delete_secrets
pl-CJump May 16, 2024
979309b
comment out delete_secrets + fix url
pl-CJump May 16, 2024
1a8cf24
make empty impl of traits
pl-CJump May 16, 2024
f83b42a
fix tpm stuff in common key_handle
pl-CJump May 16, 2024
50d746b
change test_matrix to nks in common
pl-CJump May 16, 2024
7e9e4f7
implement initialize_module for nks
pl-CJump May 16, 2024
0658f06
comment out unimplemented tests and fix compilation errors
pl-CJump May 16, 2024
1722ca5
implement create_key for nks
pl-CJump May 16, 2024
4c2e2d8
delete unused nks_root_token
pl-CJump May 16, 2024
3dabf3a
Merge remote-tracking branch 'upstream/main'
pl-CJump May 20, 2024
4e8f148
fix cargo
pl-CJump May 20, 2024
cf0c947
Merge pull request #2 from halrifai/main
halrifai May 20, 2024
ca49e8d
fit provider parameters to trait declaration
pl-CJump May 20, 2024
95bdd26
fix compilation errors
pl-CJump May 20, 2024
caf7396
add getting secrets in initialize_module
pl-CJump May 20, 2024
6a2d2cc
changes to the nks_config, other
halrifai May 20, 2024
6960978
changes to the nksconfig, changes to do_nothing method
halrifai May 20, 2024
6a4a2ab
redo overwritten changes
pl-CJump May 20, 2024
b959531
use config in nks provider
pl-CJump May 20, 2024
e1f4005
working test method
halrifai May 20, 2024
360ea5e
use config in initialize and create_key
pl-CJump May 21, 2024
0c31c6b
initialize module w/o hardcode but access to config
pl-CJump May 22, 2024
35774db
add new_token as result of get_and_save_keypair
pl-CJump May 22, 2024
95287e0
test_create_edsa_key and ...ecdh_key
pl-CJump May 22, 2024
a9aa640
add private_key and public_key fields to NksProvider. First implement…
pl-CJump May 22, 2024
9052659
re-add token.json for persistance after end of runtime
pl-CJump May 22, 2024
d854fb4
better client side error handling for when key with id already exists
pl-CJump May 23, 2024
73ee014
reduce duplicate code in provider_handle_tests + impl test_load_ecdsa…
pl-CJump May 23, 2024
01c2940
documentation for provider and provider_handle_tests
pl-CJump May 23, 2024
b9a0fce
resolve warnings and typos in provider and provider_handle_tests
pl-CJump May 23, 2024
c14c56d
remove unused variables in provider
pl-CJump May 23, 2024
c9d99de
add match for ecdh in create_key
pl-CJump May 23, 2024
31ce0e5
remove some outputs used for testing
pl-CJump May 23, 2024
c40d8c1
Added SigningFailed error
schaefer99 May 23, 2024
6a279f1
Implemented Method sign_data, decrypt_data, encrypt_data, verify_sign…
schaefer99 May 23, 2024
bd56ef6
bracket placement
schaefer99 May 23, 2024
ac5cc41
added SigningFailed to Match
schaefer99 May 23, 2024
6a3d77a
added test an verify for rsa
schaefer99 May 23, 2024
2492741
refactored all methods
schaefer99 May 23, 2024
80960f7
refactored all methods
schaefer99 May 24, 2024
cce73cb
refactored test_sign_and_verify_rsa and added test_encrypt_and_decryp…
schaefer99 May 24, 2024
5ff4fd1
made get_config public
schaefer99 May 24, 2024
502e272
fixed return of decrypt and encrypt and error on verify signature
schaefer99 May 24, 2024
8879eb3
fixed matching error if no supported algorithm could be found
schaefer99 May 24, 2024
3607474
fixed matching error if no supported algorithm could be found
schaefer99 May 24, 2024
274f4d8
Fixed Sign and verify test.
schaefer99 May 26, 2024
7a8f25d
added static base64 decoded rsa keys to test funkction. added base64 …
schaefer99 May 26, 2024
ef3e67b
Fixed test with static base64 encoded keys in key_handle.rs
schaefer99 May 26, 2024
296819e
changed to port 5000, added https support, changed URLs
halrifai May 27, 2024
a81146f
removed unused lib
halrifai May 27, 2024
b7f4156
added some error handeling, segmented methods
halrifai May 27, 2024
884b915
added static ecc key to sign
schaefer99 May 27, 2024
5a0150f
added static ecc key to sign and verify
schaefer99 May 27, 2024
40ca6cf
added test for ecdsa sign
schaefer99 May 27, 2024
d30a8db
fixed RSA key decoding
halrifai May 27, 2024
31f0191
working rsa encrypt decrypt
halrifai May 27, 2024
a4eda35
fixed rsa encrypt decrypt test
schaefer99 May 27, 2024
137c963
Merge remote-tracking branch 'origin/main'
schaefer99 May 27, 2024
854e99c
fixed rsa encrypt decrypt test
schaefer99 May 27, 2024
aee2da1
add function add_signature_to_secrets
pl-CJump May 27, 2024
fe5a676
Merge branch 'main' of https://github.com/cep-sose2024/rheinsec_rust-…
pl-CJump May 27, 2024
c4cc4be
fixed logic errors, better encrypt decrypt
halrifai May 27, 2024
04dcc0d
functioning encrypt decrypt ecdh
halrifai May 27, 2024
2a0a325
sign and verify with dalek crate
pl-CJump May 27, 2024
2d9ef47
Merge branch 'main' of https://github.com/cep-sose2024/rheinsec_rust-…
pl-CJump May 27, 2024
eec22e3
remove key creation from signing test
pl-CJump May 27, 2024
79baff0
code clean up, added optional RSA key length
halrifai May 27, 2024
2157f38
match hash in sign and verify
pl-CJump May 27, 2024
7f0f72c
Merge branch 'main' of https://github.com/cep-sose2024/rheinsec_rust-…
pl-CJump May 27, 2024
5572734
Documentation - key_handle, mod.rs, provider.rs
May 28, 2024
413c61e
Documentation - traits - mod.rs
May 28, 2024
42049d9
remove unnecessary tests
pl-CJump May 28, 2024
0fa37cc
Add test instructions to README
pl-CJump May 29, 2024
00e0ec6
dokumentation
May 29, 2024
f31cd17
Warnings entfernt
Jun 3, 2024
002a06c
Error Warnings entfernt
Jun 3, 2024
e97ddeb
Added #[Instrument] to all important methods
schaefer99 Jun 3, 2024
8540754
Dokumentation Error.rs
Jun 3, 2024
103c95b
Merge branch 'main' of https://github.com/cep-sose2024/rheinsec_rust-…
Jun 3, 2024
a03197d
Cep sose2024 main (#10)
ngussek Jun 4, 2024
f206c50
Merge branch 'main' into main
halrifai Jun 4, 2024
eb914c1
updated the init module to include sym block chipers, removed some wa…
halrifai Jun 5, 2024
7d40594
inital AES support
halrifai Jun 5, 2024
51aa23d
add aes support to create_key
pl-CJump Jun 7, 2024
37c0de0
add test for aes key creation and aes aupport in get_config
pl-CJump Jun 7, 2024
211492a
fix aes impl in create_key
pl-CJump Jun 7, 2024
645d768
add test for loading aes key
pl-CJump Jun 7, 2024
0d73dbd
add test for aes encryption and decryption, first step to implementat…
pl-CJump Jun 7, 2024
00cd61a
aes gcm first working state with hardcoded nonce
pl-CJump Jun 8, 2024
b6cd776
aes gcm with random nonce
pl-CJump Jun 8, 2024
db8ac08
cleanup aes gcm
pl-CJump Jun 8, 2024
5e985ae
support for all sizes in aes gcm + tests
pl-CJump Jun 8, 2024
e18a32e
first try at aes ccm (fails to decrypt) + tests
pl-CJump Jun 8, 2024
266e693
aes ecb implementation + test
pl-CJump Jun 9, 2024
14bea73
aes cbc implementation + test
pl-CJump Jun 9, 2024
b57f3cc
aes ctr implementation + test
pl-CJump Jun 9, 2024
58e1483
aes cfb implementation + test
pl-CJump Jun 9, 2024
c7c602d
aes ofb implementation + test
pl-CJump Jun 9, 2024
85c38ca
change get_config to reduce duplicate code
pl-CJump Jun 9, 2024
eb6aa5d
restructure aes key_handle tests to reduce duplicate code
pl-CJump Jun 9, 2024
343c882
removed AES Ccm alg
halrifai Jun 10, 2024
bdff3c8
removed old code
halrifai Jun 10, 2024
ad242a6
Merge pull request #3 from cep-sose2024/aes_impl
pl-CJump Jun 10, 2024
e171dd5
Merge branch 'main' into main
pl-CJump Jun 11, 2024
a236541
Add downcast from Any to ProviderConfig
pl-CJump Jun 12, 2024
cd138ae
remove default feature
pl-CJump Jun 12, 2024
acc30fe
Add instruction for adding default feature to README
pl-CJump Jun 12, 2024
2a5fd8c
added code and documentation that allows the users to choose to NOT t…
halrifai Jun 15, 2024
a8dcfa1
changed README.md to add Concurrent Operations documentation
halrifai Jun 15, 2024
6611515
removed sodiumoxide, replaced it with crypto_box and rand_core, added…
halrifai Jun 15, 2024
4594925
Removed step to set default feature from README, added it to test com…
pl-CJump Jun 16, 2024
5076de3
Merge pull request #4 from cep-sose2024/pentest_feedback
pl-CJump Jun 16, 2024
b198e3b
Merge https://github.com/nmshd/rust-crypto.git into 'nmshd-main"
pl-CJump Jun 16, 2024
54b94e4
Merge branch 'nmshd-main'
pl-CJump Jun 16, 2024
7bc83d5
Merge remote-tracking branch 'upstream/main' into nmshd-main
pl-CJump Jun 16, 2024
35fcc5a
delete Cargo_old.lock
pl-CJump Jun 16, 2024
2eb892d
remove unnecessary path prefixes to reduce warnings
pl-CJump Jun 17, 2024
f50b87e
Merge pull request #6 from cep-sose2024/nmshd-main
pl-CJump Jun 17, 2024
3804760
updated readme to include the RheinSec GUI repo
halrifai Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
aes ofb implementation + test
  • Loading branch information
pl-CJump committed Jun 9, 2024
commit c7c602dfeedbdc3ae810484a614bbcf0a9f6e9b6
43 changes: 35 additions & 8 deletions src/nks/hcvault/key_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,22 @@ impl KeyHandle for NksProvider {
decrypted_data.truncate(count + rest);
Ok(decrypted_data)
}
// SymmetricMode::Ofb => {
// // AES OFB encryption
// // ...
// }
SymmetricMode::Ofb => {
let cipher = match length {
KeyBits::Bits128 => Cipher::aes_128_ofb(),
KeyBits::Bits192 => Cipher::aes_192_ofb(),
KeyBits::Bits256 => Cipher::aes_256_ofb(),
_ => return Err(SecurityModuleError::UnsupportedAlgorithm),
};
let key = openssl_base64::decode_block(&self.private_key).unwrap();
let (iv, encrypted_data) = _encrypted_data.split_at(cipher.iv_len().unwrap());
let mut crypter = Crypter::new(cipher, Mode::Decrypt, &key, Some(iv)).unwrap();
let mut decrypted_data = vec![0; encrypted_data.len() + cipher.block_size()];
let count = crypter.update(encrypted_data, &mut decrypted_data).unwrap();
let rest = crypter.finalize(&mut decrypted_data[count..]).unwrap();
decrypted_data.truncate(count + rest);
Ok(decrypted_data)
}
SymmetricMode::Ctr => {
let cipher = match length {
KeyBits::Bits128 => Cipher::aes_128_ctr(),
Expand Down Expand Up @@ -507,10 +519,25 @@ impl KeyHandle for NksProvider {
result.extend(encrypted_data);
Ok(result)
}
// SymmetricMode::Ofb => {
// // AES OFB encryption
// // ...
// }
SymmetricMode::Ofb => {
let cipher = match length {
KeyBits::Bits128 => Cipher::aes_128_ofb(),
KeyBits::Bits192 => Cipher::aes_192_ofb(),
KeyBits::Bits256 => Cipher::aes_256_ofb(),
_ => return Err(SecurityModuleError::UnsupportedAlgorithm),
};
let key = openssl_base64::decode_block(&self.private_key).unwrap();
let mut iv = vec![0; cipher.iv_len().unwrap()];
openssl::rand::rand_bytes(&mut iv).unwrap();
let mut crypter = Crypter::new(cipher, Mode::Encrypt, &key, Some(&iv)).unwrap();
let mut encrypted_data = vec![0; _data.len() + cipher.block_size()];
let count = crypter.update(_data, &mut encrypted_data).unwrap();
let rest = crypter.finalize(&mut encrypted_data[count..]).unwrap();
encrypted_data.truncate(count + rest);
let mut result = iv;
result.extend(encrypted_data);
Ok(result)
}
SymmetricMode::Ctr => {
let cipher = match length {
KeyBits::Bits128 => Cipher::aes_128_ctr(),
Expand Down
28 changes: 28 additions & 0 deletions src/tests/nks/key_handle_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,31 @@ fn test_encrypt_and_decrypt_aes_cfb() {
assert_eq!(data, decrypted_data.as_slice())
}
}

#[test]
fn test_encrypt_and_decrypt_aes_ofb() {
for &key_size in &[KeyBits::Bits128, KeyBits::Bits192, KeyBits::Bits256] {
let mut provider = NksProvider::new("aes_ofb".to_string());

provider.config = Some(crate::tests::nks::provider_handle_tests::get_config("aes_ofb", Some(key_size)).unwrap());

provider
.initialize_module()
.expect("Failed to initialize module");

if let Some(nks_config) = provider.config.as_ref().unwrap().as_any().downcast_ref::<NksConfig>() {
provider
.load_key(&format!("test_aes_ofb_key_{}", key_size as u8), Box::new(nks_config.clone()))
.expect("Failed to load AES key");
} else {
println!("Failed to downcast to NksConfig");
}

let data = b"Hello, World!";
let encrypted_data = provider.encrypt_data(data).expect("Failed to encrypt data");
let decrypted_data = provider
.decrypt_data(&encrypted_data)
.expect("Failed to decrypt data");
assert_eq!(data, decrypted_data.as_slice())
}
}
15 changes: 13 additions & 2 deletions src/tests/nks/provider_handle_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn test_create_ecdh_key() {
#[test]
fn test_create_aes_key() {
for &key_size in &[KeyBits::Bits128, KeyBits::Bits192, KeyBits::Bits256] {
for &aes_mode in &["aes_gcm", "aes_ccm", "aes_ecb", "aes_cbc", "aes_ctr", "aes_cfb"] {
for &aes_mode in &["aes_gcm", "aes_ccm", "aes_ecb", "aes_cbc", "aes_ctr", "aes_cfb", "aes_ofb"] {
let mut provider = NksProvider::new("test_key".to_string());

provider.config = Some(get_config(aes_mode, Some(key_size)).unwrap());
Expand Down Expand Up @@ -158,7 +158,7 @@ fn test_load_ecdh_key() {
#[test]
fn test_load_aes_key() {
for &key_size in &[KeyBits::Bits128, KeyBits::Bits192, KeyBits::Bits256] {
for &aes_mode in &["aes_gcm", "aes_ccm", "aes_ecb", "aes_cbc", "aes_ctr", "aes_cfb"] {
for &aes_mode in &["aes_gcm", "aes_ccm", "aes_ecb", "aes_cbc", "aes_ctr", "aes_cfb", "aes_ofb"] {
let mut provider = NksProvider::new("test_key".to_string());

provider.config = Some(get_config(aes_mode, Some(key_size)).unwrap());
Expand Down Expand Up @@ -294,6 +294,17 @@ pub fn get_config(key_type: &str, key_size: Option<KeyBits>) -> Option<Arc<dyn P
Some(BlockCiphers::Aes(SymmetricMode::Cfb, key_size)),
))
},
"aes_ofb" => {
let key_size = key_size.unwrap_or(KeyBits::Bits256); // Default to 256 bits if no size is provided
Some(NksConfig::new(
"".to_string(),
"https://localhost:5000/".to_string(),
None,
Hash::Sha2(256.into()),
vec![KeyUsage::Decrypt],
Some(BlockCiphers::Aes(SymmetricMode::Cfb, key_size)),
))
},
_ => None,
}
}