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

Use trussed_core::types::EncryptedData #43

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ trussed.workspace = true

se05x = { version = "0.1.5", features = ["serde", "builder"] }
trussed-auth = "0.3.0"
trussed-core = "0.1"
trussed-manage = "0.1.0"
trussed-se050-manage = "0.1.0"
trussed-wrap-key-to-file = "0.1.0"
Expand Down Expand Up @@ -58,7 +59,8 @@ serde_test = "1.0.176"

[patch.crates-io]
ctaphid-dispatch = { git = "https://github.com/trussed-dev/ctaphid-dispatch.git", rev = "57cb3317878a8593847595319aa03ef17c29ec5b" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "046478b7a4f6e2315acf9112d98308379c2e3eee" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "eadd27cda0f457caae609e7fa972277e46695bd3" }
trussed-core = { git = "https://github.com/trussed-dev/trussed.git", rev = "eadd27cda0f457caae609e7fa972277e46695bd3" }
trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth.git", rev = "c030b82ad3441f337af09afe3a69e8a6da5785ea" }
trussed-manage = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "manage-v0.1.0" }
trussed-rsa-alloc = { git = "https://github.com/trussed-dev/trussed-rsa-backend.git", tag = "v0.2.1" }
Expand Down
30 changes: 11 additions & 19 deletions src/core_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use trussed::{
types::{CoreContext, KeyId, KeySerialization, Location, Mechanism, Message},
Bytes, Error,
};
use trussed_core::types::EncryptedData;
use trussed_rsa_alloc::{RsaImportFormat, RsaPublicParts};

use crate::{
Expand Down Expand Up @@ -89,7 +90,7 @@ pub(crate) enum WrappedKeyType {
/// If this is a raw wrapped key, `is_se050` is not included and therefore deserializes to `false`
#[derive(Serialize, Deserialize, Debug, Clone)]
struct WrappedKeyData {
encrypted_data: reply::Encrypt,
encrypted_data: EncryptedData,
ty: WrappedKeyType,
}

Expand Down Expand Up @@ -2629,7 +2630,8 @@ impl<Twi: I2CForT1, D: DelayUs<u32>> Se050Backend<Twi, D> {
<trussed::mechanisms::Chacha8Poly1305 as trussed::service::Encrypt>::encrypt(
core_keystore,
&encryption_request,
)?;
)?
.into();

let mut wrapped_key: Bytes<1024> = postcard::to_vec(&WrappedKeyData { encrypted_data, ty })
.map_err(|_| Error::CborError)?
Expand Down Expand Up @@ -2749,24 +2751,14 @@ impl<Twi: I2CForT1, D: DelayUs<u32>> Se050Backend<Twi, D> {
return Err(Error::FunctionNotSupported);
}

let WrappedKeyData {
encrypted_data:
reply::Encrypt {
ciphertext,
nonce,
tag,
},
ty,
} = postcard::from_bytes(&req.wrapped_key[1..]).map_err(|_| Error::CborError)?;
let WrappedKeyData { encrypted_data, ty } =
postcard::from_bytes(&req.wrapped_key[1..]).map_err(|_| Error::CborError)?;

let decryption_request = request::Decrypt {
mechanism: Mechanism::Chacha8Poly1305,
key: req.wrapping_key,
message: ciphertext,
associated_data: req.associated_data.clone(),
nonce,
tag,
};
let decryption_request = encrypted_data.decrypt(
Mechanism::Chacha8Poly1305,
req.wrapping_key,
req.associated_data.clone(),
);

let decryption_result =
<trussed::mechanisms::Chacha8Poly1305 as trussed::service::Decrypt>::decrypt(
Expand Down
Loading