From e249f2f2c6b2fa277470a161f667fecd06649f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 29 Mar 2023 17:32:59 +0200 Subject: [PATCH 01/10] Add reading of large data objects --- Cargo.toml | 2 +- src/lib.rs | 13 +++++++---- src/state.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4bb1c0f..3763d61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ log-warn = [] log-error = [] [patch.crates-io] -trussed = { git = "https://github.com/Nitrokey/trussed", tag = "v0.1.0-nitrokey.8"} +trussed = { git = "https://github.com/sosthene-nitrokey/trussed", rev = "25ae084251b76bacfa8919eb8"} trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", tag = "v0.2.1"} littlefs2 = { git = "https://github.com/Nitrokey/littlefs2", tag = "v0.3.2-nitrokey-2" } diff --git a/src/lib.rs b/src/lib.rs index a31b42b..debf3a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -910,10 +910,15 @@ impl<'a, T: trussed::Client + AuthClient + trussed::client::Ed255> LoadedAuthent let offset = reply.len(); match container { Container::KeyHistoryObject => self.get_key_history_object(reply.lend())?, - _ => match ContainerStorage(container).load(self.trussed, self.options.storage)? { - Some(data) => reply.expand(&data)?, - None => return Err(Status::NotFound), - }, + _ => { + if !ContainerStorage(container).load( + self.trussed, + self.options.storage, + reply.lend(), + )? { + return Err(Status::NotFound); + } + } } reply.prepend_len(offset)?; diff --git a/src/state.rs b/src/state.rs index 93c145e..b2cf0f3 100644 --- a/src/state.rs +++ b/src/state.rs @@ -8,6 +8,7 @@ use flexiber::EncodableHeapless; use heapless::Vec; use heapless_bytes::Bytes; use iso7816::Status; +use trussed::types::OpenSeekFrom; use trussed::{ api::reply::Metadata, config::MAX_MESSAGE_LENGTH, @@ -17,6 +18,7 @@ use trussed::{ use trussed_auth::AuthClient; use crate::piv_types::CardHolderUniqueIdentifier; +use crate::reply::Reply; use crate::{constants::*, piv_types::AsymmetricAlgorithms}; use crate::{ container::{AsymmetricKeyReference, Container, ReadAccessRule, SecurityCondition}, @@ -617,6 +619,53 @@ fn load_if_exists( } } +/// Returns false if the file does not exist +fn load_if_exists_streaming( + client: &mut impl trussed::Client, + location: Location, + path: &PathBuf, + mut buffer: Reply<'_, R>, +) -> Result { + let mut read_len = 0; + let file_len; + match try_syscall!(client.read_file_chunk(location, path.clone(), OpenSeekFrom::Start(0))) { + Ok(r) => { + read_len += r.data.len(); + file_len = r.len; + buffer.expand(&r.data)?; + } + Err(_) => match try_syscall!(client.entry_metadata(location, path.clone())) { + Ok(Metadata { metadata: None }) => return Ok(false), + Ok(Metadata { + metadata: Some(_metadata), + }) => { + error!("File {path} exists but couldn't be read: {_metadata:?}"); + return Err(Status::UnspecifiedPersistentExecutionError); + } + Err(_err) => { + error!("File {path} couldn't be read: {_err:?}"); + return Err(Status::UnspecifiedPersistentExecutionError); + } + }, + } + + while read_len < file_len { + match try_syscall!(client.read_file_chunk( + location, + path.clone(), + OpenSeekFrom::Start(read_len as u32) + )) { + Ok(r) => { + read_len += r.data.len(); + buffer.expand(&r.data)?; + } + Err(_err) => error!("Failed to read chunk: {:?}", _err), + } + } + + Ok(true) +} + #[derive(Clone, Copy, Debug)] pub struct ContainerStorage(pub Container); @@ -703,13 +752,22 @@ impl ContainerStorage { } } - pub fn load( + pub fn load( self, client: &mut impl trussed::Client, storage: Location, - ) -> Result>, Status> { - load_if_exists(client, storage, &self.path()) - .map(|data| data.or_else(|| self.default().map(Bytes::from))) + mut reply: Reply<'_, R>, + ) -> Result { + if load_if_exists_streaming(client, storage, &self.path(), reply.lend())? { + return Ok(true); + } + + if let Some(data) = self.default() { + reply.expand(&data)?; + Ok(true) + } else { + Ok(false) + } } pub fn save( From ddc67d75709d24549f0646bb036922fe5dfffaa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 29 Mar 2023 17:48:25 +0200 Subject: [PATCH 02/10] Implement writing of large data objects --- src/state.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/state.rs b/src/state.rs index b2cf0f3..043da1e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -776,14 +776,34 @@ impl ContainerStorage { bytes: &[u8], storage: Location, ) -> Result<(), Status> { - let msg = Bytes::from(heapless::Vec::try_from(bytes).map_err(|_| { - error!("Buffer full"); - Status::IncorrectDataParameter - })?); + let mut msg = Bytes::new(); + let chunk_size = msg.capacity(); + let mut chunks = bytes.chunks(chunk_size).map(|chunk| { + Bytes::from( + heapless::Vec::try_from(chunk) + .expect("Iteration over chunks yields maximum of chunk_size"), + ) + }); + msg = chunks.next().unwrap_or_default(); + let mut written = msg.len(); try_syscall!(client.write_file(storage, self.path(), msg, None)).map_err(|_err| { error!("Failed to store data: {_err:?}"); Status::UnspecifiedNonpersistentExecutionError })?; + for chunk in chunks { + let off = written; + written += chunk.len(); + try_syscall!(client.write_file_chunk( + storage, + self.path(), + chunk, + OpenSeekFrom::Start(off as u32) + )) + .map_err(|_err| { + error!("Failed to store data: {_err:?}"); + Status::UnspecifiedNonpersistentExecutionError + })?; + } Ok(()) } } From ac6097a8d17b1f089a6ad41479eb755ee0a93e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 30 Mar 2023 11:23:28 +0200 Subject: [PATCH 03/10] Add test with large certificate --- src/lib.rs | 2 +- tests/large-cert.der | Bin 0 -> 1849 bytes tests/large-cert.pem | 41 +++++++++++++++++++++++++++++++++++++++++ tests/pivy.rs | 31 ++++++++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tests/large-cert.der create mode 100644 tests/large-cert.pem diff --git a/src/lib.rs b/src/lib.rs index debf3a0..0de6770 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,7 +151,7 @@ where ) -> Result { info!("PIV responding to {:02x?}", command); let parsed_command: Command = command.try_into()?; - info!("parsed: {:?}", &parsed_command); + info!("parsed: {:02x?}", &parsed_command); let reply = Reply(reply); match parsed_command { diff --git a/tests/large-cert.der b/tests/large-cert.der new file mode 100644 index 0000000000000000000000000000000000000000..01ec76c5544c36959f2b5b5c9efb0c6f34965da1 GIT binary patch literal 1849 zcmXqLVmCEtVv}9K%*4pVB*Oa0JJj=Bz&7(bq4&K@`%>S(iu`84%f_kI=F#?@mywa1 zmBFBiNyCuafRl|ml!Z;0Da6&VvD=`r1H|RvX>15_4GtMdjBpM6U~rA6fjcN~hL{XzOw&F#z!RoC3O{i0Il z^RrhgKmKlQ4gHu}=yC1nJZ1Yp!=D*>UU4(lxO;l%In41iFgt(Z@vDRPoLmAQY~CHn z&cw{fz_>WrAkaXTjX6}7k420{q*glPKAZcY52?MbP z>iXykgVaEA6Lt z6)ygAJ6pijr*5ys#M#crq<39eb#rNe4Dw_`E8$CzZ!@*$fo~# zbwGXAO7n~v88d>kdHB-*M=9MnDzNg{e%(p#=J%7A&M0r(V0bFAm+j@P*iHksb%wo; zlRO>I7M$1r*YwOKFzZ*Zs$W(7yT?0jm2UL9{ZH!S%$q_FMJ`qTZ1+tS?Y+Nm%cRPRgVop7_i>l9L$&YSRRaZp(Jj=-va33rR)7j9x; o;F_)f@$U_R$>!ZhUkd->@-OHQp0WCm&5e@^M; Date: Thu, 30 Mar 2023 14:05:35 +0200 Subject: [PATCH 04/10] Use correct length in advance when loading files This reduces the need to shuffle the stack --- src/lib.rs | 8 +++++--- src/state.rs | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0de6770..0e64492 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -907,9 +907,12 @@ impl<'a, T: trussed::Client + AuthClient + trussed::client::Ed255> LoadedAuthent _ => &[0x53], }; reply.expand(tag)?; - let offset = reply.len(); match container { - Container::KeyHistoryObject => self.get_key_history_object(reply.lend())?, + Container::KeyHistoryObject => { + let offset = reply.len(); + self.get_key_history_object(reply.lend())?; + reply.prepend_len(offset)?; + } _ => { if !ContainerStorage(container).load( self.trussed, @@ -920,7 +923,6 @@ impl<'a, T: trussed::Client + AuthClient + trussed::client::Ed255> LoadedAuthent } } } - reply.prepend_len(offset)?; Ok(()) } diff --git a/src/state.rs b/src/state.rs index 043da1e..ed2b4f2 100644 --- a/src/state.rs +++ b/src/state.rs @@ -632,6 +632,7 @@ fn load_if_exists_streaming( Ok(r) => { read_len += r.data.len(); file_len = r.len; + buffer.append_len(file_len)?; buffer.expand(&r.data)?; } Err(_) => match try_syscall!(client.entry_metadata(location, path.clone())) { @@ -752,6 +753,7 @@ impl ContainerStorage { } } + // Write the length of the file and write pub fn load( self, client: &mut impl trussed::Client, @@ -763,6 +765,7 @@ impl ContainerStorage { } if let Some(data) = self.default() { + reply.append_len(data.len())?; reply.expand(&data)?; Ok(true) } else { From bcb4b2ee792e57a5722bc662602ee13b92052658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 30 Mar 2023 14:35:49 +0200 Subject: [PATCH 05/10] Remove duplicated certificate --- tests/large-cert.der | Bin 1849 -> 0 bytes tests/pivy.rs | 6 ++++-- 2 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 tests/large-cert.der diff --git a/tests/large-cert.der b/tests/large-cert.der deleted file mode 100644 index 01ec76c5544c36959f2b5b5c9efb0c6f34965da1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1849 zcmXqLVmCEtVv}9K%*4pVB*Oa0JJj=Bz&7(bq4&K@`%>S(iu`84%f_kI=F#?@mywa1 zmBFBiNyCuafRl|ml!Z;0Da6&VvD=`r1H|RvX>15_4GtMdjBpM6U~rA6fjcN~hL{XzOw&F#z!RoC3O{i0Il z^RrhgKmKlQ4gHu}=yC1nJZ1Yp!=D*>UU4(lxO;l%In41iFgt(Z@vDRPoLmAQY~CHn z&cw{fz_>WrAkaXTjX6}7k420{q*glPKAZcY52?MbP z>iXykgVaEA6Lt z6)ygAJ6pijr*5ys#M#crq<39eb#rNe4Dw_`E8$CzZ!@*$fo~# zbwGXAO7n~v88d>kdHB-*M=9MnDzNg{e%(p#=J%7A&M0r(V0bFAm+j@P*iHksb%wo; zlRO>I7M$1r*YwOKFzZ*Zs$W(7yT?0jm2UL9{ZH!S%$q_FMJ`qTZ1+tS?Y+Nm%cRPRgVop7_i>l9L$&YSRRaZp(Jj=-va33rR)7j9x; o;F_)f@$U_R$>!ZhUkd->@-OHQp0WCm&5e@^M; Date: Tue, 4 Apr 2023 10:04:43 +0200 Subject: [PATCH 06/10] Update to flushing streaming api --- Cargo.toml | 2 +- src/state.rs | 34 ++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3763d61..22605c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ log-warn = [] log-error = [] [patch.crates-io] -trussed = { git = "https://github.com/sosthene-nitrokey/trussed", rev = "25ae084251b76bacfa8919eb8"} +trussed = { git = "https://github.com/sosthene-nitrokey/trussed", rev = "3eeda2a21106cb31120e08f5ae67a490b3d47bd6" } trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", tag = "v0.2.1"} littlefs2 = { git = "https://github.com/Nitrokey/littlefs2", tag = "v0.3.2-nitrokey-2" } diff --git a/src/state.rs b/src/state.rs index ed2b4f2..5c6c58c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -773,8 +773,8 @@ impl ContainerStorage { } } - pub fn save( - self, + fn save_inner( + &self, client: &mut impl trussed::Client, bytes: &[u8], storage: Location, @@ -789,10 +789,12 @@ impl ContainerStorage { }); msg = chunks.next().unwrap_or_default(); let mut written = msg.len(); - try_syscall!(client.write_file(storage, self.path(), msg, None)).map_err(|_err| { - error!("Failed to store data: {_err:?}"); - Status::UnspecifiedNonpersistentExecutionError - })?; + try_syscall!(client.start_chunked_write(storage, self.path(), msg, None)).map_err( + |_err| { + error!("Failed to store data: {_err:?}"); + Status::UnspecifiedNonpersistentExecutionError + }, + )?; for chunk in chunks { let off = written; written += chunk.len(); @@ -809,4 +811,24 @@ impl ContainerStorage { } Ok(()) } + + pub fn save( + self, + client: &mut impl trussed::Client, + bytes: &[u8], + storage: Location, + ) -> Result<(), Status> { + let res = self.save_inner(client, bytes, storage); + if res.is_ok() { + try_syscall!(client.flush_chunks(storage, self.path())) + .map(drop) + .map_err(|_err| { + error!("Failed to flush data: {_err:?}"); + Status::UnspecifiedNonpersistentExecutionError + }) + } else { + syscall!(client.abort_chunked_write(storage, self.path())); + res + } + } } From fffbe7761464fd6ef060d10c2fe30e167124d390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 4 Apr 2023 14:26:21 +0200 Subject: [PATCH 07/10] Use trussed's util for writing large files --- Cargo.toml | 2 +- src/state.rs | 56 +++++----------------------------------------------- 2 files changed, 6 insertions(+), 52 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22605c1..986595d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ log-warn = [] log-error = [] [patch.crates-io] -trussed = { git = "https://github.com/sosthene-nitrokey/trussed", rev = "3eeda2a21106cb31120e08f5ae67a490b3d47bd6" } +trussed = { git = "https://github.com/sosthene-nitrokey/trussed", rev = "fa26fa984008276909d426b9d902f5fa05c36f1e" } trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", tag = "v0.2.1"} littlefs2 = { git = "https://github.com/Nitrokey/littlefs2", tag = "v0.3.2-nitrokey-2" } diff --git a/src/state.rs b/src/state.rs index 5c6c58c..0009a3f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -14,6 +14,7 @@ use trussed::{ config::MAX_MESSAGE_LENGTH, syscall, try_syscall, types::{KeyId, KeySerialization, Location, Mechanism, PathBuf, StorageAttributes}, + utils, }; use trussed_auth::AuthClient; @@ -773,62 +774,15 @@ impl ContainerStorage { } } - fn save_inner( - &self, - client: &mut impl trussed::Client, - bytes: &[u8], - storage: Location, - ) -> Result<(), Status> { - let mut msg = Bytes::new(); - let chunk_size = msg.capacity(); - let mut chunks = bytes.chunks(chunk_size).map(|chunk| { - Bytes::from( - heapless::Vec::try_from(chunk) - .expect("Iteration over chunks yields maximum of chunk_size"), - ) - }); - msg = chunks.next().unwrap_or_default(); - let mut written = msg.len(); - try_syscall!(client.start_chunked_write(storage, self.path(), msg, None)).map_err( - |_err| { - error!("Failed to store data: {_err:?}"); - Status::UnspecifiedNonpersistentExecutionError - }, - )?; - for chunk in chunks { - let off = written; - written += chunk.len(); - try_syscall!(client.write_file_chunk( - storage, - self.path(), - chunk, - OpenSeekFrom::Start(off as u32) - )) - .map_err(|_err| { - error!("Failed to store data: {_err:?}"); - Status::UnspecifiedNonpersistentExecutionError - })?; - } - Ok(()) - } - pub fn save( self, client: &mut impl trussed::Client, bytes: &[u8], storage: Location, ) -> Result<(), Status> { - let res = self.save_inner(client, bytes, storage); - if res.is_ok() { - try_syscall!(client.flush_chunks(storage, self.path())) - .map(drop) - .map_err(|_err| { - error!("Failed to flush data: {_err:?}"); - Status::UnspecifiedNonpersistentExecutionError - }) - } else { - syscall!(client.abort_chunked_write(storage, self.path())); - res - } + utils::write_all(client, storage, self.path(), bytes, None).map_err(|_err| { + error!("Failed to write data object: {:?}", _err); + Status::UnspecifiedNonpersistentExecutionError + }) } } From 9362e9f2f52421da76011242c8728fe8e192414b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 13 Apr 2023 10:22:13 +0200 Subject: [PATCH 08/10] Fix compilation --- src/state.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/state.rs b/src/state.rs index 0009a3f..0e00b84 100644 --- a/src/state.rs +++ b/src/state.rs @@ -661,7 +661,9 @@ fn load_if_exists_streaming( read_len += r.data.len(); buffer.expand(&r.data)?; } - Err(_err) => error!("Failed to read chunk: {:?}", _err), + Err(_err) => { + error!("Failed to read chunk: {:?}", _err); + } } } From aeeafbabbb48ec11e46d258b2dab3d8a79058101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 13 Apr 2023 10:40:07 +0200 Subject: [PATCH 09/10] Fix reuse compliance --- tests/large-cert.pem | 41 --------------------------------------- tests/pivy.rs | 46 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 44 deletions(-) delete mode 100644 tests/large-cert.pem diff --git a/tests/large-cert.pem b/tests/large-cert.pem deleted file mode 100644 index 293073a..0000000 --- a/tests/large-cert.pem +++ /dev/null @@ -1,41 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIHNTCCBh2gAwIBAgIUBeJLVUnOULY3fhLvjaWOZe/qWfYwDQYJKoZIhvcNAQEL -BQAwggIoMQswCQYDVQQGEwJURTGBizCBiAYDVQQIDIGAVEVTVFRFU1RURVNUVEVT -VFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVT -VFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVT -VFRFU1RURVNUVEVTVFRFU1QxgYswgYgGA1UEBwyBgFRFU1RURVNUVEVTVFRFU1RU -RVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RU -RVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RU -RVNUVEVTVFRFU1RURVNUMUkwRwYDVQQKDEBURVNUVEVTVFRFU1RURVNUVEVTVFRF -U1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUMUk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QEAjEZtjVvccB3j/ZZWdor3YDWou0Ww -JWc0A7bAaFKK2cWjY08atejeoeuOvqezAejhSgqA9R60B8LJSGFg6y3D3QJ3JOOx -8ZodYIl0/QNfIHG1oaG9hp7zCaGlqyV6J+Bn1Sm3A6ElrNjb6Hkc8+bqqfH7gZbW -w3vDgx6u3sgnB6QnP/Zg9+H/1Ws3rCEyU8eaJhQpi2JBzODLDGmVkoo07U4D/7TG -nu5LgPBIRV0vmiCejMtpYhPCGAnTSdbhvKkNJAkZ8s225YlLFACgTVVmpcGb+cKu -RVXxZXFI1sWeIz9RMflobkpemKxHSUtuQJxJMDbPyOPqwd5CRFHgs7tRBwIDAQAB -o1MwUTAdBgNVHQ4EFgQUfRto8fDPPLA/ok5lgK7MypPSh54wHwYDVR0jBBgwFoAU -fRto8fDPPLA/ok5lgK7MypPSh54wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0B -AQsFAAOCAQEAWyy0drsTRfU8/J+rrX4trDb9o6iy7dSHyrpxo/TbaxBFTH69OJGb -Q8YbutSq1a4m4UaSnGJYwarVCxmntjciz7byhfUwFEAdZ/rqwCeaqTdomGiYUisM -Dmf/WiLYxRCpxr8tkkc332OlmHeBsDHKYY0G6dpdiTAGrjGNQZJJQc1wzy/+guZE -UWr6jSVOel/u47jadbFK2/4a8ZnZEuEU0nn5h01lFY3fvrHr93Z3yzZ60LKeMszs -SmDyoVI1XfNSJd8YbshGP91CVHFnDWDqo1JWV7hRev5g3XJfobIAAAqbL/H92BCT -N4vF6RP8Ck9wj1OYq/w82MkgxOPleUju4Q== ------END CERTIFICATE----- diff --git a/tests/pivy.rs b/tests/pivy.rs index d7435a5..e4d3c3f 100644 --- a/tests/pivy.rs +++ b/tests/pivy.rs @@ -9,7 +9,6 @@ use card::with_vsc; use expectrl::{spawn, Eof, Regex, WaitStatus}; -use std::include_str; use std::io::{Read, Write}; use std::process::{Command, Stdio}; @@ -78,7 +77,48 @@ fn ecdh() { }); } -const LARGE_CERT: &str = include_str!("large-cert.pem"); +const LARGE_CERT: &str = "-----BEGIN CERTIFICATE----- +MIIHNTCCBh2gAwIBAgIUBeJLVUnOULY3fhLvjaWOZe/qWfYwDQYJKoZIhvcNAQEL +BQAwggIoMQswCQYDVQQGEwJURTGBizCBiAYDVQQIDIGAVEVTVFRFU1RURVNUVEVT +VFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVT +VFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVT +VFRFU1RURVNUVEVTVFRFU1QxgYswgYgGA1UEBwyBgFRFU1RURVNUVEVTVFRFU1RU +RVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RU +RVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RU +RVNUVEVTVFRFU1RURVNUMUkwRwYDVQQKDEBURVNUVEVTVFRFU1RURVNUVEVTVFRF +U1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUMUkwRwYD +VQQLDEBURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVT +VFRFU1RURVNUVEVTVFRFU1RURVNUMUkwRwYDVQQDDEBURVNUVEVTVFRFU1RURVNU +VEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNU +MRwwGgYJKoZIhvcNAQkBFg10ZXN0QHRlc3QuY29tMB4XDTIzMDMzMDA5NDg0NFoX +DTI0MDMyOTA5NDg0NFowggIoMQswCQYDVQQGEwJURTGBizCBiAYDVQQIDIGAVEVT +VFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVT +VFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RURVNUVEVTVFRFU1RUR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K7MypPSh54wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0B +AQsFAAOCAQEAWyy0drsTRfU8/J+rrX4trDb9o6iy7dSHyrpxo/TbaxBFTH69OJGb +Q8YbutSq1a4m4UaSnGJYwarVCxmntjciz7byhfUwFEAdZ/rqwCeaqTdomGiYUisM +Dmf/WiLYxRCpxr8tkkc332OlmHeBsDHKYY0G6dpdiTAGrjGNQZJJQc1wzy/+guZE +UWr6jSVOel/u47jadbFK2/4a8ZnZEuEU0nn5h01lFY3fvrHr93Z3yzZ60LKeMszs +SmDyoVI1XfNSJd8YbshGP91CVHFnDWDqo1JWV7hRev5g3XJfobIAAAqbL/H92BCT +N4vF6RP8Ck9wj1OYq/w82MkgxOPleUju4Q== +-----END CERTIFICATE----- +"; #[test_log::test] fn large_cert() { @@ -103,7 +143,7 @@ fn large_cert() { let mut stdout = p.stdout.take().unwrap(); let mut buf = String::new(); stdout.read_to_string(&mut buf).unwrap(); - assert_eq!(buf, LARGE_CERT); + assert_eq!(&buf, LARGE_CERT); assert_eq!(p.wait().unwrap().code(), Some(0)); }); } From d5b01d5bb3325c6d54e063c30ac906f6ffcb6697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 13 Apr 2023 14:25:27 +0200 Subject: [PATCH 10/10] Use tagged version of trussed --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 986595d..5a8d05b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ log-warn = [] log-error = [] [patch.crates-io] -trussed = { git = "https://github.com/sosthene-nitrokey/trussed", rev = "fa26fa984008276909d426b9d902f5fa05c36f1e" } +trussed = { git = "https://github.com/Nitrokey/trussed", tag = "v0.1.0-nitrokey.9" } trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", tag = "v0.2.1"} littlefs2 = { git = "https://github.com/Nitrokey/littlefs2", tag = "v0.3.2-nitrokey-2" }