Merge branch 'master' into master

This commit is contained in:
Jean-Michel Picod
2020-09-22 17:15:04 +02:00
committed by GitHub
17 changed files with 117 additions and 54 deletions

View File

@@ -913,6 +913,13 @@ if __name__ == "__main__":
const="oom_test",
help=("Compiles and installs the oom_test example that tests the "
"allocator until an out-of-memory error occurs."))
apps_group.add_argument(
"--console_test",
dest="application",
action="store_const",
const="console_test",
help=("Compiles and installs the console_test example that tests the "
"console driver with messages of various lengths."))
main_parser.set_defaults(features=["with_ctap1"])

33
examples/console_test.rs Normal file
View File

@@ -0,0 +1,33 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![no_std]
extern crate lang_items;
use libtock_drivers::console::{Console, BUFFER_SIZE};
fn main() {
// Write messages of length up to the console driver's buffer size.
let mut buf = [0; BUFFER_SIZE];
loop {
for i in 1..buf.len() {
for j in 0..i {
buf[j] = b'0' + ((i % 10) as u8);
}
buf[i] = b'\n';
Console::write_unbuffered(&mut buf[..(i + 1)]);
}
}
}

View File

@@ -1,9 +1,9 @@
c242b0237b93328eea0213411916f84e3ce631c3eea3bf56d6769ae5aa0b8d06 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
34e36dc04716c159800ae3ab3f2750bee4ea66df40e08b864a93d873c34142e7 target/nrf52840dk_merged.hex
259a54fae11cb8f1306051354825d19223ba4c33f3adfdb2d3e9d9efc7229302 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
64f4b7b21ab3ff492f1e108ed72c96ec9c8cba5d44774c3fa0900e443f3d2de8 target/nrf52840_dongle_merged.hex
49d647374a1448c9c3107758b6e0a1cabdf008c3e53524a3b047a16c27b8af29 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
cb70d4547756f8cbfc54ec94ee350022b2a0433c370a240a35d22128c8864337 target/nrf52840_dongle_dfu_merged.hex
06a38a0d6d356145467a73c765e28a945878f663664016f888393207097bfe10 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin
affb4c7ca43212a6734aa112fb19aa23cb2f0571bc085d5dfd4b6fe08c97f110 target/nrf52840_mdk_dfu_merged.hex
898a78d4f1ecc94d2894552caf62f0b382a743aecb316ac3791df70fc62370b9 target/tab/ctap2.tab
91a98f475cb3042dd5184598a8292edb2a414df8d967a35c8f2295826b5a161b third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
fd7febdc4497c59d3adeeba572effbd20d95cb7e58dc29619306f002c919495f target/nrf52840dk_merged.hex
a5943c5311158b0f99370246d37782eb9b12fc36c56387eadb6587a3a4fe8fd5 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
4f4a5428fb06548ad2cf16f050bde37c9af5fac4629141455064fdb7f96dfbd9 target/nrf52840_dongle_merged.hex
663297e3e29b9e2a972b68cea1592aaf965d797242579bb5bca09cd73cdfb637 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
4367026ef48c8109f0635d5e635ec5999f0a1f2e0af9c5f35e51969ebd3fd3c0 target/nrf52840_dongle_dfu_merged.hex
162a05d056aafc16d4868d5c3aa10518e41299dddd60608f96954dc9cf964cd3 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin
009f4e60074ad1dc6d0aacbeb7e78fa7b6de9e39fa79a6aaad33105389f8ed02 target/nrf52840_mdk_dfu_merged.hex
09b7ff9a4d44cd675c4ee581d43713addb5f3931ea9e7c8d71d448e0539f7070 target/tab/ctap2.tab

View File

