Skip to content

Commit

Permalink
Remove cbor_serialize_message helper
Browse files Browse the repository at this point in the history
The cbor_serialize_message helper mixed re-exports of cbor-smol from
trussed and ctap-types.  This can be problematic if both select
different versions.  It could be fixed by keeping both in sync, but to
avoid this problem entirely, we can also just use cbor_serialize_bytes
from Trussed directly.
  • Loading branch information
robin-nitrokey committed Oct 24, 2024
1 parent 28e0b05 commit b931a48
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/ctap2/pin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{cbor_serialize_message, TrussedRequirements};
use crate::TrussedRequirements;
use cosey::EcdhEsHkdf256PublicKey;
use ctap_types::{ctap2::client_pin::Permissions, Error, Result};
use trussed::{
cbor_deserialize,
cbor_deserialize, cbor_serialize_bytes,
client::{CryptoClient, HmacSha256, P256},
syscall, try_syscall,
types::{
Expand Down Expand Up @@ -312,7 +312,7 @@ impl<'a, T: TrussedRequirements> PinProtocol<'a, T> {
}

fn shared_secret_impl(&mut self, peer_key: &EcdhEsHkdf256PublicKey) -> Option<SharedSecret> {
let serialized_peer_key = cbor_serialize_message(peer_key).ok()?;
let serialized_peer_key: Message = cbor_serialize_bytes(peer_key).ok()?;
let peer_key = try_syscall!(self.trussed.deserialize_p256_key(
&serialized_peer_key,
KeySerialization::EcdhEsHkdf256,
Expand Down
12 changes: 1 addition & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ generate_macros!();

use core::time::Duration;

use trussed::{
client, syscall,
types::{Location, Message},
Client as TrussedClient,
};
use trussed::{client, syscall, types::Location, Client as TrussedClient};
use trussed_fs_info::{FsInfoClient, FsInfoReply};
use trussed_hkdf::HkdfClient;

Expand Down Expand Up @@ -252,12 +248,6 @@ impl UserPresence for Conforming {
}
}

fn cbor_serialize_message<T: serde::Serialize>(
object: &T,
) -> core::result::Result<Message, ctap_types::serde::Error> {
trussed::cbor_serialize_bytes(object)
}

impl<UP, T> Authenticator<UP, T>
where
UP: UserPresence,
Expand Down
4 changes: 2 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ctap_types::{
String,
};
use trussed::{
client, syscall, try_syscall,
cbor_serialize_bytes, client, syscall, try_syscall,
types::{KeyId, Location, Mechanism, PathBuf},
Client as TrussedClient,
};
Expand Down Expand Up @@ -298,7 +298,7 @@ impl PersistentState {
}

pub fn save<T: TrussedClient>(&self, trussed: &mut T) -> Result<()> {
let data = crate::cbor_serialize_message(self).unwrap();
let data = cbor_serialize_bytes(self).unwrap();

syscall!(trussed.write_file(
Location::Internal,
Expand Down

0 comments on commit b931a48

Please sign in to comment.