Hi,
I have an inhouse developed secure authentication program that uses certificate for authentication. I have used mbedtls library for the x.509 certificate verification purpose. In our custom PKI we have only three level of certificates, Root-CA -> Intermediate-CA -> Device-Cert.
The embedded device has very limited memory, so instead of sending whole certificate chain, the devices communicates intermediate_CA and device cert (in der format base64 encoded) in separate packet. Root-CA will be available on node as trusted-ca. Intermediate is verified against Root; then device cert is verified against intermediate.
The problem is, the poc developed on linux platform is working fine - but on embedded platform I encounter either 0x3b00(parsing failed) or 0x2700(with flag 8). Also the error code are inconsistent.
I verified the integrity of packet with certificate using crc16. So no chance of certificate getting corrupted. Also verified the certificate's base64 format integrity using crc16.
All certificates are sha256WithRSAEncryption; RSA Public-Key: (4096 bit)
Attached config.h on target platform for reference - could you help me if anything wrong with configuration.
While trying to trace, the flag was set from x509_crt.c from below code.
/* No parent? We're done here */
if( parent == NULL )
{
printf("NO_PARENT\r\n");
*flags |= MBEDTLS_X509_BADCERT_NOT_TRUSTED;
return( 0 );
}
Any clue would be helpful.
Thanks,
Gopi Krishnan
Hi All,
A gentle reminder that the US-Europe timezone-friendly MBed TLS Tech forum
is next Monday at 4:30 PM UK time. Invite details can be found on the
online calendar here <https://www.trustedfirmware.org/meetings/>.
If you have any topics, please let Dave Rodgman know. :)
Best regards,
Don Harbin
TrustedFirmware Community Manager
don.harbin(a)linaro.org
Hi, I recently had to do some PKCS#7 signature validation and was
disappointed to find that it didn't just work. After digging through
RFCs to figure out the myriad of things I'd done wrong I was also left
with a lack of 3 features in mbedtls:
1. The full certificate chain was not being loaded and explicitly not
supported. I believe this is in error since the certificate was never
actually used anywhere, meaning it basically errored out for no reason.
Since this certificate chain also contains the key used to validate the
signature in my case that presented a pretty fundamental problem.
2. signedAttributes were not supported at all.
3. All the fields in mbedtls_pkcs7 and its associated structures are
marked as MBEDTLS_PRIVATE. I need to inspect both the certificates and
the signedAttributes and would rather not have to parse the entire DER
myself.
I have attached patches implementing the first two. I believe I've done
so without altering the behavior of the calls although I'm a bit unsure
as to why mbedtls_x509_crt_verify doesn't take a const mbedtls_x509_crt.
The third issue is a matter of policy and I don't know what your opinion
on it is. For the moment I can at least get away with poking at the
internal fields.
I have tested it on several signatures, one of which I have included
here and I apologize in advance for the absolute spew but I thought it
better than attaching even more files.
The data:
3059301306072A8648CE3D020106082A8648CE3D030107034200041B58AEE5B7C868AE0EED554133774B7C16802062EC2EB5A1A053318A9ED7DB943CE1F877671DADCFEB4D3171ACC2714ECBC0C0BCADE0569DF7CD0031623AF1BBDE72D8FFF60EC6D04B0D6C93658FC40F4AF2E22E1F68BF1A500FE00A94B804B7CA1DD7AF825C000FCF77A0ABB6918D2DF55C7A3CBC90BE14C59D8EE62A02B988DF7F32117770012AE362C03FB3AA3918AB9D10BE78442EFA7FCBA3CB02D6E196CE4137C6C3F280D963A5CD050EAC8871B3EB2C4500916FB3E39840D8EB198D58F49A434B2736385075BF9397405360B8694D0AD1E5DA8291F9EA47743F803F4A409EA72C2DF94F43DB60A0EAB8A8BD409C4D684200778B23D2A8126827995C3A80CAACA4AB7077266CED79BF91725330C9FCE3B8F1F5316C08C17B9994CF0ECB26D87A5C1F8FEB1FA737F78794895F6C5153B575EF8E95A8D433FD9486AA6C2B46ED6633D2BE0938202B99BEC21895018FB6FC59BAD662815A2C65200B8B1BAA4B69A8C89204B1EA70094026E9F710E599E14941476C8CD2E2879CF58E850DC732A506885F646BB9BE96B7A65355A6A9B907956E6DF65336504300CF062BA9DE50
It's SHA2-256 hash is:
C76DE7AF191C16E01405CE8FE89136EB60AC035B3DDE34ACF65220AC7C3CA619
If you decode the signature DER you'll see a matching id-messageDigest
in the signedAttributes towards the very bottom.
The signature in DER format:
3082089B06092A864886F70D010702A082088C30820888020101310D300B0609608648016503040201300B06092A864886F70D010701A08206D9308203E330820388A00302010202084C304149519D5436300A06082A8648CE3D040302307A312E302C06035504030C254170706C65204170706C69636174696F6E20496E746567726174696F6E204341202D20473331263024060355040B0C1D4170706C652043657274696669636174696F6E20417574686F7269747931133011060355040A0C0A4170706C6520496E632E310B3009060355040613025553301E170D3139303531383031333235375A170D3234303531363031333235375A305F3125302306035504030C1C6563632D736D702D62726F6B65722D7369676E5F5543342D50524F4431143012060355040B0C0B694F532053797374656D7331133011060355040A0C0A4170706C6520496E632E310B30090603550406130255533059301306072A8648CE3D020106082A8648CE3D03010703420004C21577EDEBD6C7B2218F68DD7090A1218DC7B0BD6F2C283D846095D94AF4A5411B83420ED811F3407E83331F1C54C3F7EB3220D6BAD5D4EFF49289893E7C0F13A38202113082020D300C0603551D130101FF04023000301F0603551D2304183016801423F249C44F93E4EF27E6C4F6286C3FA2BBFD2E4B304506082B0601
050507010104393037303506082B060105050730018629687474703A2F2F6F6373702E6170706C652E636F6D2F6F63737030342D6170706C65616963613330323082011D0603551D2004820114308201103082010C06092A864886F7636405013081FE3081C306082B060105050702023081B60C81B352656C69616E6365206F6E207468697320636572746966696361746520627920616E7920706172747920617373756D657320616363657074616E6365206F6620746865207468656E206170706C696361626C65207374616E64617264207465726D7320616E6420636F6E646974696F6E73206F66207573652C20636572746966696361746520706F6C69637920616E642063657274696669636174696F6E2070726163746963652073746174656D656E74732E303606082B06010505070201162A687474703A2F2F7777772E6170706C652E636F6D2F6365727469666963617465617574686F726974792F30340603551D1F042D302B3029A027A0258623687474703A2F2F63726C2E6170706C652E636F6D2F6170706C6561696361332E63726C301D0603551D0E041604149457DB6FD57481868989762F7E578507E79B5824300E0603551D0F0101FF040403020780300F06092A864886F76364061D04020500300A06082A8648CE3D0403020349003046022100BE09571FE71E1E7
35B55E5AFACB4C72FEB445F30185222C7251002B61EBD6F55022100D18B350A5DD6DD6EB1746035B11EB2CE87CFA3E6AF6CBD8380890DC82CDDAA63308202EE30820275A0030201020208496D2FBF3A98DA97300A06082A8648CE3D0403023067311B301906035504030C124170706C6520526F6F74204341202D20473331263024060355040B0C1D4170706C652043657274696669636174696F6E20417574686F7269747931133011060355040A0C0A4170706C6520496E632E310B3009060355040613025553301E170D3134303530363233343633305A170D3239303530363233343633305A307A312E302C06035504030C254170706C65204170706C69636174696F6E20496E746567726174696F6E204341202D20473331263024060355040B0C1D4170706C652043657274696669636174696F6E20417574686F7269747931133011060355040A0C0A4170706C6520496E632E310B30090603550406130255533059301306072A8648CE3D020106082A8648CE3D03010703420004F017118419D76485D51A5E25810776E880A2EFDE7BAE4DE08DFC4B93E13356D5665B35AE22D097760D224E7BBA08FD7617CE88CB76BB6670BEC8E82984FF5445A381F73081F4304606082B06010505070101043A3038303606082B06010505073001862A687474703A2F2F6F6373702E6170706C
652E636F6D2F6F63737030342D6170706C65726F6F7463616733301D0603551D0E0416041423F249C44F93E4EF27E6C4F6286C3FA2BBFD2E4B300F0603551D130101FF040530030101FF301F0603551D23041830168014BBB0DEA15833889AA48A99DEBEBDEBAFDACB24AB30370603551D1F0430302E302CA02AA0288626687474703A2F2F63726C2E6170706C652E636F6D2F6170706C65726F6F74636167332E63726C300E0603551D0F0101FF0404030201063010060A2A864886F7636406020E04020500300A06082A8648CE3D040302036700306402303ACF7283511699B186FB35C356CA62BFF417EDD90F754DA28EBEF19C815E42B789F898F79B599F98D5410D8F9DE9C2FE0230322DD54421B0A305776C5DF3383B9067FD177C2C216D964FC6726982126F54F87A7D1B99CB9B0989216106990F09921D3182018830820184020101308186307A312E302C06035504030C254170706C65204170706C69636174696F6E20496E746567726174696F6E204341202D20473331263024060355040B0C1D4170706C652043657274696669636174696F6E20417574686F7269747931133011060355040A0C0A4170706C6520496E632E310B300906035504061302555302084C304149519D5436300B0609608648016503040201A08193301806092A864886F70D010903310B06092A864
886F70D010701301C06092A864886F70D010905310F170D3233303230393231333032345A302806092A864886F70D010934311B3019300B0609608648016503040201A10A06082A8648CE3D040302302F06092A864886F70D01090431220420C76DE7AF191C16E01405CE8FE89136EB60AC035B3DDE34ACF65220AC7C3CA619300A06082A8648CE3D04030204473045022100EE9B221CD9B5EEB1C6AF4160128D099C9414440A96C855A789846599E3BDE442022005AE51DC947E0B2AA6593E8FDB9F888782C71E5BB1CB6BF3C32B79C448C6A75D
Joakim
Hi All,
A gentle reminder that the Asia-Europe timezone-friendly MBed TLS Tech
forum is next *Monday, Feb 27th at 10:00am UK time*. Invite details can be
found on the online calendar here
<https://www.trustedfirmware.org/meetings/>.
As usual, if anyone has any topics, please let Dave Rodgman, cc'd, know. :)
Best regards,
Don Harbin
TrustedFirmware Community Manager
don.harbin(a)linaro.org
Hi,
I'm using AES 128 GCM with TLS 1.2 and trying to understand the AES key expansion code for decrypting received SSL records.
I'm not an expert on AES but as I understand it, we use the IV (4 byte salt + 8 byte explicit nonce in the received message), pad to 16 bytes, increment and use this as input to the AES key expansion for the first block of ciphertext. This produces a round key per AES round (10 rounds for AES 128). We then increment our IV as input to the key expansion and generate the rounding keys for the next block.
I noticed aesni_setkey_enc_128 in aesni.c contains the Intel AES-NI instruction AESKEYGENASSIST which helps with key expansion.
However, what's confusing me is when I add a breakpoint in GDB, this function is only called once, via mbedtls_ctr_drbg_seed in ctr_drbg.c. I thought we need to do the key expansion on every block, to generate the round keys?
I kept looking at the code and I noticed mbedtls_aesni_crypt_ecb, which contains the Intel AES-NI instructions for performing decryption.
This loads the round key via ctx->buf + ctx->rk_offset but I do not see any code updating this round key per block.
Could someone please explain where the round keys are generated for each round, per block?
Thanks,
Hi All,
I have a couple of tasks which use LWIP and which get suspended for a
few seconds during TLS RSA/EC crypto. One (a primitive http server)
uses Netconn and the other (a serial to TCP data copy process) uses
sockets.
I also have a number of tasks which don't do any networking and which
run as they should, throughout. Experimentation of what priority these
need is difficult but it looks like it needs to be at/above the tasks
which invoke TLS. If their priority is 0 then TLS hangs them up as
well.
After much experimentation with RTOS priorities, this is what I found,
and I wonder if it is right:
TCP/IP applications (whether using the LWIP Netconn API or the LWIP
socket API) should run at a priority equal to or lower than that of
LWIP itself which [in this project] is osPriorityHigh (40). TCP/IP
applications can be run with a priority all the way down to
tskIDLE_PRIORITY (0).
The exception is if TLS is in use. TLS does not yield to the RTOS; you
get a solid CPU time lump of ~3 secs (STM 32F417, hardware AES only).
TLS starts in the priority of the task which invokes it, but
subsequent TLS-driven TCP/IP operations run at the priority of LWIP.
So when TLS is doing the session setup crypto, tasks of a priority
lower than LWIP get suspended. If this gap is an issue, the priority
of the relevant tasks should be equal to LWIP's. Furthermore, due to
the structure of LWIP, the priority of a task using it should not be
higher than LWIP (24) since it might cause blocking on socket (or
netconn) writes.
Does this make sense?
It looks like LWIP blocks all netconn and socket ops when TLS is using
it. Is that possible?
I am running with
#define LWIP_TCPIP_CORE_LOCKING 0
#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
#define SYS_LIGHTWEIGHT_PROT 1
as this was found to have much better granularity for task switching.
With LWIP_TCPIP_CORE_LOCKING=1 you end up with a crude mutex across
the entire API call, which is fine in a single RTOS task.
Thank you in advance for any pointers.
Peter
Hi Team,
I have a requirement to generate self signed certificate programmatically.
I have raw EDCSA key pairs generated via OP-TEE APIs.
I m trying to generate self signed certificate. I tried the example as shown in programs/x509/cert_write.c. This doesn't work for me as I have raw key pairs where as this expects the key pairs to be in either pem/der format.
I tried the following code but it throws error "0xffffdd00" when I call mbedtls_x509write_crt_der
Code to set the raw key pairs:
mbedtls_ecdh_context issuer_ctx;
mbedtls_ecdh_init(&issuer_ctx);
ret = mbedtls_ecdh_setup(&issuer_ctx, MBEDTLS_ECP_DP_SECP384R1);
if (ret != 0) {
goto exit;
}
res = TA_ECSetPublicKey(&issuer_ctx, public_keyX, public_key_Y, 48);
if (res != TEE_SUCCESS)
{
goto exit;
}
res = TA_ECSetPrivateKey(&issuer_ctx, private_key, 48);
if (res != TEE_SUCCESS)
{
goto exit;
}
Am I doing something wrong ? Please help
It would be very helpful if some working example of generating certificate programmatically is shared for my reference
Thanks,
Prithvi
Hello,
In our project we use mbedTLS together with freeRTOS. mbedTLS requires an mbedtls_ssl_context (let's say `ssl_context`) for the send (`mbedtls_ssl_write(...)`) and receive (`mbedtls_ssl_read(...)`) functions. In our project we have a freeRTOS task `A` to send data with mbedTLS and a freeRTOS task `B`to receive data with mbedTLS over the same session/interface. Both tasks use the same `ssl_context` instance. Potentially sending and receiving can happen at the same time.
Is it safe to use the same `ssl_context` instance from both taks? Or should only one task access the `ssl_context`?
At the moment we are using `mbedtls_ssl_read(...)` in blocking mode and hence the `ssl_context` cannot be protected against multiple access with a mutex because then the sending task cannot obtain the mutex as long as the receiving task is the blocked receiving state (holding the mutext).
Thank you for your help.
Best regards,
Pascal
Hello,
We intend to remove DES (including Triple-DES) in the next major version
of Mbed TLS, i.e. Mbed TLS 4.0. We do not yet have a release date, but
at the moment it seems likely that there will be a new major version in
2024. As usual, the Mbed TLS 3.x series will keep the current support
for DES, and we intend to maintain the last 3.x minor release as a
long-term support branch for 3 years.
Rationale: Most security standards deprecate DES if they do not forbid
it already. Tooling is widely available to switch to AES or other
cipher. In particular, NIST will forbid Triple-DES except to decrypt
legacy data after 31 December 2023 (following SP 800-131A
<https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf>).
We would like to remove the last 64-bit block cipher from Mbed TLS to
simplify some parts of the code and reduce the maintenance burden.
If you wish for Mbed TLS to keep supporting DES longer, please let us
know what your business case is, either by replying to this email or on
the GitHub issue: https://github.com/Mbed-TLS/mbedtls/issues/7024
Best regards,
--
Gilles Peskine
Mbed TLS developer