@@ -1,9 +1,9 @@
dab66677002854f6abfb1745d24d1c9e4e93c9bba286b14024e42cb8f2b99b9a third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
8e33b850330bdd19314e443792a170e04669fe932122af5498dcdd38bf47af7b target/nrf52840dk_merged.hex
70cf9f6c1d6b2149c1ca88664073a92e092215faaf551310f8bfd8e171d3d3a1 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
4cf4a438a9796091e91e80d15cc1ca840d0cf7e7cf5816a9650e7c33f0a78120 target/nrf52840_dongle_merged.hex
f550b6493c8cd401d191306510de50ddd6d4c709dcf90ea1bd3a9f1bcffd11b5 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
02f529795cb2faf09a82e0b42cc1152a9d0f7fa2679135333d2b8e9e19069f59 target/nrf52840_dongle_dfu_merged.hex
1baaf518a74c6077cb936d9cf178b6dd0232e7562fa56174886b05b77886cc32 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin
1c32f85c081d69eaf88bf08b885ee2c4b0a590f824045fa73350a14ad2b4f0b9 target/nrf52840_mdk_dfu_merged.hex
327a46a4f591072004d47e48983ad0b8c2ee5eb2fc64e5aba78cd3d2b1916336 target/tab/ctap2.tab
3feb5d29a3d669107b460a00391440be4ebc5e50461f9ef3248714f4f99c070e third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
b0711a92223dfd2b3801caf38b2f004a4e18fa2dbd1ca8d5ec60b7b7b0720a8e target/nrf52840dk_merged.hex
8eebe1c1dfe22003466c2570b3735c54c58ae91b8168582ad363ab79c9230a15 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
2af04acdc8705f9a06535dee1fdbedc6e39d1e59e88ced9acc2fd3e2b585c29b target/nrf52840_dongle_merged.hex
779d77071d1e629f92210ac313e230bcaea6d77c710210c1ac4b40f8085cdad7 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
0b9591842b56e5c9a1c4a9160681d023a11135593373c483f383c39142be9a8f target/nrf52840_dongle_dfu_merged.hex
f466490d6498f6c06c7c4a717eb437ba2fb06d1985532c23f145d38b9daa8259 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin
43393a780ed9fe89cfb000a153a6e8af3735e75c5ccc0b34795381a4914973e2 target/nrf52840_mdk_dfu_merged.hex
0fe175c3cf5a77a9f6df8f5aa3f82715986536e2f737aee44cb680a1e801dac4 target/tab/ctap2.tab

View File

@@ -6,8 +6,8 @@ Min RAM size from segments in ELF: 20 bytes
Number of writeable flash regions: 0
Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes.
Entry point is in .text section
Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes.
Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes.
Adding .text section. Offset: 128 (0x80). Length: 186112 (0x2d700) bytes.
Adding .stack section. Offset: 186240 (0x2d780). Length: 16384 (0x4000) bytes.
Searching for .rel.X sections to add.
TBF Header:
version: 2 0x2
@@ -30,8 +30,8 @@ Min RAM size from segments in ELF: 20 bytes
Number of writeable flash regions: 0
Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes.
Entry point is in .text section
Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes.
Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes.
Adding .text section. Offset: 128 (0x80). Length: 186112 (0x2d700) bytes.
Adding .stack section. Offset: 186240 (0x2d780). Length: 16384 (0x4000) bytes.
Searching for .rel.X sections to add.
TBF Header:
version: 2 0x2
@@ -54,8 +54,8 @@ Min RAM size from segments in ELF: 20 bytes
Number of writeable flash regions: 0
Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes.
Entry point is in .text section
Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes.
Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes.
Adding .text section. Offset: 128 (0x80). Length: 186112 (0x2d700) bytes.
Adding .stack section. Offset: 186240 (0x2d780). Length: 16384 (0x4000) bytes.
Searching for .rel.X sections to add.
TBF Header:
version: 2 0x2
@@ -78,8 +78,8 @@ Min RAM size from segments in ELF: 20 bytes
Number of writeable flash regions: 0
Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes.
Entry point is in .text section
Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes.
Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes.
Adding .text section. Offset: 128 (0x80). Length: 186112 (0x2d700) bytes.
Adding .stack section. Offset: 186240 (0x2d780). Length: 16384 (0x4000) bytes.
Searching for .rel.X sections to add.
TBF Header:
version: 2 0x2

View File

