Skip to content

Share parsed mbedtls_x509_crt and mbedtls_pk_context between sessions #75

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ jobs:
./
xtask

- name: Detect esp-mbedtls-sys/ changes
uses: dorny/paths-filter@v3
id: detect-changes
with:
filters: |
libs:
- 'esp-mbedtls-sys/**'

- name: Install Rust for Xtensa and Espressif LLVM installation (optional)
uses: esp-rs/[email protected]
with:
Expand All @@ -77,14 +85,6 @@ jobs:
}}

# ==== Build libs ====
- name: Detect esp-mbedtls-sys/ changes
uses: dorny/paths-filter@v3
id: detect-changes
with:
filters: |
libs:
- 'esp-mbedtls-sys/**'

- name: Build libraries and bindings
if: |
steps.detect-changes.outputs.libs == 'true' ||
Expand Down
2 changes: 1 addition & 1 deletion esp-mbedtls-sys/gen/include/soc/esp32/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
*
* Enable this layer to allow use of alternative memory allocators.
*/
//#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_MEMORY

/**
* \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Expand Down
2 changes: 1 addition & 1 deletion esp-mbedtls-sys/gen/include/soc/esp32c3/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
*
* Enable this layer to allow use of alternative memory allocators.
*/
//#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_MEMORY

/**
* \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Expand Down
2 changes: 1 addition & 1 deletion esp-mbedtls-sys/gen/include/soc/esp32s2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
*
* Enable this layer to allow use of alternative memory allocators.
*/
//#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_MEMORY

/**
* \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Expand Down
2 changes: 1 addition & 1 deletion esp-mbedtls-sys/gen/include/soc/esp32s3/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
*
* Enable this layer to allow use of alternative memory allocators.
*/
//#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_MEMORY

