Ben Taylor
4565d5d4e6
Change the call to mbedtls_pk_verify_ext in pkcs7 to have a variable input cert->sig_pk
...
Signed-off-by: Ben Taylor <ben.taylor@linaro.org >
2025-10-30 13:37:09 +00:00
Ben Taylor
1b32994bef
Fix style issues
...
Signed-off-by: Ben Taylor <ben.taylor@linaro.org >
2025-10-28 07:58:37 +00:00
Ben Taylor
cef9d2d31f
Revert change to mbedtls_pk_{sign,verify}_restartable and replace with ext version
...
Signed-off-by: Ben Taylor <ben.taylor@linaro.org >
2025-10-28 07:58:37 +00:00
Ben Taylor
5e23093285
Fix code style issues
...
Signed-off-by: Ben Taylor <ben.taylor@linaro.org >
2025-10-28 07:58:37 +00:00
Ben Taylor
279dd4ab59
Remove dependencies on mbedtls_pk_verify
...
Replace mbedtls_pk_verify with mbedtls_pk_verify_restartable, as mbedtls_pk_verify has now been
removed and was origonally a pass through call to mbedtls_pk_verify_restartable.
Signed-off-by: Ben Taylor <ben.taylor@linaro.org >
2025-10-28 07:58:37 +00:00
Gilles Peskine
cd4c0d7b00
Move OID string definitions back to mbedtls/oid.h
...
Some code that parses or writes X.509 needs to know OID values. We provide a
convenient list. Don't remove this list from the public interface of the
library.
For user convenience, expose these values in the same header as before and
with the same name as before: `MBEDTLS_OID_xxx` in `<mbedtls/oid.h>`.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com >
2025-06-03 15:51:34 +02:00
Gilles Peskine
532e3ee104
Switch library and tests to the x509_oid module
...
```
git grep -l -P 'mbedtls_oid_get_(?!numeric_string\b)' | xargs perl -i -pe 's/\bmbedtls_oid_get_(?!numeric_string\b)/mbedtls_x509_oid_get_/'
./framework/scripts/code_style.py --since HEAD~1 --fix
```
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com >
2025-06-03 15:51:34 +02:00
Gilles Peskine
86a47f85fa
Switch to "x509_oid.h" in code that uses OID functions
...
Keep "mbedtls/oid.h" in code that only uses OID macros.
```
git grep -l mbedtls_oid_ '**/*.[hc]' tests/suites/*.function | xargs perl -i -pe 's!["<]mbedtls/oid\.h[">]!"x509_oid.h"!g'
```
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com >
2025-06-03 15:51:34 +02:00
Harry Ramsey
4d432d6ea5
Remove mbedtls/build_info from pkcs7.c
...
This commit removes #include "mbedtls/buildinfo.h" from pkcs7.c as it is
not needed unlike other C modules.
Signed-off-by: Harry Ramsey <harry.ramsey@arm.com >
2024-10-11 12:20:13 +01:00
Harry Ramsey
0f6bc41a22
Update includes for each library file
...
Signed-off-by: Harry Ramsey <harry.ramsey@arm.com >
2024-10-09 11:18:50 +01:00
Valerio Setti
25b282ebfe
x509: move internal functions declarations to a private header
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no >
2024-01-19 09:07:35 +01:00
Dave Rodgman
e4a6f5a7ec
Use size_t cast for pointer subtractions
...
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-11-21 17:09:46 +00:00
Dave Rodgman
16799db69a
update headers
...
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-11-02 19:47:20 +00:00
Dave Rodgman
efbc5f7322
Update wording in comments
...
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-03-13 12:15:49 +00:00
Tom Cosgrove
5c8505f061
Fix typos
...
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com >
2023-03-07 11:39:52 +00:00
Dave Rodgman
a1b2bfff46
Add clarifying comments
...
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-02-20 14:45:09 +00:00
Dave Rodgman
fc64352253
Adjust position of empty line
...
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-02-16 16:23:09 +00:00
Dave Rodgman
f691268ee9
Add missing initialisers
...
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-02-10 12:56:10 +00:00
Demi Marie Obenour
35598adb78
pkcs7: Check that hash algs are in digestAlgorithms
...
Since only a single hash algorithm is currenlty supported, this avoids
having to perform hashing more than once.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com >
2023-02-10 12:56:10 +00:00
Demi Marie Obenour
6cfc469296
pkcs7: reject signatures with internal data
...
A CMS signature can have internal data, but mbedTLS does not support
verifying such signatures. Reject them during parsing.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com >
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-02-10 12:56:10 +00:00
Demi Marie Obenour
e373a254c4
pkcs7: do not store content type OIDs
...
They will always be constant.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com >
2023-02-10 12:56:10 +00:00
Demi Marie Obenour
55d9df25ef
Simple cleanup
...
No change in behavior.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com >
2023-02-10 12:56:10 +00:00
Demi Marie Obenour
4ec8355795
Check for junk after SignedData
...
There must not be any.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com >
2023-02-10 12:56:10 +00:00
Demi Marie Obenour
aaf3c0028d
pkcs7: do not store content type OID
...
Since only one content type (signed data) is supported, storing the
content type just wastes memory.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com >
2023-02-10 12:56:10 +00:00
Demi Marie Obenour
512818b1d2
pkcs7: check that content lengths fill whole buffer
...
Otherwise invalid data could be accepted.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com >
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-02-10 12:56:10 +00:00
Dave Rodgman
78c6f40736
Fix code-style
...
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com >
2023-02-09 09:21:14 +00:00
Nick Child
14f255f332
pkcs7: Remove unnecessary dependencies
...
stdio, stdlib and string header files are not
used. Remove them.
Signed-off-by: Nick Child <nick.child@ibm.com >
2023-02-08 15:38:48 +00:00
Nick Child
3dafc6c3b3
pkcs7: Drop support for signature in contentInfo of signed data
...
The contentInfo field of PKCS7 Signed Data structures can
optionally contain the content of the signature. Per RFC 2315
it can also contain any of the PKCS7 data types. Add test and
comments making it clear that the current implementation
only supports the DATA content type and the data must be empty.
Return codes should be clear whether content was invalid or
unsupported.
Identification and fix provided by:
- Demi Marie Obenour <demiobenour@gmail.com >
- Dave Rodgman <dave.rodgman@arm.com >
Signed-off-by: Nick Child <nick.child@ibm.com >
2023-02-07 20:04:52 +00:00
Nick Child
282d50493a
pkcs7: Remove duplicate oid condition
...
MBEDTLS_OID_PKCS7_ENCRYPTED_DATA was listed twice in
the oid conditional. Remove one of them.
Signed-off-by: Nick Child <nick.child@ibm.com >
2023-02-01 18:32:55 +00:00
Nick Child
3bd17f2f58
pkcs7: Use end_issuer_and_sn where appropriate
...
There were some areas where `end_signer` were being
used when it makes more sense to use `end_issuer_and_sn`,
as pointed out by demiobenour@gmail.com .
Signed-off-by: Nick Child <nick.child@ibm.com >
2023-01-31 20:42:26 +00:00
Nick Child
ec81709516
pkcs7: Ensure all data in asn1 structure is accounted for
...
Several PKCS7 invalid ASN1 Tests were failing due to extra
data bytes or incorrect content lengths going unnoticed. Make
the parser aware of possible malformed ASN1 data.
Signed-off-by: Nick Child <nick.child@ibm.com >
2023-01-30 16:44:58 +00:00
Gilles Peskine
449bd8303e
Switch to the new code style
...
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com >
2023-01-11 14:50:10 +01:00
Bence Szépkúti
f7641544ea
Correct the fix for the PKCS 7 memory leak
...
This corrects an issue in the origina fix in
4f01121f6e .
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com >
2022-12-12 21:59:03 +01:00
Tom Cosgrove
1797b05602
Fix typos prior to release
...
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com >
2022-12-04 17:19:59 +00:00
Gilles Peskine
4f01121f6e
Fix memory leak on error in pkcs7_get_signers_info_set
...
mbedtls_x509_name allocates memory, which must be freed if there is a
subsequent error.
Credit to OSS-Fuzz (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53811 ).
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com >
2022-11-27 22:02:10 +01:00
Gilles Peskine
e7f8c616d0
Fix dangling freed pointer in pkcs7_free_signer_info
...
This may have been a use-after-free, but I haven't worked out whether it was
a problem or not. Even if it turns out to have been ok, keeping invalid
pointers around is fragile.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com >
2022-11-27 21:55:29 +01:00
Gilles Peskine
47a732635b
Simplify control flow in PKCS7 functions
...
Remove useless goto in several functions.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com >
2022-11-27 21:55:29 +01:00
Gilles Peskine
290f01b3f5
Fix dangling freed pointer on error in pkcs7_get_signers_info_set
...
This fixes a use-after-free in PKCS#7 parsing when the signer data is
malformed.
Credit to OSS-Fuzz (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53798 ).
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com >
2022-11-27 21:55:29 +01:00
Nick Child
3951a4f3ad
pkcs7: Use better error codes
...
Remove an unnecessary debug print (whoops).
Use new error code for when the x509 is expired.
When there are no signers return invalid certificate.
Signed-off-by: Nick Child <nick.child@ibm.com >
Co-authored-by: Dave Rodgman <dave.rodgman@arm.com >
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-10-31 09:38:42 -05:00
Nick Child
5f39767495
pkcs7: Fix imports
...
Respond to feedback about duplicate imports[1] and new import style [2].
[1] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r991355485
[2] https://github.com/Mbed-TLS/mbedtls/pull/3431#pullrequestreview-1138745361
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-10-28 12:38:41 -05:00
Nick Child
bb82ab764f
pkcs7: Respond to feeback on parsing logic
...
After recieving review on the pkcs7 parsing functions, attempt
to use better API's, increase consisitency and use better
documentation. The changes are in response to the following
comments:
- use mbedtls_x509_crt_parse_der instead of mbedtls_x509_crt_parse [1]
- make lack of support for authenticatedAttributes more clear [2]
- increment pointer in pkcs7_get_content_info_type rather than after [3]
- rename `start` to `p` for consistency in mbedtls_pkcs7_parse_der [4]
[1] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r992509630
[2] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r992562450
[3] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r992741877
[4] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r992754103
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-10-28 12:28:54 -05:00
Nick Child
73621ef0f0
pkcs7: Improve verify logic and rebuild test data
...
Various responses to feedback regarding the
pkcs7_verify_signed_data/hash functions. Mainly, merge these two
functions into one to reduce redudant logic [1]. As a result, an
identified bug about skipping over a signer is patched [2].
Additionally, add a conditional in the verify logic that checks if
the given x509 validity period is expired [3]. During testing of this
conditional, it turned out that all of the testing data was expired.
So, rebuild all of the pkcs7 testing data to refresh timestamps.
[1] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r999652525
[2] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r997090215
[3] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r967238206
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-10-28 11:24:25 -05:00
Nick Child
5f9456f3e3
pkcs7: Fix trailing whitespace
...
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-09-26 09:18:12 -05:00
Nick Child
8ce1b1afc8
pkcs7: Correct various syntatical mistakes
...
Resond to feedback from the following comments:
- use correct spacing [1-7]
- remove unnecessary parenthesis [8]
- fixup comments [9-11]
- remove unnecessary init work [12]
- use var instead of type for sizeof [13]
[1] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953655691
[2] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953661514
[3] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953689929
[4] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953696384
[5] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953697558
[6] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953697793
[7] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953697951
[8] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953699102
[9] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r971223775
[10] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r967133905
[11] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r967135932
[12] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r967151430
[13] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r967154159
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-09-14 15:13:52 -05:00
Nick Child
34d5e931cf
pkcs7: Use better return code for unimplemented specifications
...
In response to feedback [1] [2], use MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE
instead of MBEDTLS_ERR_PKCS7_INVALID_FORMAT for errors due to the
pkcs7 implemntation being incomplete.
[1] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953649079
[2] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953658276
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-09-14 14:44:03 -05:00
Nick Child
7089ce8381
pkcs7: Handle md errors in multisigner pkcs7 verification
...
In resonse to feedback [1], if `mbedtls_md_info_from_type` were to
fail then skip the signer and try the next one.
Additionally, use a for loop instead of a while loop when iterating
over signers because it simplifies the use of `continue`.
[1] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r967198650
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-09-14 14:18:00 -05:00
Nick Child
9f4fb3e63f
pkcs7: Unite function return style
...
In response to feedback[1], standardize return variable
management across all pkcs7 functions.
Additionally, when adding return codes from two error values,
use `MBEDTLS_ERROR_ADD` as recommended [2].
[1] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953634781
[2] https://github.com/Mbed-TLS/mbedtls/pull/3431#discussion_r953635128
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-09-12 16:32:36 -05:00
Nick Child
62b2d7e7d4
pkcs7: Support verification of hash with multiple signers
...
Make `mbedtls_pkcs7_signed_hash_verify` loop over all signatures in the
PKCS7 structure and return success if any of them verify successfully.
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-09-01 19:45:41 -05:00
Daniel Axtens
3538479faa
pkcs7: support multiple signers
...
Rather than only parsing/verifying one SignerInfo in the SignerInfos
field of the PKCS7 stucture, allow the ability to parse and verify more
than one signature. Verification will return success if any of the signatures
produce a match.
Signed-off-by: Daniel Axtens <dja@axtens.net >
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-09-01 19:45:41 -05:00
Nick Child
5d881c36ea
pkcs7: Change copyright
...
Signed-off-by: Nick Child <nick.child@ibm.com >
2022-09-01 19:45:41 -05:00