Skip to content

Commit ed1f8bf

Browse files
Merge pull request #49 from sentclose/rec-keys
Rec keys
2 parents 5cfe488 + c2191e2 commit ed1f8bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+4641
-901
lines changed

Cargo.lock

+323-101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"implementation/dart/sentc_flutter_rust_light",
1212
"crypto_keys/crypto_std_keys",
1313
"crypto_keys/crypto_fips_keys",
14+
"crypto_keys/crypto_rec_keys",
1415
]
1516

1617
[workspace.package]
@@ -38,7 +39,6 @@ sentc-crypto-rec-keys = { version = "0.13.0", path = "crypto_keys/crypto_rec_key
3839
#key export
3940
# must use this version because it is not comp. with password_hash from argon2
4041
base64ct = { version = "1.0.1", default-features = false, features = ["alloc"] }
41-
pem-rfc7468 = { version = "0.3.1", features = ["alloc"] }
4242
serde = { version = "1.0.137", features = ["derive"] }
4343
serde_json = { version = "1.0.81", default-features = false, features = ["alloc"] }
4444

crypto/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ sentc-crypto-utils = { workspace = true, features = ["encryption"] }
2323
sentc-crypto-common = { workspace = true }
2424
sentc-crypto-std-keys = { workspace = true, features = ["full"], optional = true }
2525
sentc-crypto-fips-keys = { workspace = true, features = ["full"], optional = true }
26+
sentc-crypto-rec-keys = { workspace = true, features = ["full"], optional = true }
2627

2728
# key and data export
2829
base64ct.workspace = true
29-
pem-rfc7468.workspace = true
3030

3131
# json handling
3232
serde_json.workspace = true
@@ -38,6 +38,8 @@ std_keys = ["sentc-crypto-std-keys"]
3838

3939
fips_keys = ["sentc-crypto-fips-keys"]
4040

41+
rec_keys = ["sentc-crypto-rec-keys"]
42+
4143
server = []
4244
server_test = []
4345

crypto/src/crypto/crypto.rs

+17-36
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use base64ct::{Base64, Encoding};
66
use sentc_crypto_common::crypto::{EncryptedHead, GeneratedSymKeyHeadServerOutput};
77
use sentc_crypto_common::user::UserPublicKeyData;
88
use sentc_crypto_core::cryptomat::{CryptoAlg, SymKeyComposer, SymKeyGen};
9-
use sentc_crypto_utils::cryptomat::{PkFromUserKeyWrapper, PkWrapper, SkWrapper, SymKeyComposerWrapper, SymKeyGenWrapper, SymKeyWrapper};
9+
use sentc_crypto_utils::cryptomat::{PkFromUserKeyWrapper, SkWrapper, SymKeyComposerWrapper, SymKeyGenWrapper, SymKeyWrapper};
1010
use serde::{Deserialize, Serialize};
1111

1212
use crate::util::public::handle_server_response;
@@ -186,7 +186,7 @@ impl<SGen: SymKeyGenWrapper, SC: SymKeyComposerWrapper, P: PkFromUserKeyWrapper>
186186
{
187187
let public_key = P::from_user_key(reply_public_key)?;
188188

189-
let (encrypted_key, key) = SGen::KeyGen::generate_symmetric_with_public_key(public_key.get_key())?;
189+
let (encrypted_key, key) = SGen::KeyGen::generate_symmetric_with_public_key(&public_key)?;
190190

191191
let encrypted_key_string = Base64::encode_string(&encrypted_key);
192192

@@ -195,7 +195,7 @@ impl<SGen: SymKeyGenWrapper, SC: SymKeyComposerWrapper, P: PkFromUserKeyWrapper>
195195
let server_output = GeneratedSymKeyHeadServerOutput {
196196
alg: sym_key_format.get_key().get_alg_str().to_string(),
197197
encrypted_key_string,
198-
master_key_id: public_key.get_id().to_string(),
198+
master_key_id: reply_public_key.public_key_id.to_string(),
199199
key_id: "non_registered".to_string(),
200200
time: 0,
201201
};
@@ -209,20 +209,22 @@ mod test
209209
{
210210
use sentc_crypto_utils::cryptomat::{PkFromUserKeyWrapper, SkCryptoWrapper, SymKeyCrypto};
211211

212-
use crate::crypto::mimic_keys::FakeSignKeyWrapper;
213212
use crate::group::test_fn::create_group;
214213
use crate::user::test_fn::create_user;
215214

216215
#[cfg(feature = "std_keys")]
217216
pub type TestKeyGenerator = crate::keys::std::StdKeyGenerator;
218217
#[cfg(all(feature = "fips_keys", not(feature = "std_keys")))]
219218
pub type TestKeyGenerator = crate::keys::fips::FipsKeyGenerator;
219+
#[cfg(all(feature = "rec_keys", not(feature = "std_keys")))]
220+
pub type TestKeyGenerator = crate::keys::rec::RecKeyGenerator;
220221

221222
#[cfg(feature = "std_keys")]
222223
pub type TestPublicKey = sentc_crypto_std_keys::util::PublicKey;
223-
224224
#[cfg(all(feature = "fips_keys", not(feature = "std_keys")))]
225225
pub type TestPublicKey = sentc_crypto_fips_keys::util::PublicKey;
226+
#[cfg(all(feature = "rec_keys", not(feature = "std_keys")))]
227+
pub type TestPublicKey = sentc_crypto_rec_keys::util::PublicKey;
226228

227229
#[test]
228230
fn test_encrypt_decrypt_sym_raw()
@@ -235,9 +237,7 @@ mod test
235237
//now start encrypt and decrypt with the group master key
236238
let text = "123*+^êéèüöß@€&$";
237239

238-
let (head, encrypted) = group_key
239-
.encrypt_raw(text.as_bytes(), None::<&FakeSignKeyWrapper>)
240-
.unwrap();
240+
let (head, encrypted) = group_key.encrypt_raw(text.as_bytes(), None).unwrap();
241241

242242
let decrypted = group_key.decrypt_raw(&encrypted, &head, None).unwrap();
243243

@@ -280,7 +280,7 @@ mod test
280280
let payload = b"payload1234567891011121314151617";
281281

282282
let (head, encrypted) = group_key
283-
.encrypt_raw_with_aad(text.as_bytes(), payload, None::<&FakeSignKeyWrapper>)
283+
.encrypt_raw_with_aad(text.as_bytes(), payload, None)
284284
.unwrap();
285285

286286
let decrypted = group_key
@@ -325,12 +325,7 @@ mod test
325325
let text = "123*+^êéèüöß@€&$";
326326
let user = create_user();
327327

328-
let (head, encrypted) = TestPublicKey::encrypt_raw_with_user_key(
329-
&user.user_keys[0].exported_public_key,
330-
text.as_bytes(),
331-
None::<&FakeSignKeyWrapper>,
332-
)
333-
.unwrap();
328+
let (head, encrypted) = TestPublicKey::encrypt_raw_with_user_key(&user.user_keys[0].exported_public_key, text.as_bytes(), None).unwrap();
334329

335330
let decrypted = user.user_keys[0]
336331
.private_key
@@ -372,9 +367,7 @@ mod test
372367
//now start encrypt and decrypt with the group master key
373368
let text = "123*+^êéèüöß@€&$";
374369

375-
let encrypted = group_key
376-
.encrypt(text.as_bytes(), None::<&FakeSignKeyWrapper>)
377-
.unwrap();
370+
let encrypted = group_key.encrypt(text.as_bytes(), None).unwrap();
378371

379372
let decrypted = group_key.decrypt(&encrypted, None).unwrap();
380373

@@ -393,7 +386,7 @@ mod test
393386
let payload = b"payload1234567891011121314151617";
394387

395388
let encrypted = group_key
396-
.encrypt_with_aad(text.as_bytes(), payload, None::<&FakeSignKeyWrapper>)
389+
.encrypt_with_aad(text.as_bytes(), payload, None)
397390
.unwrap();
398391

399392
let decrypted = group_key
@@ -416,7 +409,7 @@ mod test
416409
let payload2 = b"payload1234567891011121314151618";
417410

418411
let encrypted = group_key
419-
.encrypt_with_aad(text.as_bytes(), payload, None::<&FakeSignKeyWrapper>)
412+
.encrypt_with_aad(text.as_bytes(), payload, None)
420413
.unwrap();
421414

422415
let decrypted = group_key.decrypt_with_aad(&encrypted, payload2, None);
@@ -457,12 +450,7 @@ mod test
457450
//now start encrypt and decrypt with the group master key
458451
let text = "123*+^êéèüöß@€&$";
459452

460-
let encrypted = TestPublicKey::encrypt_with_user_key(
461-
&user.user_keys[0].exported_public_key,
462-
text.as_bytes(),
463-
None::<&FakeSignKeyWrapper>,
464-
)
465-
.unwrap();
453+
let encrypted = TestPublicKey::encrypt_with_user_key(&user.user_keys[0].exported_public_key, text.as_bytes(), None).unwrap();
466454

467455
let decrypted = user.user_keys[0]
468456
.private_key
@@ -506,9 +494,7 @@ mod test
506494
//now start encrypt and decrypt with the group master key
507495
let text = "123*+^êéèüöß@€&$";
508496

509-
let encrypted = group_key
510-
.encrypt_string(text, None::<&FakeSignKeyWrapper>)
511-
.unwrap();
497+
let encrypted = group_key.encrypt_string(text, None).unwrap();
512498

513499
let decrypted = group_key.decrypt_string(&encrypted, None).unwrap();
514500

@@ -526,7 +512,7 @@ mod test
526512
let payload = "payload1234567891011121314151617";
527513

528514
let encrypted = group_key
529-
.encrypt_string_with_aad(text, payload, None::<&FakeSignKeyWrapper>)
515+
.encrypt_string_with_aad(text, payload, None)
530516
.unwrap();
531517

532518
let decrypted = group_key
@@ -566,12 +552,7 @@ mod test
566552
//now start encrypt and decrypt with the group master key
567553
let text = "123*+^êéèüöß@€&$";
568554

569-
let encrypted = TestPublicKey::encrypt_string_with_user_key(
570-
&user.user_keys[0].exported_public_key,
571-
text,
572-
None::<&FakeSignKeyWrapper>,
573-
)
574-
.unwrap();
555+
let encrypted = TestPublicKey::encrypt_string_with_user_key(&user.user_keys[0].exported_public_key, text, None).unwrap();
575556

576557
let decrypted = user.user_keys[0]
577558
.private_key

crypto/src/crypto/mimic_keys.rs

-105
This file was deleted.

crypto/src/crypto/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub(crate) mod crypto;
22
#[cfg(feature = "export")]
33
mod crypto_export;
4-
pub mod mimic_keys;
54

65
pub use self::crypto::KeyGenerator;
76
#[cfg(not(feature = "export"))]

crypto/src/crypto_sortable/crypto_sortable_export.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use crate::SdkError;
1010
pub fn encrypt_raw_number(key: &str, data: u64) -> Result<u64, String>
1111
{
1212
let key: SortableKey = key.parse()?;
13-
Ok(key.encrypt_sortable(data).map_err(Into::<SdkError>::into)?)
13+
Ok(key
14+
.get_key()
15+
.encrypt_sortable(data)
16+
.map_err(Into::<SdkError>::into)?)
1417
}
1518

1619
pub fn encrypt_number(key: &str, data: u64) -> Result<SortableEncryptOutput, String>

crypto/src/crypto_sortable/mod.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@ mod crypto_sortable_export;
44
#[cfg(feature = "export")]
55
pub use crypto_sortable_export::*;
66

7-
#[cfg(all(test, feature = "std_keys"))]
7+
#[cfg(all(test, any(feature = "std_keys", feature = "rec_keys")))]
88
mod test
99
{
1010
use core::str::FromStr;
1111

1212
use sentc_crypto_core::cryptomat::SortableKey as CoreSort;
13-
use sentc_crypto_std_keys::util::SortableKey;
1413
use sentc_crypto_utils::cryptomat::SortableKeyWrapper;
1514

1615
use crate::group::test_fn::create_group;
1716
use crate::user::test_fn::create_user;
1817

1918
extern crate std;
2019

20+
#[cfg(feature = "std_keys")]
21+
pub type TestKey = sentc_crypto_std_keys::util::SortableKey;
22+
#[cfg(all(feature = "rec_keys", not(feature = "std_keys")))]
23+
pub type TestKey = sentc_crypto_rec_keys::util::SortableKey;
24+
2125
#[test]
2226
fn test_simple()
2327
{
@@ -49,18 +53,21 @@ mod test
4953
{
5054
const KEY: &str = r#"{"Ope16":{"key":"5kGPKgLQKmuZeOWQyJ7vOg==","key_id":"1876b629-5795-471f-9704-0cac52eaf9a1"}}"#;
5155

52-
let a = SortableKey::from_str(KEY)
56+
let a = TestKey::from_str(KEY)
5357
.unwrap()
58+
.key
5459
.encrypt_sortable(262)
5560
.unwrap();
5661

57-
let b = SortableKey::from_str(KEY)
62+
let b = TestKey::from_str(KEY)
5863
.unwrap()
64+
.key
5965
.encrypt_sortable(263)
6066
.unwrap();
6167

62-
let c = SortableKey::from_str(KEY)
68+
let c = TestKey::from_str(KEY)
6369
.unwrap()
70+
.key
6471
.encrypt_sortable(65321)
6572
.unwrap();
6673

0 commit comments

Comments
 (0)