@@ -6,8 +6,8 @@ Min RAM size from segments in ELF: 20 bytes
Number of writeable flash regions: 0
Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes.
Entry point is in .text section
Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes.
Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes.
Adding .text section. Offset: 128 (0x80). Length: 186080 (0x2d6e0) bytes.
Adding .stack section. Offset: 186208 (0x2d760). Length: 16384 (0x4000) bytes.
Searching for .rel.X sections to add.
TBF Header:
version: 2 0x2
@@ -30,8 +30,8 @@ Min RAM size from segments in ELF: 20 bytes
Number of writeable flash regions: 0
Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes.
Entry point is in .text section
Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes.
Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes.
Adding .text section. Offset: 128 (0x80). Length: 186080 (0x2d6e0) bytes.
Adding .stack section. Offset: 186208 (0x2d760). Length: 16384 (0x4000) bytes.
Searching for .rel.X sections to add.
TBF Header:
version: 2 0x2
@@ -54,8 +54,8 @@ Min RAM size from segments in ELF: 20 bytes
Number of writeable flash regions: 0
Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes.
Entry point is in .text section
Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes.
Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes.
Adding .text section. Offset: 128 (0x80). Length: 186080 (0x2d6e0) bytes.
Adding .stack section. Offset: 186208 (0x2d760). Length: 16384 (0x4000) bytes.
Searching for .rel.X sections to add.
TBF Header:
version: 2 0x2
@@ -78,8 +78,8 @@ Min RAM size from segments in ELF: 20 bytes
Number of writeable flash regions: 0
Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes.
Entry point is in .text section
Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes.
Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes.
Adding .text section. Offset: 128 (0x80). Length: 186080 (0x2d6e0) bytes.
Adding .stack section. Offset: 186208 (0x2d760). Length: 16384 (0x4000) bytes.
Searching for .rel.X sections to add.
TBF Header:
version: 2 0x2

View File

@@ -16,11 +16,11 @@ use super::hid::ChannelID;
use super::key_material::{ATTESTATION_CERTIFICATE, ATTESTATION_PRIVATE_KEY};
use super::status_code::Ctap2StatusCode;
use super::CtapState;
use crate::timer::ClockValue;
use alloc::vec::Vec;
use core::convert::Into;
use core::convert::TryFrom;
use crypto::rng256::Rng256;
use libtock_drivers::timer::ClockValue;
// The specification referenced in this file is at:
// https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-raw-message-formats-v1.2-ps-20170411.pdf

View File

@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
mod receive;
mod send;
pub mod receive;
pub mod send;
use self::receive::MessageAssembler;
use self::send::HidPacketIterator;
@@ -22,13 +22,13 @@ use super::ctap1;
use super::status_code::Ctap2StatusCode;
use super::timed_permission::TimedPermission;
use super::CtapState;
use crate::timer::{ClockValue, Duration, Timestamp};
use alloc::vec::Vec;
#[cfg(feature = "debug_ctap")]
use core::fmt::Write;
use crypto::rng256::Rng256;
#[cfg(feature = "debug_ctap")]
use libtock_drivers::console::Console;
use libtock_drivers::timer::{ClockValue, Duration, Timestamp};
// CTAP specification (version 20190130) section 8.1
// TODO: Channel allocation, section 8.1.3?

View File