/**
* \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Expand Down
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/riscv32imc-unknown-none-elf/libmbedtls.a
Binary file not shown.
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32-none-elf/libmbedcrypto.a
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32-none-elf/libmbedtls.a
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32-none-elf/libmbedx509.a
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32s2-none-elf/libmbedcrypto.a
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32s2-none-elf/libmbedtls.a
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32s2-none-elf/libmbedx509.a
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32s3-none-elf/libmbedcrypto.a
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32s3-none-elf/libmbedtls.a
Binary file not shown.
Binary file modified esp-mbedtls-sys/libs/xtensa-esp32s3-none-elf/libmbedx509.a
Binary file not shown.
50 changes: 50 additions & 0 deletions esp-mbedtls-sys/src/extra_impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Provide extra implementations to the generated bindings
use core::ffi::{c_char, c_int, CStr};

impl core::fmt::Debug for crate::bindings::mbedtls_x509_time {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
// ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
"{:04}-{:02}-{:02}T{:02}:{:02}:{:02}Z",
self.year, self.mon, self.day, self.hour, self.min, self.sec
)
}
}

impl core::fmt::Debug for crate::bindings::mbedtls_x509_crt {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut crt: *const crate::bindings::mbedtls_x509_crt = self;
let mut index = 0;
let mut buf = [0u8; 1024];
while !crt.is_null() {
index += 1;
buf.fill(0);
let buf_ptr = buf.as_mut_ptr() as *mut c_char;
let ret: c_int = unsafe {
crate::bindings::mbedtls_x509_crt_info(buf_ptr, buf.len() - 1, c"".as_ptr(), crt)
};
if ret < 0 {
writeln!(
f,
"Certificate #{}: mbedtls_x509_crt_info failed with code {}",
index, ret
)?;
} else {
let cstr = unsafe { CStr::from_ptr(buf_ptr) };
match cstr.to_str() {
Ok(s) => write!(f, "\nCertificate #{}:\n{}", index, s)?,
Err(_) => {
writeln!(f, "\nCertificate #{}: mbedtls_x509_crt_info returned invalid UTF-8 in output", index)?;
let slice = &buf[..buf.iter().position(|&b| b == 0).unwrap_or(buf.len())];
for line in slice.split(|&b| b == b'\n') {
writeln!(f, "{:?}", core::str::from_utf8(line))?;
}
}
}
}
crt = unsafe { (*crt).next };
}
Ok(())
}
}
1 change: 1 addition & 0 deletions esp-mbedtls-sys/src/include/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub const RE_DUP_MAX: u32 = 255;
pub const MB_LEN_MAX: u32 = 1;
pub const NL_ARGMAX: u32 = 32;
pub const _POSIX2_RE_DUP_MAX: u32 = 255;
pub const CHAR_MIN: u32 = 0;
pub const __int20: u32 = 2;
pub const __int20__: u32 = 2;
pub const __INT8: &[u8; 3] = b"hh\0";
Expand Down
177 changes: 19 additions & 158 deletions esp-mbedtls-sys/src/include/esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,127 +199,8 @@ pub const PSA_WANT_KEY_TYPE_DERIVE: u32 = 1;
pub const PSA_WANT_KEY_TYPE_PASSWORD: u32 = 1;
pub const PSA_WANT_KEY_TYPE_PASSWORD_HASH: u32 = 1;
pub const PSA_WANT_KEY_TYPE_RAW_DATA: u32 = 1;
pub const _LIBC_LIMITS_H_: u32 = 1;
pub const __NEWLIB_H__: u32 = 1;
pub const _NEWLIB_VERSION_H__: u32 = 1;
pub const _NEWLIB_VERSION: &[u8; 6] = b"4.3.0\0";
pub const __NEWLIB__: u32 = 4;
pub const __NEWLIB_MINOR__: u32 = 3;
pub const __NEWLIB_PATCHLEVEL__: u32 = 0;
pub const _ATEXIT_DYNAMIC_ALLOC: u32 = 1;
pub const _FSEEK_OPTIMIZATION: u32 = 1;
pub const _FVWRITE_IN_STREAMIO: u32 = 1;
pub const _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL: u32 = 1;
pub const _HAVE_INITFINI_ARRAY: u32 = 1;
pub const _HAVE_LONG_DOUBLE: u32 = 1;
pub const _ICONV_ENABLED: u32 = 1;
pub const _MB_LEN_MAX: u32 = 1;
pub const _NANO_MALLOC: u32 = 1;
pub const _REENT_CHECK_VERIFY: u32 = 1;
pub const _RETARGETABLE_LOCKING: u32 = 1;
pub const _UNBUF_STREAM_OPT: u32 = 1;
pub const _WANT_IO_C99_FORMATS: u32 = 1;
pub const _WANT_IO_LONG_LONG: u32 = 1;
pub const _WANT_IO_POS_ARGS: u32 = 1;
pub const _WANT_REENT_BACKWARD_BINARY_COMPAT: u32 = 1;
pub const _WANT_REENT_SMALL: u32 = 1;
pub const _WANT_USE_GDTOA: u32 = 1;
pub const _DEFAULT_SOURCE: u32 = 1;
pub const _POSIX_SOURCE: u32 = 1;
pub const _POSIX_C_SOURCE: u32 = 200809;
pub const _ATFILE_SOURCE: u32 = 1;
pub const __ATFILE_VISIBLE: u32 = 1;
pub const __BSD_VISIBLE: u32 = 1;
pub const __GNU_VISIBLE: u32 = 0;
pub const __ISO_C_VISIBLE: u32 = 2011;
pub const __LARGEFILE_VISIBLE: u32 = 0;
pub const __MISC_VISIBLE: u32 = 1;
pub const __POSIX_VISIBLE: u32 = 200809;
pub const __SVID_VISIBLE: u32 = 1;
pub const __XSI_VISIBLE: u32 = 0;
pub const __SSP_FORTIFY_LEVEL: u32 = 0;
pub const _POSIX_THREADS: u32 = 1;
pub const _POSIX_TIMEOUTS: u32 = 1;
pub const _POSIX_TIMERS: u32 = 1;
pub const _POSIX_MONOTONIC_CLOCK: u32 = 200112;
pub const _POSIX_CLOCK_SELECTION: u32 = 200112;
pub const _UNIX98_THREAD_MUTEX_ATTRIBUTES: u32 = 1;
pub const _POSIX_READER_WRITER_LOCKS: u32 = 200112;
pub const __have_longlong64: u32 = 1;
pub const __have_long32: u32 = 1;
pub const ___int8_t_defined: u32 = 1;
pub const ___int16_t_defined: u32 = 1;
pub const ___int32_t_defined: u32 = 1;
pub const ___int64_t_defined: u32 = 1;
pub const ___int_least8_t_defined: u32 = 1;
pub const ___int_least16_t_defined: u32 = 1;
pub const ___int_least32_t_defined: u32 = 1;
pub const ___int_least64_t_defined: u32 = 1;
pub const __GNUCLIKE_ASM: u32 = 3;
pub const __GNUCLIKE___TYPEOF: u32 = 1;
pub const __GNUCLIKE___SECTION: u32 = 1;
pub const __GNUCLIKE_CTOR_SECTION_HANDLING: u32 = 1;
pub const __GNUCLIKE_BUILTIN_CONSTANT_P: u32 = 1;
pub const __GNUCLIKE_BUILTIN_VARARGS: u32 = 1;
pub const __GNUCLIKE_BUILTIN_STDARG: u32 = 1;
pub const __GNUCLIKE_BUILTIN_VAALIST: u32 = 1;
pub const __GNUC_VA_LIST_COMPATIBILITY: u32 = 1;
pub const __GNUCLIKE_BUILTIN_NEXT_ARG: u32 = 1;
pub const __GNUCLIKE_BUILTIN_MEMCPY: u32 = 1;
pub const __CC_SUPPORTS_INLINE: u32 = 1;
pub const __CC_SUPPORTS___INLINE: u32 = 1;
pub const __CC_SUPPORTS___INLINE__: u32 = 1;
pub const __CC_SUPPORTS___FUNC__: u32 = 1;
pub const __CC_SUPPORTS_WARNING: u32 = 1;
pub const __CC_SUPPORTS_VARADIC_XXX: u32 = 1;
pub const __CC_SUPPORTS_DYNAMIC_ARRAY_INIT: u32 = 1;
pub const ARG_MAX: u32 = 65536;
pub const CHILD_MAX: u32 = 40;
pub const LINK_MAX: u32 = 32767;
pub const MAX_CANON: u32 = 255;
pub const MAX_INPUT: u32 = 255;
pub const NAME_MAX: u32 = 255;
pub const NGROUPS_MAX: u32 = 16;
pub const OPEN_MAX: u32 = 64;
pub const PATH_MAX: u32 = 1024;
pub const PIPE_BUF: u32 = 512;
pub const IOV_MAX: u32 = 1024;
pub const BC_BASE_MAX: u32 = 99;
pub const BC_DIM_MAX: u32 = 2048;
pub const BC_SCALE_MAX: u32 = 99;
pub const BC_STRING_MAX: u32 = 1000;
pub const COLL_WEIGHTS_MAX: u32 = 0;
pub const EXPR_NEST_MAX: u32 = 32;
pub const LINE_MAX: u32 = 2048;
pub const RE_DUP_MAX: u32 = 255;
pub const MB_LEN_MAX: u32 = 1;
pub const NL_ARGMAX: u32 = 32;
pub const _POSIX2_RE_DUP_MAX: u32 = 255;
pub const CHAR_MIN: u32 = 0;
pub const __int20: u32 = 2;
pub const __int20__: u32 = 2;
pub const __INT8: &[u8; 3] = b"hh\0";
pub const __INT16: &[u8; 2] = b"h\0";
pub const __INT64: &[u8; 3] = b"ll\0";
pub const __FAST8: &[u8; 3] = b"hh\0";
pub const __FAST16: &[u8; 2] = b"h\0";
pub const __FAST64: &[u8; 3] = b"ll\0";
pub const __LEAST8: &[u8; 3] = b"hh\0";
pub const __LEAST16: &[u8; 2] = b"h\0";
pub const __LEAST64: &[u8; 3] = b"ll\0";
pub const __int8_t_defined: u32 = 1;
pub const __int16_t_defined: u32 = 1;
pub const __int32_t_defined: u32 = 1;
pub const __int64_t_defined: u32 = 1;
pub const __int_least8_t_defined: u32 = 1;
pub const __int_least16_t_defined: u32 = 1;
pub const __int_least32_t_defined: u32 = 1;
pub const __int_least64_t_defined: u32 = 1;
pub const __int_fast8_t_defined: u32 = 1;
pub const __int_fast16_t_defined: u32 = 1;
pub const __int_fast32_t_defined: u32 = 1;
pub const __int_fast64_t_defined: u32 = 1;
pub const WINT_MIN: u32 = 0;
pub const MBEDTLS_ERR_MPI_FILE_IO_ERROR: i32 = -2;
pub const MBEDTLS_ERR_MPI_BAD_INPUT_DATA: i32 = -4;
pub const MBEDTLS_ERR_MPI_INVALID_CHARACTER: i32 = -6;
Expand Down Expand Up @@ -1062,26 +943,25 @@ pub const MBEDTLS_CTR_DRBG_MAX_SEED_INPUT: u32 = 384;
pub const MBEDTLS_CTR_DRBG_PR_OFF: u32 = 0;
pub const MBEDTLS_CTR_DRBG_PR_ON: u32 = 1;
pub const MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN: u32 = 0;
pub type __int8_t = crate::c_types::c_schar;
pub type __uint8_t = crate::c_types::c_uchar;
pub type __int16_t = crate::c_types::c_short;
pub type __uint16_t = crate::c_types::c_ushort;
pub type __int32_t = crate::c_types::c_int;
pub type __uint32_t = crate::c_types::c_uint;
pub type __int64_t = crate::c_types::c_longlong;
pub type __uint64_t = crate::c_types::c_ulonglong;
pub type __int_least8_t = crate::c_types::c_schar;
pub type __uint_least8_t = crate::c_types::c_uchar;
pub type __int_least16_t = crate::c_types::c_short;
pub type __uint_least16_t = crate::c_types::c_ushort;
pub type __int_least32_t = crate::c_types::c_int;
pub type __uint_least32_t = crate::c_types::c_uint;
pub type __int_least64_t = crate::c_types::c_longlong;
pub type __uint_least64_t = crate::c_types::c_ulonglong;
pub type __intmax_t = crate::c_types::c_longlong;
pub type __uintmax_t = crate::c_types::c_ulonglong;
pub type __intptr_t = crate::c_types::c_int;
pub type __uintptr_t = crate::c_types::c_uint;
pub type int_least64_t = i64;
pub type uint_least64_t = u64;
pub type int_fast64_t = i64;
pub type uint_fast64_t = u64;
pub type int_least32_t = i32;
pub type uint_least32_t = u32;
pub type int_fast32_t = i32;
pub type uint_fast32_t = u32;
pub type int_least16_t = i16;
pub type uint_least16_t = u16;
pub type int_fast16_t = i16;
pub type uint_fast16_t = u16;
pub type int_least8_t = i8;
pub type uint_least8_t = u8;
pub type int_fast8_t = i8;
pub type uint_fast8_t = u8;
pub type intmax_t = crate::c_types::c_longlong;
pub type uintmax_t = crate::c_types::c_ulonglong;
pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int;
pub type wchar_t = crate::c_types::c_int;
#[repr(C)]
#[repr(align(16))]
Expand All @@ -1091,25 +971,6 @@ pub struct max_align_t {
pub __bindgen_padding_0: u64,
pub __clang_max_align_nonce2: u128,
}
pub type intmax_t = __intmax_t;
pub type uintmax_t = __uintmax_t;
pub type int_least8_t = __int_least8_t;
pub type uint_least8_t = __uint_least8_t;
pub type int_least16_t = __int_least16_t;
pub type uint_least16_t = __uint_least16_t;
pub type int_least32_t = __int_least32_t;
pub type uint_least32_t = __uint_least32_t;
pub type int_least64_t = __int_least64_t;
pub type uint_least64_t = __uint_least64_t;
pub type int_fast8_t = crate::c_types::c_schar;
pub type uint_fast8_t = crate::c_types::c_uchar;
pub type int_fast16_t = crate::c_types::c_short;
pub type uint_fast16_t = crate::c_types::c_ushort;
pub type int_fast32_t = crate::c_types::c_int;
pub type uint_fast32_t = crate::c_types::c_uint;
pub type int_fast64_t = crate::c_types::c_longlong;
pub type uint_fast64_t = crate::c_types::c_ulonglong;
pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int;
extern "C" {
/// \brief Securely zeroize a buffer
///
Expand Down
1 change: 1 addition & 0 deletions esp-mbedtls-sys/src/include/esp32s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub const RE_DUP_MAX: u32 = 255;
pub const MB_LEN_MAX: u32 = 1;
pub const NL_ARGMAX: u32 = 32;
pub const _POSIX2_RE_DUP_MAX: u32 = 255;
pub const CHAR_MIN: u32 = 0;
pub const __int20: u32 = 2;
pub const __int20__: u32 = 2;
pub const __INT8: &[u8; 3] = b"hh\0";
Expand Down
1 change: 1 addition & 0 deletions esp-mbedtls-sys/src/include/esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub const RE_DUP_MAX: u32 = 255;
pub const MB_LEN_MAX: u32 = 1;
pub const NL_ARGMAX: u32 = 32;
pub const _POSIX2_RE_DUP_MAX: u32 = 255;
pub const CHAR_MIN: u32 = 0;
pub const __int20: u32 = 2;
pub const __int20__: u32 = 2;
pub const __INT8: &[u8; 3] = b"hh\0";
Expand Down
1 change: 1 addition & 0 deletions esp-mbedtls-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use esp_wifi as _;

#[cfg(not(target_os = "espidf"))]
mod c_types;
mod extra_impls;

#[allow(
non_camel_case_types,
Expand Down
Loading