Use published libraries only. Add CI

This commit is contained in:
Nicolas Stalder
2021-01-31 16:32:33 +01:00
parent 0a463c6a27
commit 8ec47f0fcd
19 changed files with 172 additions and 106 deletions
+29
View File
@@ -0,0 +1,29 @@
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install build dependencies
run: >
sudo apt-get update -y -qq &&
sudo apt-get install -y -qq llvm libc6-dev-i386 libclang-dev
- uses: fiam/arm-none-eabi-gcc@v1
with:
release: "9-2020-q2"
- name: Build
run: cargo build --verbose --features clients-1
- name: Run tests
run: cargo test --verbose --features clients-12
- name: Build Documentation
run: cargo doc --no-deps --features clients-1
- name: Deploy Docs
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
+3
View File
@@ -1 +1,4 @@
/target
Cargo.lock
**/*.bin
/pkcs11v3
+18 -34
View File
@@ -16,49 +16,32 @@ block-modes = { version = "0.3.3", default-features = false }
block-cipher-trait = { version = "0.6.2" }
chacha20 = { version = "0.3.4", features = ["rng"] }
chacha20poly1305 = { version = "0.3.3", default-features = false, features = ["heapless", "reduced-round"] }
cosey = "0.1.0"
delog = "0.1.0-alpha.3"
rand_core = "0.5.1"
# ctapcbor = { git = "https://github.com/nickray/ctapcbor", branch = "main" }
# TODO: Currently, only depend on this for cose::P256PublicKey
# --> would be good to remove dependency
# OTOH, ctapcbor is in ctap_types too, and we use it a lot
# --> so maybe split CBOR + COSE out of ctap-types?
ctap-types = { path = "../ctap-types" }
cbor-smol = "0.1.0"
des = { version = "0.3.0", optional = true }
embedded-hal = { version = "0.2.3", features = ["unproven"] }
generic-array = "0.12.3" # "0.13.2"
# generic-array = "0.13.2"
# generic-array = { version = "0.13.2", default-features = false }
heapless = "0.5.5"
heapless = { version = "0.5.6", features = ["serde"] }
# heapless = { git = "https://github.com/nickray/heapless", branch = "heapless-14" }
heapless-bytes = { version = "0.1.0", features = ["cbor"] }
hmac = "0.7.1"
interchange = { path = "../interchange" }
interchange = "0.1.0"
littlefs2 = "0.1.0"
nb = "1"
serde = { version = "1.0", default-features = false }
serde_cbor = { version = "0.11.0", default-features = false }
serde-indexed = "0.0.4"
serde-indexed = "0.1.0"
sha-1 = { version = "0.8.2", default-features = false, optional = true }
sha2 = { version = "0.8.0", default-features = false }
delog = "0.1.0-alpha.3"
[dependencies.heapless-bytes]
# version = "0.1.0"
# path = "../../../heapless-bytes"
git = "https://github.com/ycrypto/heapless-bytes"
branch = "main"
[dependencies.littlefs2]
# path = "../../../littlefs2"
git = "https://github.com/nickray/littlefs2"
branch = "closures-instead-of-ub"
# git = "https://github.com/nickray/littlefs2"
# branch = "main"
[dependencies.nisty]
version = "0.1.0-alpha.2"
version = "0.1.0-alpha.3"
features = ["asn1-der", "cose"]
# path = "../../../nisty"
# git = "https://github.com/ycrypto/nisty"
# branch = "main"
[dependencies.salty]
git = "https://github.com/ycrypto/salty"
@@ -105,9 +88,10 @@ clients-2 = []
clients-3 = []
clients-4 = []
clients-5 = []
[patch.crates-io]
heapless = { git = "https://github.com/nicolas-solokeys/heapless", branch = "bytebuf" }
# MacOS needed patches
nisty = {git = "https://github.com/ycrypto/nisty", branch="main"}
clients-6 = []
clients-7 = []
clients-8 = []
clients-9 = []
clients-10 = []
clients-11 = []
clients-12 = []
+1 -1
View File
@@ -2,5 +2,5 @@
# Running tests
```bash
cargo test --features logging/std,clients-1 --target $(rustc -Vv | awk 'NR==5{print $2}')
cargo test --features clients-12
```
+15 -15
View File
@@ -202,7 +202,7 @@ pub trait Client {
fn hash_sha256<'c>(&'c mut self, message: &[u8])
-> ClientResult<'c, reply::Hash, Self>
{
self.hash(Mechanism::Sha256, Message::from_slice(message).map_err(|_| ClientError::DataTooLarge)?)
self.hash(Mechanism::Sha256, Message::try_from_slice(message).map_err(|_| ClientError::DataTooLarge)?)
}
fn decrypt_chacha8poly1305<'c>(&'c mut self, key: &ObjectHandle, message: &[u8], associated_data: &[u8],
@@ -225,7 +225,7 @@ pub trait Client {
-> ClientResult<'c, reply::Encrypt, Self>
{
self.encrypt(Mechanism::Chacha8Poly1305, key.clone(), message, associated_data,
nonce.and_then(|nonce| ShortData::from_slice(nonce).ok()))
nonce.and_then(|nonce| ShortData::try_from_slice(nonce).ok()))
}
fn decrypt_tdes<'c>(&'c mut self, key: &ObjectHandle, message: &[u8])
@@ -553,8 +553,8 @@ where S: Syscall {
message: &[u8], associated_data: &[u8], nonce: Option<ShortData>)
-> ClientResult<'c, reply::Encrypt, Self>
{
let message = Message::from_slice(message).map_err(|_| ClientError::DataTooLarge)?;
let associated_data = ShortData::from_slice(associated_data).map_err(|_| ClientError::DataTooLarge)?;
let message = Message::try_from_slice(message).map_err(|_| ClientError::DataTooLarge)?;
let associated_data = ShortData::try_from_slice(associated_data).map_err(|_| ClientError::DataTooLarge)?;
let r = self.request(request::Encrypt { mechanism, key, message, associated_data, nonce })?;
r.client.syscall.syscall();
Ok(r)
@@ -572,10 +572,10 @@ where S: Syscall {
)
-> ClientResult<'c, reply::Decrypt, Self>
{
let message = Message::from_slice(message).map_err(|_| ClientError::DataTooLarge)?;
let associated_data = Message::from_slice(associated_data).map_err(|_| ClientError::DataTooLarge)?;
let nonce = ShortData::from_slice(nonce).map_err(|_| ClientError::DataTooLarge)?;
let tag = ShortData::from_slice(tag).map_err(|_| ClientError::DataTooLarge)?;
let message = Message::try_from_slice(message).map_err(|_| ClientError::DataTooLarge)?;
let associated_data = Message::try_from_slice(associated_data).map_err(|_| ClientError::DataTooLarge)?;
let nonce = ShortData::try_from_slice(nonce).map_err(|_| ClientError::DataTooLarge)?;
let tag = ShortData::try_from_slice(tag).map_err(|_| ClientError::DataTooLarge)?;
let r = self.request(request::Decrypt { mechanism, key, message, associated_data, nonce, tag })?;
r.client.syscall.syscall();
Ok(r)
@@ -772,7 +772,7 @@ where S: Syscall {
let r = self.request(request::Sign {
key,
mechanism,
message: ByteBuf::from_slice(data).map_err(|_| ClientError::DataTooLarge)?,
message: ByteBuf::try_from_slice(data).map_err(|_| ClientError::DataTooLarge)?,
format,
})?;
r.client.syscall.syscall();
@@ -792,8 +792,8 @@ where S: Syscall {
let r = self.request(request::Verify {
mechanism,
key,
message: Message::from_slice(&message).expect("all good"),
signature: Signature::from_slice(&signature).expect("all good"),
message: Message::try_from_slice(&message).expect("all good"),
signature: Signature::try_from_slice(&signature).expect("all good"),
format,
})?;
r.client.syscall.syscall();
@@ -824,7 +824,7 @@ where S: Syscall {
info_now!("{}B: raw key: {:X?}", raw_key.len(), raw_key);
let r = self.request(request::UnsafeInjectKey {
mechanism: Mechanism::Totp,
raw_key: ShortData::from_slice(raw_key).unwrap(),
raw_key: ShortData::try_from_slice(raw_key).unwrap(),
attributes: StorageAttributes::new().set_persistence(persistence),
})?;
r.client.syscall.syscall();
@@ -836,7 +836,7 @@ where S: Syscall {
{
let r = self.request(request::UnsafeInjectKey {
mechanism: Mechanism::Tdes,
raw_key: ShortData::from_slice(raw_key).unwrap(),
raw_key: ShortData::try_from_slice(raw_key).unwrap(),
attributes: StorageAttributes::new().set_persistence(persistence),
})?;
r.client.syscall.syscall();
@@ -851,7 +851,7 @@ where S: Syscall {
associated_data: &[u8], attributes: StorageAttributes)
-> ClientResult<'c, reply::UnwrapKey, Self>
{
let associated_data = Message::from_slice(associated_data).map_err(|_| ClientError::DataTooLarge)?;
let associated_data = Message::try_from_slice(associated_data).map_err(|_| ClientError::DataTooLarge)?;
let r = self.request(request::UnwrapKey { mechanism, wrapping_key, wrapped_key, associated_data, attributes })?;
r.client.syscall.syscall();
Ok(r)
@@ -865,7 +865,7 @@ where S: Syscall {
associated_data: &[u8])
-> ClientResult<'c, reply::WrapKey, Self>
{
let associated_data = Message::from_slice(associated_data).map_err(|_| ClientError::DataTooLarge)?;
let associated_data = Message::try_from_slice(associated_data).map_err(|_| ClientError::DataTooLarge)?;
let r = self.request(request::WrapKey { mechanism, wrapping_key, key, associated_data })?;
r.client.syscall.syscall();
Ok(r)
+18 -4
View File
@@ -11,6 +11,22 @@
extern crate delog;
generate_macros!();
#[cfg(not(any(
feature = "clients-1",
feature = "clients-2",
feature = "clients-3",
feature = "clients-4",
feature = "clients-5",
feature = "clients-6",
feature = "clients-7",
feature = "clients-8",
feature = "clients-9",
feature = "clients-10",
feature = "clients-11",
feature = "clients-12",
)))]
compile_error!("Please select how many Trussed™ clients will be needed, using one of the `clients-*` features.");
pub use interchange::Interchange;
pub mod api;
@@ -29,10 +45,8 @@ pub use error::Error;
pub use client::{Client, ClientImplementation};
pub use service::Service;
pub use ctap_types::{
ArrayLength, ByteBuf, consts,
serde::{cbor_serialize, cbor_serialize_bytes, cbor_serialize_bytebuf, cbor_deserialize},
};
pub use cbor_smol::{cbor_serialize, cbor_serialize_bytes, cbor_serialize_bytebuf, cbor_deserialize};
pub use heapless_bytes::{ArrayLength, Bytes as ByteBuf, consts};
#[cfg(test)]
mod tests;
+6 -6
View File
@@ -28,7 +28,7 @@ impl<B: Board> Encrypt<B> for super::Aes256Cbc
let symmetric_key: [u8; 32] = resources
.load_key(KeyType::Secret, None, &key_id)?
.value.as_slice().try_into()
.value.as_ref().try_into()
.map_err(|_| Error::InternalError)?;
let zero_iv = [0u8; 16];
@@ -47,7 +47,7 @@ impl<B: Board> Encrypt<B> for super::Aes256Cbc
// The padding space should be big enough for padding, otherwise method will return Err(BlockModeError).
let ciphertext = cipher.encrypt(&mut buffer, l).unwrap();
let ciphertext = Message::from_slice(&ciphertext).unwrap();
let ciphertext = Message::try_from_slice(&ciphertext).unwrap();
Ok(reply::Encrypt { ciphertext, nonce: ShortData::new(), tag: ShortData::new() })
}
}
@@ -64,9 +64,9 @@ impl<B: Board> WrapKey<B> for super::Aes256Cbc
// let message: Message = serialized_key.value.try_to_byte_buf().map_err(|_| Error::InternalError)?;
let message: Message = resources
let message: Message = crate::ByteBuf::try_from_slice(resources
.load_key(KeyType::Secret, None, &request.key.object_id)?
.value.try_to_byte_buf().map_err(|_| Error::InternalError)?;
.value.as_ref()).map_err(|_| Error::InternalError)?;
let encryption_request = request::Encrypt {
mechanism: Mechanism::Aes256Cbc,
@@ -100,7 +100,7 @@ impl<B: Board> Decrypt<B> for super::Aes256Cbc
let key_id = request.key.object_id;
let symmetric_key: [u8; 32] = resources
.load_key(KeyType::Secret, None, &key_id)?
.value.as_slice()
.value.as_ref()
.try_into()
.map_err(|_| Error::InternalError)?;
@@ -121,7 +121,7 @@ impl<B: Board> Decrypt<B> for super::Aes256Cbc
// hprintln!("symmetric key: {:?}", &symmetric_key).ok();
let plaintext = cipher.decrypt(&mut buffer).unwrap();
// hprintln!("decrypted: {:?}", &plaintext).ok();
let plaintext = Message::from_slice(&plaintext).unwrap();
let plaintext = Message::try_from_slice(&plaintext).unwrap();
Ok(reply::Decrypt { plaintext: Some(plaintext) })
}
+7 -7
View File
@@ -65,7 +65,7 @@ Decrypt<B> for super::Chacha8Poly1305
let serialized_value = resources
.load_key(KeyType::Secret, Some(KeyKind::Symmetric32Nonce12), &request.key.object_id)?
.value;
let serialized = serialized_value.as_slice();
let serialized = serialized_value.as_ref();
// if serialized.len() != 44 {
// return Error::InternalError;
@@ -113,7 +113,7 @@ Encrypt<B> for super::Chacha8Poly1305
let mut serialized_value = resources
.load_key(key_type, Some(key_kind), key_id)?
.value;
let serialized = serialized_value.as_mut_slice();
let serialized = serialized_value.as_mut();
assert!(serialized.len() == 44);
@@ -153,10 +153,10 @@ Encrypt<B> for super::Chacha8Poly1305
&mut ciphertext,
).unwrap().as_slice().try_into().unwrap();
let nonce = ShortData::from_slice(nonce).unwrap();
let tag = ShortData::from_slice(&tag).unwrap();
let nonce = ShortData::try_from_slice(nonce).unwrap();
let tag = ShortData::try_from_slice(&tag).unwrap();
// let ciphertext = Message::from_slice(&ciphertext).unwrap();
// let ciphertext = Message::try_from_slice(&ciphertext).unwrap();
Ok(reply::Encrypt { ciphertext, nonce, tag })
}
}
@@ -303,7 +303,7 @@ UnwrapKey<B> for super::Chacha8Poly1305
// // Returns an error if buffer length is not multiple of block size and
// // if after decoding message has malformed padding.
// let plaintext = cipher.decrypt(&mut buffer).unwrap();
// let plaintext = Message::from_slice(&plaintext).unwrap();
// let plaintext = Message::try_from_slice(&plaintext).unwrap();
// Ok(reply::Decrypt { plaintext: Ok(plaintext) })
// }
@@ -352,7 +352,7 @@ UnwrapKey<B> for super::Chacha8Poly1305
// // // The padding space should be big enough for padding, otherwise method will return Err(BlockModeError).
// // let ciphertext = cipher.encrypt(&mut buffer, l).unwrap();
// // let ciphertext = Message::from_slice(&ciphertext).unwrap();
// // let ciphertext = Message::try_from_slice(&ciphertext).unwrap();
// Ok(reply::Encrypt { ciphertext })
// }
// }
+7 -7
View File
@@ -12,7 +12,7 @@ fn load_public_key<B: Board>(resources: &mut ServiceResources<B>, key_id: &Uniqu
let public_bytes: [u8; 32] = resources
.load_key(KeyType::Public, Some(KeyKind::Ed25519), &key_id)?
.value.as_slice()
.value.as_ref()
.try_into()
.map_err(|_| Error::InternalError)?;
@@ -26,7 +26,7 @@ fn load_keypair<B: Board>(resources: &mut ServiceResources<B>, key_id: &UniqueId
let seed: [u8; 32] = resources
.load_key(KeyType::Secret, Some(KeyKind::Ed25519), &key_id)?
.value.as_slice()
.value.as_ref()
.try_into()
.map_err(|_| Error::InternalError)?;
@@ -128,10 +128,10 @@ SerializeKey<B> for super::Ed25519
let mut serialized_key = Message::new();
match request.format {
KeySerialization::Cose => {
let cose_pk = ctap_types::cose::Ed25519PublicKey {
// x: ByteBuf::from_slice(public_key.x_coordinate()).unwrap(),
// x: ByteBuf::from_slice(&buf).unwrap(),
x: ByteBuf::from_slice(public_key.as_bytes()).unwrap(),
let cose_pk =cosey::Ed25519PublicKey {
// x: ByteBuf::try_from_slice(public_key.x_coordinate()).unwrap(),
// x: ByteBuf::try_from_slice(&buf).unwrap(),
x: ByteBuf::try_from_slice(public_key.as_bytes()).unwrap(),
};
crate::cbor_serialize_bytes(&cose_pk, &mut serialized_key).map_err(|_| Error::CborError)?;
}
@@ -184,7 +184,7 @@ Sign<B> for super::Ed25519
let keypair = load_keypair(resources, &key_id)?;
let native_signature = keypair.sign(&request.message);
let our_signature = Signature::from_slice(&native_signature.to_bytes()).unwrap();
let our_signature = Signature::try_from_slice(&native_signature.to_bytes()).unwrap();
// hprintln!("Ed25519 signature:").ok();
// hprintln!("msg: {:?}", &request.message).ok();
+2 -2
View File
@@ -23,7 +23,7 @@ Sign<B> for super::HmacSha256
// let path = resources.prepare_path_for_key(KeyType::Secret, &key_id)?;
// let (serialized_key, _) = resources.load_key_unchecked(&path)?;
// let shared_secret = &serialized_key.value;
let l = shared_secret.as_slice().len();
let l = shared_secret.as_ref().len();
if (l & 0xf) != 0 {
info_now!("wrong key length, expected multiple of 16, got {}", l);
Err(Error::WrongKeyKind)?;
@@ -41,7 +41,7 @@ Sign<B> for super::HmacSha256
// incorrect use of the code value may permit timing attacks which defeat
// the security provided by the `MacResult`
let code_bytes: [u8; 32] = result.code().as_slice().try_into().unwrap();
let signature = Signature::from_slice(&code_bytes).unwrap();
let signature = Signature::try_from_slice(&code_bytes).unwrap();
// return signature
Ok(reply::Sign { signature })
+16 -16
View File
@@ -13,7 +13,7 @@ fn load_public_key<B: Board>(resources: &mut ServiceResources<B>, key_id: &Uniqu
.load_key(KeyType::Public, Some(KeyKind::P256), &key_id)?
.value;
let public_bytes = match public_bytes.as_slice().len() {
let public_bytes = match public_bytes.as_ref().len() {
64 => {
let mut public_bytes_ = [0u8; 64];
public_bytes_.copy_from_slice(&public_bytes.as_ref());
@@ -96,7 +96,7 @@ DeserializeKey<B> for super::P256
let public_key = match request.format {
KeySerialization::Cose => {
// TODO: this should all be done upstream
let cose_public_key: ctap_types::cose::P256PublicKey = crate::cbor_deserialize(
let cose_public_key: cosey::P256PublicKey = crate::cbor_deserialize(
&request.serialized_key).map_err(|_| Error::CborError)?;
let mut serialized_key = [0u8; 64];
if cose_public_key.x.len() != 32 || cose_public_key.y.len() != 32 {
@@ -114,7 +114,7 @@ DeserializeKey<B> for super::P256
KeySerialization::EcdhEsHkdf256 => {
// TODO: this should all be done upstream
let cose_public_key: ctap_types::cose::EcdhEsHkdf256PublicKey = crate::cbor_deserialize(
let cose_public_key: cosey::EcdhEsHkdf256PublicKey = crate::cbor_deserialize(
&request.serialized_key).map_err(|_| Error::CborError)?;
let mut serialized_key = [0u8; 64];
if cose_public_key.x.len() != 32 || cose_public_key.y.len() != 32 {
@@ -200,16 +200,16 @@ SerializeKey<B> for super::P256
let mut serialized_key = Message::new();
match request.format {
KeySerialization::EcdhEsHkdf256 => {
let cose_pk = ctap_types::cose::EcdhEsHkdf256PublicKey {
x: ByteBuf::from_slice(&public_key.x_coordinate()).unwrap(),
y: ByteBuf::from_slice(&public_key.y_coordinate()).unwrap(),
let cose_pk = cosey::EcdhEsHkdf256PublicKey {
x: ByteBuf::try_from_slice(&public_key.x_coordinate()).unwrap(),
y: ByteBuf::try_from_slice(&public_key.y_coordinate()).unwrap(),
};
crate::cbor_serialize_bytes(&cose_pk, &mut serialized_key).map_err(|_| Error::CborError)?;
}
KeySerialization::Cose => {
let cose_pk = ctap_types::cose::P256PublicKey {
x: ByteBuf::from_slice(&public_key.x_coordinate()).unwrap(),
y: ByteBuf::from_slice(&public_key.y_coordinate()).unwrap(),
let cose_pk = cosey::P256PublicKey {
x: ByteBuf::try_from_slice(&public_key.x_coordinate()).unwrap(),
y: ByteBuf::try_from_slice(&public_key.y_coordinate()).unwrap(),
};
crate::cbor_serialize_bytes(&cose_pk, &mut serialized_key).map_err(|_| Error::CborError)?;
}
@@ -249,7 +249,7 @@ fn load_keypair<B: Board>(resources: &mut ServiceResources<B>, key_id: &UniqueId
// info_now!("loading keypair");
let seed: [u8; 32] = resources
.load_key(KeyType::Secret, Some(KeyKind::P256), &key_id)?
.value.as_slice()
.value.as_ref()
.try_into()
.map_err(|_| Error::InternalError)?;
@@ -269,7 +269,7 @@ Sign<B> for super::P256
let seed: [u8; 32] = resources
.load_key(KeyType::Secret, Some(KeyKind::P256), &key_id)?
.value.as_slice()
.value.as_ref()
.try_into()
.map_err(|_| Error::InternalError)?;
@@ -277,10 +277,10 @@ Sign<B> for super::P256
let our_signature = match request.format {
SignatureSerialization::Asn1Der => {
Signature::from_slice(&native_signature.to_asn1_der()).unwrap()
Signature::try_from_slice(&native_signature.to_asn1_der()).unwrap()
}
SignatureSerialization::Raw => {
Signature::from_slice(&native_signature.to_bytes()).unwrap()
Signature::try_from_slice(&native_signature.to_bytes()).unwrap()
}
};
// #[cfg(all(test, feature = "verbose-tests"))]
@@ -316,7 +316,7 @@ Sign<B> for super::P256Prehashed
info_now!("wrong length");
return Err(Error::WrongMessageLength);
}
let message: [u8; 32] = request.message.as_slice().try_into().unwrap();
let message: [u8; 32] = request.message.as_ref().try_into().unwrap();
info_now!("cast to 32B array");
let native_signature = keypair.sign_prehashed(&message);
@@ -324,10 +324,10 @@ Sign<B> for super::P256Prehashed
let our_signature = match request.format {
SignatureSerialization::Asn1Der => {
Signature::from_slice(&native_signature.to_asn1_der()).unwrap()
Signature::try_from_slice(&native_signature.to_asn1_der()).unwrap()
}
SignatureSerialization::Raw => {
Signature::from_slice(&native_signature.to_bytes()).unwrap()
Signature::try_from_slice(&native_signature.to_bytes()).unwrap()
}
};
// #[cfg(all(test, feature = "verbose-tests"))]
+1 -1
View File
@@ -17,7 +17,7 @@ DeriveKey<B> for super::Sha256
let shared_secret: [u8; 32] = resources
.load_key(KeyType::Secret, Some(KeyKind::SharedSecret32), base_id)?
.value.as_slice()
.value.as_ref()
.try_into()
.map_err(|_| Error::InternalError)?;
+2 -2
View File
@@ -28,7 +28,7 @@ impl<B: Board> Encrypt<B> for super::Tdes
let symmetric_key: [u8; 24] = resources
.load_key(KeyType::Secret, None, &key_id)?
.value.as_slice().try_into()
.value.as_ref().try_into()
.map_err(|_| Error::InternalError)?;
let cipher = des::TdesEde3::new(GenericArray::from_slice(&symmetric_key));
@@ -53,7 +53,7 @@ impl<B: Board> Decrypt<B> for super::Tdes
let symmetric_key: [u8; 24] = resources
.load_key(KeyType::Secret, None, &key_id)?
.value.as_slice().try_into()
.value.as_ref().try_into()
.map_err(|_| Error::InternalError)?;
let cipher = des::TdesEde3::new(GenericArray::from_slice(&symmetric_key));
+2 -2
View File
@@ -79,7 +79,7 @@ Sign<B> for super::Totp
let secret: [u8; 20] = resources
.load_key(KeyType::Secret, None, &key_id)?
.value.as_slice().try_into()
.value.as_ref().try_into()
.map_err(|_| Error::InternalError)?;
if request.message.len() != 8 {
@@ -90,7 +90,7 @@ Sign<B> for super::Totp
let totp_value: u64 = hotp_raw(&secret, timestamp, DIGITS);
// return signature (encode as LE)
Ok(reply::Sign { signature: totp_value.to_le_bytes().as_ref().try_into().unwrap() })
Ok(reply::Sign { signature: crate::ByteBuf::try_from_slice(totp_value.to_le_bytes().as_ref()).unwrap() })
}
}
+36
View File
@@ -29,6 +29,42 @@ interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 5, [None, None, None, None, None])
}
#[cfg(feature = "clients-6")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 6, [None, None, None, None, None, None])
}
#[cfg(feature = "clients-7")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 7, [None, None, None, None, None, None, None])
}
#[cfg(feature = "clients-8")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 8, [None, None, None, None, None, None, None, None])
}
#[cfg(feature = "clients-9")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 9, [None, None, None, None, None, None, None, None, None])
}
#[cfg(feature = "clients-10")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 10, [None, None, None, None, None, None, None, None, None, None])
}
#[cfg(feature = "clients-11")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 11, [None, None, None, None, None, None, None, None, None, None, None])
}
#[cfg(feature = "clients-12")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 12, [None, None, None, None, None, None, None, None, None, None, None, None])
}
// pub use interchange::TrussedInterchange;
// TODO: The request pipe should block if there is an unhandled
+4 -4
View File
@@ -1,7 +1,7 @@
use core::convert::{TryFrom, TryInto};
pub use rand_core::{RngCore, SeedableRng};
use heapless::ByteBuf;
use heapless_bytes::Bytes as ByteBuf;
use interchange::Responder;
use littlefs2::path::{Path, PathBuf};
use chacha20::ChaCha8Rng;
@@ -635,11 +635,11 @@ impl<B: Board> ServiceResources<B> {
let path = self.namespace_path(&path);
let mut data = Message::new();
data.resize_to_capacity();
let data: Message = match request.location {
let data: Message = crate::ByteBuf::from(match request.location {
StorageLocation::Internal => self.board.store().ifs().read(&path),
StorageLocation::External => self.board.store().efs().read(&path),
StorageLocation::Volatile => self.board.store().vfs().read(&path),
}.map_err(|_| Error::InternalError)?.into();
}.map_err(|_| Error::InternalError)?);
// data.resize_default(size).map_err(|_| Error::InternalError)?;
Ok(Reply::ReadFile(reply::ReadFile { data } ))
}
@@ -829,7 +829,7 @@ impl<B: Board> ServiceResources<B> {
KeyType::Public => b"pub\0".try_into().unwrap(),
KeyType::Secret => b"sec\0".try_into().unwrap(),
});
path.push(&PathBuf::from(key_id.hex().as_slice()));
path.push(&PathBuf::from(key_id.hex().as_ref()));
// no dataspacing
self.namespace_path(&path)
}
+1 -1
View File
@@ -327,7 +327,7 @@ impl<'a> TryFrom<(KeyKind, &'a [u8])> for SerializedKey {
fn try_from(from: (KeyKind, &'a [u8])) -> Result<Self, Error> {
Ok(SerializedKey {
kind: from.0,
value: ByteBuf::from_slice(from.1).map_err(|_| Error::InternalError)?,
value: ByteBuf::try_from_slice(from.1).map_err(|_| Error::InternalError)?,
})
}
}
+2 -2
View File
@@ -192,7 +192,7 @@ macro_rules! setup {
let board = $board::new(rng, store, pc_interface);
let mut trussed: crate::Service<$board> = crate::service::Service::new(board);
let (test_trussed_requester, test_trussed_responder) = crate::pipe::TrussedInterchange::claim(0)
let (test_trussed_requester, test_trussed_responder) = crate::pipe::TrussedInterchange::claim()
.expect("could not setup TEST TrussedInterchange");
let mut test_client_id = littlefs2::path::PathBuf::new();
test_client_id.push(b"TEST\0".try_into().unwrap());
@@ -369,7 +369,7 @@ fn aead() {
).map_err(drop).expect("no client error"))
.map_err(drop).expect("no errors").plaintext;
assert_eq!(&message[..], plaintext.unwrap().as_slice());
assert_eq!(&message[..], plaintext.unwrap().as_ref());
}
#[test]
+2 -2
View File
@@ -9,7 +9,7 @@ pub use heapless::{
Vec,
};
pub use heapless::ByteBuf;
pub use heapless_bytes::Bytes as ByteBuf;
pub use littlefs2::{
fs::{DirEntry, Filesystem},
@@ -515,7 +515,7 @@ impl UniqueId {
// (0..hex.len())
// use hex::FromHex;
// let maybe_bytes = <[u8; 16]>::from_hex(hex).map_err(|e| ());
// maybe_bytes.map(|bytes| Self(ByteBuf::from_slice(&bytes).unwrap()))
// maybe_bytes.map(|bytes| Self(ByteBuf::try_from_slice(&bytes).unwrap()))
if (hex.len() & 1) == 1 {
// panic!("hex len & 1 = {}", hex.len() & 1);
return Err(());