@@ -13,9 +13,9 @@
// limitations under the License.
use super::{ChannelID, CtapHid, HidPacket, Message, ProcessedPacket};
use crate::timer::Timestamp;
use alloc::vec::Vec;
use core::mem::swap;
use libtock_drivers::timer::Timestamp;
// A structure to assemble CTAPHID commands from a series of incoming USB HID packets.
pub struct MessageAssembler {
@@ -195,7 +195,7 @@ impl MessageAssembler {
#[cfg(test)]
mod test {
use super::*;
use crate::timer::Duration;
use libtock_drivers::timer::Duration;
// Except for tests that exercise timeouts, all packets are synchronized at the same dummy
// timestamp.

View File

@@ -12,17 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::crypto::rng256::Rng256;
#[cfg(feature = "with_ctap2_1")]
use crate::ctap::data_formats::{extract_array, extract_text_string};
use crate::ctap::data_formats::{CredentialProtectionPolicy, PublicKeyCredentialSource};
use crate::ctap::pin_protocol_v1::PIN_AUTH_LENGTH;
use crate::ctap::status_code::Ctap2StatusCode;
use crate::ctap::{key_material, USE_BATCH_ATTESTATION};
use crate::embedded_flash::{self, StoreConfig, StoreEntry, StoreError};
use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryInto;
use ctap2::embedded_flash::{self, StoreConfig, StoreEntry, StoreError};
use crypto::rng256::Rng256;
#[cfg(any(test, feature = "ram_storage"))]
type Storage = embedded_flash::BufferStorage;
@@ -660,9 +660,9 @@ fn _serialize_min_pin_length_rp_ids(rp_ids: Vec<String>) -> Result<Vec<u8>, Ctap
#[cfg(test)]
mod test {
use super::*;
use crate::crypto;
use crate::crypto::rng256::{Rng256, ThreadRng256};
use crate::ctap::data_formats::{PublicKeyCredentialSource, PublicKeyCredentialType};
use crypto;
use crypto::rng256::{Rng256, ThreadRng256};
fn create_credential_source(
rng: &mut ThreadRng256,

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::timer::{ClockValue, Duration};
use libtock_drivers::timer::{ClockValue, Duration};
#[derive(Clone, Copy, Debug)]
pub enum TimedPermission {

View File

@@ -12,12 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(any(test, feature = "ram_storage"))]
mod buffer;
mod storage;
mod store;
#[cfg(not(any(test, feature = "ram_storage")))]
mod syscall;
#[cfg(any(test, feature = "ram_storage"))]
pub use self::buffer::{BufferOptions, BufferStorage};
pub use self::storage::{Index, Storage, StorageError, StorageResult};
pub use self::store::{Store, StoreConfig, StoreEntry, StoreError, StoreIndex};
#[cfg(not(any(test, feature = "ram_storage")))]
pub use self::syscall::SyscallStorage;

View File

@@ -163,9 +163,11 @@ mod bitfield;
mod format;
use self::format::{Format, IsReplace};
#[cfg(feature = "std")]
use super::BufferStorage;
use super::{Index, Storage};
#[cfg(any(test, feature = "ram_storage"))]
use crate::embedded_flash::BufferStorage;
#[cfg(any(test, feature = "ram_storage"))]
use alloc::boxed::Box;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
@@ -402,6 +404,7 @@ impl<S: Storage, C: StoreConfig> Store<S, C> {
/// Computes the length in bytes that would be used in the storage if an insert operation is
/// executed provided the data of the inserted entry has `length` bytes and whether this data is
/// sensitive.
#[allow(dead_code)]
pub fn insert_len(&self, sensitive: bool, length: usize) -> usize {
self.format.entry_size(IsReplace::Insert, sensitive, length)
}
@@ -410,6 +413,7 @@ impl<S: Storage, C: StoreConfig> Store<S, C> {
///
/// The value at index `page` of the result is the number of times page `page` was erased. This
/// number is an underestimate in case power was lost when this page was erased.
#[allow(dead_code)]
pub fn compaction_info(&self) -> Vec<usize> {
let mut info = Vec::with_capacity(self.format.num_pages);
for page in 0..self.format.num_pages {
@@ -766,7 +770,7 @@ impl<S: Storage, C: StoreConfig> Store<S, C> {
}
// Those functions are not meant for production.
#[cfg(feature = "std")]
#[cfg(any(test, feature = "ram_storage"))]
impl<C: StoreConfig> Store<BufferStorage, C> {
/// Takes a snapshot of the storage after a given amount of word operations.
pub fn arm_snapshot(&mut self, delay: usize) {

View File

@@ -16,8 +16,13 @@
#[macro_use]
extern crate alloc;
#[macro_use]
extern crate arrayref;
#[macro_use]
extern crate cbor;
extern crate lang_items;
extern crate libtock_core;
extern crate libtock_drivers;
pub mod ctap;
pub mod embedded_flash;

View File

@@ -28,6 +28,7 @@ extern crate cbor;
extern crate crypto;
mod ctap;
pub mod embedded_flash;
use core::cell::Cell;
#[cfg(feature = "debug_ctap")]

View File

@@ -7,3 +7,10 @@ mod allocator;
mod panic_handler;
#[cfg(not(feature = "std"))]
mod util;
#[cfg(feature = "std")]
#[no_mangle]
unsafe fn libtock_alloc_init(_app_heap_start: usize, _app_heap_size: usize) {
// Stub so that the symbol is present.
unimplemented!()
}

View File

@@ -17,7 +17,7 @@ mod allow_nr {
pub const SHARE_BUFFER: usize = 1;
}
const BUFFER_SIZE: usize = 1024;
pub const BUFFER_SIZE: usize = 1024;
pub struct Console {
allow_buffer: [u8; BUFFER_SIZE],
@@ -70,11 +70,13 @@ impl Console {
// Clear the buffer even in case of error, to avoid an infinite loop.
self.count_pending = 0;
let result = syscalls::allow(
DRIVER_NUMBER,
allow_nr::SHARE_BUFFER,
&mut self.allow_buffer[..count],
);
Console::write_unbuffered(&mut self.allow_buffer[..count]);
}
pub fn write_unbuffered(buf: &mut [u8]) {
let count = buf.len();
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::SHARE_BUFFER, buf);
if result.is_err() {
return;
}