Skip to content
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

Ada wrapper incorrectly sets verification method for remote peers #7461

Closed
dalybrown opened this issue Apr 23, 2024 · 16 comments · Fixed by #8256
Closed

Ada wrapper incorrectly sets verification method for remote peers #7461

dalybrown opened this issue Apr 23, 2024 · 16 comments · Fixed by #8256
Assignees

Comments

@dalybrown
Copy link
Contributor

I think there is a bug in the logic for setting the verification method in the Ada wrapper here.

The documentation suggests it should be a logical OR operator here.

However, it performs an AND operator here.

Unless the documentation is incorrect! But the C examples suggest it is a logical OR here.

@dgarske dgarske self-assigned this Apr 23, 2024
@dgarske
Copy link
Contributor

dgarske commented Apr 23, 2024

@joakim-strandberg can you please review this bug report?

@joakim-strandberg
Copy link

@dalybrown good catch! The Ada code should be a direct translation of the C examples and that translation does not look correct. My bad, thanks for finding it!!

The best way to fix it? One idea is to rename the function 'function "&" (Left, Right : Mode_Type) return Mode_Type;' to 'function "|" (Left, Right : Mode_Type) return Mode_Type;' and instead of "and" in the implementation "or" should be used instead. It will make the Ada code look more like the C implementation when using the wolfSSL library. What do you think?

@dalybrown
Copy link
Contributor Author

@dalybrown good catch! The Ada code should be a direct translation of the C examples and that translation does not look correct. My bad, thanks for finding it!!

The best way to fix it? One idea is to rename the function 'function "&" (Left, Right : Mode_Type) return Mode_Type;' to 'function "|" (Left, Right : Mode_Type) return Mode_Type;' and instead of "and" in the implementation "or" should be used instead. It will make the Ada code look more like the C implementation when using the wolfSSL library. What do you think?

My preference would be to use the existing Ada syntax for logical operators: and, or, and xor. So in this case, my preference would be to define the or operator for the Mode_Type.

In general, I like things to not look like C haha... but that's my opinion.

@dalybrown
Copy link
Contributor Author

p.s., there is another issue too with examples: the user_settings.h needs to be updated to include #define HAVE_NETDB_H. This was introduced in a subsequent commit.

@dalybrown
Copy link
Contributor Author

p.p.s, I'm happy to fix both issues here. Let me know.

@dgarske
Copy link
Contributor

dgarske commented Apr 24, 2024

Hi @dalybrown , yes feel free to put up a PR fixing both issues. You are right about needing HAVE_NETDB_H. That normally comes from configure in the config.h.

@joakim-strandberg
Copy link

My preference would be to use the existing Ada syntax for logical operators: and, or, and xor. So in this case, my preference would be to define the or operator for the Mode_Type.

It's reasonable to use the "or" operator instead of the "|" operator. You can choose either way @dalybrown. I do note that we are in a gray zone. The Ada language uses both the keyword "or" and "|" to list alternatives. In if-statements the "or" keyword is used, for example "if A or B then" but in case-statement over an enumeration type the "|" is used for example "when Red | Green | Blue =>". In the C version of the wolfSSL library it is known that the Method_Type is an unsigned 32-bit number and one uses bit-wise operations to turn on specific flags. In the Ada version of the wolfSSL library the Method_Type is a private type indicating to the user that the exact type of a Method_Type instance is unknown. It's a fundamental idea in Ada to hide exact representations from users as much as possible to limit potential errors. Classical example is the Integer type where one does not have access to the representation. The major argument for that is the code should be cross-platform and negative numbers may be represented in different ways depending on the hardware. So, in an Ada binding the Method_Type should be private, so it is not known what Method_Type is, but then using the "or" operator to list alternatives implicates that the Method_Type is actually a modular type defined in the Interfaces package and the "or" operator defined there is used under the hood. Which is true, but then again I am thinking is it possible to hide this fact and still have an Ada binding that is easy to use and understand? Just something to keep in mind. I don't think we should spend time on this. It's good to be pragmatic, pushing things forward, everything doesn't have to be perfect.

@dalybrown
Copy link
Contributor Author

That's a good point. WolfSSL happens to use a logical operator here. There is probably a more idiomatic Ada way of specifying this than having clients do any logical operations.

I'll think about it for a bit and circle back with a few options.

One way would be to track the state of the mode that is set, and have a subprogram that you continually set the flags. Under the hood it will perform the logical or operation but that's not exposed to the client.

type State is private;
procedure Set (This : Mode_Type; In_This : in out State);

private

type State is Unsigned_32;

and then in the body you could just the operator:

procedure Set (This : Mode_Type; In_This : in out State)
is
begin
   In_This := In_This or Unsigned_32 (This);
end Set;

You can then just call it for every flag you want to set and then call the regular procedure.

There are probably many other options. Thoughts?

@dalybrown
Copy link
Contributor Author

Maybe better names would be:

procedure Include (This : Mode_Type; With_These : in out Flags);

Or something...

@dgarske
Copy link
Contributor

dgarske commented May 2, 2024

Hi @dalybrown , will you be able to put up a PR to fix this mask and the netdb_h?

@dalybrown
Copy link
Contributor Author

Hi @dalybrown , will you be able to put up a PR to fix this mask and the netdb_h?

Definitely! I was hoping to hear back from @joakim-strandberg on my suggestions prior to pushing any changes.

@dgarske
Copy link
Contributor

dgarske commented Aug 22, 2024

Hi @dalybrown ,

Is this issue resolved? Let me know if you need anything.

Thanks ,
David Garske, wolfSSL

@dalybrown
Copy link
Contributor Author

Ah I didn't get back to this yet - sorry! It's been a busy summer. I haven't forgotten - will get back to this hopefully in September.

@dgarske
Copy link
Contributor

dgarske commented Nov 15, 2024

Hi @dalybrown or @joakim-strandberg

It looks like that bug with the WolfSSL_CTX_Set_Verify "AND" is still there. Are either of you able to work on resolving this? If not please let me know and we can assign internally.

Thanks,
David Garske, wolfSSL

@dalybrown
Copy link
Contributor Author

Hi,

Sorry for the inaction.

I plan to eventually get to this, but truthfully I don't know when. It's an easy enough fix, but unfortunately I've been too busy to circle back.

How about this: if I don't fix by the new year, someone internal can take a look.

Let me know!

Cheers,

Daly

@LinuxJedi LinuxJedi self-assigned this Dec 5, 2024
LinuxJedi added a commit to LinuxJedi/wolfssl that referenced this issue Dec 5, 2024
The Ada wrapper had an `&` operator for the verification mode. This
effectively caused the verification mode to equal `0`.

The operator has been switched to `or` now, in addition, a getter has
been added to the API. This allows for the test I've added to the server
code to verify that it is being set correctly.

`OPENSSL_ALL` flag added to Ada so that the verify mode getter function
is compiled in.

Fixes wolfSSL#7461

Thanks to @dalybrown for reporting it.
@LinuxJedi
Copy link
Member

Hi @dalybrown,

I have opened a pull request which should fix the issue. Thank you for reporting it.

Andrew (LinuxJedi) Hutchings, wolfSSL

@dgarske dgarske closed this as completed in 158d625 Dec 6, 2024
gasbytes pushed a commit to gasbytes/wolfssl that referenced this issue Dec 21, 2024
The Ada wrapper had an `&` operator for the verification mode. This
effectively caused the verification mode to equal `0`.

The operator has been switched to `or` now, in addition, a getter has
been added to the API. This allows for the test I've added to the server
code to verify that it is being set correctly.

`OPENSSL_ALL` flag added to Ada so that the verify mode getter function
is compiled in.

Fixes wolfSSL#7461

Thanks to @dalybrown for reporting it.
gasbytes pushed a commit to gasbytes/wolfssl that referenced this issue Dec 21, 2024
This adds support for the STM32MP13 HAL, tested on the STM32MP135F MPU.

Using the HAL this modifies our previous RNG, AES-CBC, AES-GCM, HASH,
ECDSA and DES3 ST HAL acceleration to work with the MPU. It also works
around bugs found in the AES-GCM code of the HAL.

The HAL does not appear to have support for MD5 HASH at the moment, so
this has been given a flag to disable it on this MPU.

linuxkm: work around aarch64 dependency on alt_cb_patch_nops for enable-linuxkm-pie (FIPS support).

wolfssl/wolfcrypt/aes.h: #define WC_NO_COMPAT_AES_BLOCK_SIZE in OPENSSL_COEXIST builds.  see comment in source code with usage instructions.

wolfhsm-mldsa-fixes

SP ARM: big-endian support

Handle reading and writing from big-endian byte array when compiling for
big endian.
Rework little endian to be more effiecient too.

Fix wolfSSL_X509_STORE_get0_objects to handle case where no CA has been loaded

Fix conversion on various files. Work from Reda.

Additional conversion warnings.

Addressing CI/CD before continuing with the fixing

More Wconversion fixing (Renesas specific)

Moved variable to the top of the scope

fixes for OPENSSL_COEXIST with FIPS and with/without TEST_OPENSSL_COEXIST.

adjustments to x509.h macro list

Add STM32MP13 to Cube IDE

Add STM32MP13 HAL support for more SHA types

This adds STM32 HAL support for:

* SHA384
* SHA512 (with -224 and -256)
* SHA3 (all variants apart from SHAKE)

The partial FIFO block calculations have been adjusted based in the
STM32 code to support the larger hash sizes.

This should work with other chips such as the STM32U5xx, but is not
enabled for that yet.

Fix STM32 example broken in wolfSSL#8143.

Fixes for building with SP RSA small and RSA Public only. ZD 18996

src/ssl_sess.c: in wolfSSL_CTX_flush_sessions(), add missing check of s->sessionIDSz, similar to the fix to TlsSessionCacheGetAndLock() in wolfSSL#8182 (ef67b1c).  also, add missing macro to .wolfssl_known_macro_extras.

Fix test environment

Add size checks to sessionID

Fix for Compressed Keys with FIPS

build dsa in visual studio

wc_port: change zephyr struct k_thread tid member to pointer.

Fix issue with wc_lms_impl.c or wc_lms not including settings.h. Caused issue enabling LMS from user_settings.h.

Fixes for ML-DSA and LMS cast warnings and spelling errors.

Expose compatibility get_verify functions with openssl_extra.

Fix broken verify on Ada wrapper

The Ada wrapper had an `&` operator for the verification mode. This
effectively caused the verification mode to equal `0`.

The operator has been switched to `or` now, in addition, a getter has
been added to the API. This allows for the test I've added to the server
code to verify that it is being set correctly.

`OPENSSL_ALL` flag added to Ada so that the verify mode getter function
is compiled in.

Fixes wolfSSL#7461

Thanks to @dalybrown for reporting it.

Add libspdm action

Depends on wolfSSL/osp#217

configure.ac: add --enable-fips=cert4718 alias for v5, and make --enable-fips=v5 set FIPS to 5.2.1; set DEF_FAST_MATH and DEF_SP_MATH to "no" when "yes" would conflict with user-supplied arguments.

configure.ac: fix SC1105 ("Shells disambiguate (( differently or not at all.").

wolfssl/wolfcrypt/types.h and wolfssl/wolfcrypt/hash.h: define WOLF_AGG_DUMMY_MEMBER, pivoting on HAVE_EMPTY_AGGREGATES, and use WOLF_AGG_DUMMY_MEMBER in wc_Hashes.

src/ssl_crypto.c: revert FIPS gate threshold in wolfSSL_AES_decrypt() changed in d85c108 -- original value was correct, misdiagnosed by faulty test.

update fips-check.sh for cert wolfSSL#4718: remap linuxv5 as an alias for linuxv5.2.1, and add linuxv5-RC12.

fips-check.sh: add support for WOLFSSL_REPO and noautogen option; tweak git fetching to keep wolfssl and fips tags distinct, and fetch all needed tags by name to assure availability for checkout.  also, hide stdout noise from pushd/popd.

peer review: refactor HAVE_ANONYMOUS_INLINE_AGGREGATES and HAVE_EMPTY_AGGREGATES to conform to wolfssl convention -- defined() for true, !defined() for false -- while retaining ability for user override-off by passing in explicit 0 definition.

src/internal.c: in HashSkeData(), remove unneeded logically faulty nullness check around XFREE(ssl->buffers.digest.buffer, ...).

Add nss interop

Add sanity check for configuration method

Disable hitch OSP test

Fix from review

move !defined(EXTERNAL_OPTS_OPENVPN) assert from src/internal.c to wolfssl/wolfcrypt/types.h with refinements; refine logic+message of assert in wolfssl/wolfcrypt/settings.h re "wolfssl/options.h included in compiled wolfssl library object..".

wolfssl/wolfcrypt/settings.h: use #warning, not #error, for "No configuration for wolfSSL detected, check header order", to avoid unnecessary breakage of old projects with nonstandard custom settings.

Revert to ubuntu-22.04

add support for WOLFSSL_NO_OPTIONS_H:
* activate WOLFSSL_NO_OPTIONS_H in linuxkm/Kbuild for in-module test.o and benchmark.o.
* refine explanatory comments in settings.h re WOLFSSL_USE_OPTIONS_H, WOLFSSL_NO_OPTIONS_H, and WOLFSSL_CUSTOM_CONFIG.
* add safety catch to options.h/options.h.in to inhibit inclusion if defined(WOLFSSL_NO_OPTIONS_H).
* for good measure, add explicit check for WOLFSSL_NO_OPTIONS_H to wolfcrypt/benchmark/benchmark.c and wolfcrypt/test/test.c.

Improve Espressif SHA HW/SW mutex messages

.wolfssl_known_macro_extras: regenerate

Use proper ref count handling when adding to x509 store

Always keep original x509 pointer with proper refcounts even for self signed trusted CA

Dont use specific free function

Free x509 on fail to push

CMAKE: look for pthreads when importing wolfSSL if required

All required dependencies of a package must also be found in the
package configuration file. Consumers of wolfSSL can't know
if it was built with or without threads support. This change
adds find_package(Threads) lookup in the file used for
find_package(wolfssl) if wolfSSL was built with threads support.

Initial implementation for using PKCS11 to retrieve certificate for SSL CTX

Updates per review comments

Add support for cert format in get cert crypto callback

Use char instead of sword8, sanity length check on CKA_VALUE

No redundant NULL check on free

Remove redundant NULL check

Aarch64 Poly1305: fix corner case

Don't mask top 26 bits as it may have next bit set as reduction step was
only approximate.

Fix memory leak

make new sanity check be a warning

defining custom config avoids warning of library builds pulling in options.h

Add support for the RFC822 Mailbox attribute.

Aarch64: make code compile when no hardware crypto avail

Detects availability of instructions for Aarch64.

WOLFSSL_ALWAYS_KEEP_SNI enabled by default with --enable-jni

wolfSSL_CTX_set_tlsext_use_srtp() should return 1 on failure and 0 upon success.

Same with wolfSSL_set_tlsext_use_srtp().

See https://docs.openssl.org/1.1.1/man3/SSL_CTX_set_tlsext_use_srtp/

Add a test.

Various cleanups and fixes:
* Fix to properly set configure.ac LMS/XMSS enables and build of those code files.
* Remove duplicate aes.c `wc_AesSetKeyLocal` call to `wc_AesSetIV`. Moved earlier in function in commit a10260c.
* Benchmark missing time.h with NO_ASN_TIME.
* Added option to support disabling AES CFB 1/8 `WOLFSSL_NO_AES_CFB_1_8`.
* Fixes for building with combinations of `WOLFSSL_RSA_VERIFY_ONLY` and `WOLFSSL_RSA_PUBLIC_ONLY`.
* Fix for building `--enable-stacksize=verbose` with single threaded.
* Various tab and formatting cleanups.
ZD 18996

Fixes for macro names.

Cleanup the gating for `WOLFSSL_NO_AES_CFB_1_8`.

Revert "Aarch64: make code compile when no hardware crypto avail"

fix for sig fault harden build

linuxkm/Kbuild and linuxkm/module_exports.c.template: on kernel >=6.13, add quotes around the namespace arg to EXPORT_SYMBOL_NS_GPL() (upstream change actually made in 6.13-rc2).

Aarch64: make code compile when no hardware crypto avail

Detects availability of instructions for Aarch64.

MacOS: allow SHA-3 instructions to be explicitly not used

Some iPads and iPhones don't support SHA-3 instructions.
Allow SHA-3 instructions to explicitly not be used for these devices.

Fix compile issue with NO_WOLFSSL_DIR

`test_wolfSSL_CTX_load_system_CA_certs()` would try to use DIR functions
when `NO_WOLFSSL_DIR` was used.

EdDSA Ed448: sc_muladd now does full reduction

sc_muladd was reducing to word boundary and not to order.
Now reduces to order as last step.

CID also supported in DTLS 1.2

Add CID interop with mbedtls

add shebang

use unique key

fix redirect order

Use source hostap repo

Initialize vars & change types to appease Windows/VS

fips-check.sh fixes + enhancements:
* change default WOLFSSL_REPO to the canonical upstream.
* refactor tag calculation without bash associative arrays, for backward compat.
* add support for fetching FIPS tags/branches into a persistent fips repo if one is found at ../fips.
* use --shared in git clones where applicable.
* always check out the master FIPS branch, for its tooling, and always make sure it's up to date with $FIPS_REPO.
* after each fetch for a previously unknown tag, explicitly associate the tag with the FETCH_HEAD.

Enable support for using certificate manager only. Fixes for building without TLS enabled (NO_TLS). ZD 19054. Tested using `./configure --disable-tlsv12 --disable-tls13 CFLAGS="-DNO_TLS" && make check`

Fix issues in `test_tls13_apis` with no filesystem or no RSA/ECC.

Fix nested `NO_TLS`.

Further fixes with NO_TLS to support use with compatibility layer.

Add `--disable-tls` option that can be used with `--enable-all` to disable TLS features and set `NO_TLS`. Useful for allowing certificate manager and crypto compatibility API's only.

configure.ac: fix faulty logic in FIPS v6 feature calculation re ENABLED_ARMASM_CRYPTO, originally added in 6e0a901.

wolfcrypt/src/aes.c: add missing WOLFSSL_ARMASM gate clause around wolfCrypt_FIPS_aes_ro_sanity, necessitated by 514a92d/wolfSSL#8293.

wolfCrypt -Wconversion expansion: fix numerous warnings, all benign, from -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion.

Espressif Managed Component wolfSSL 5.7.4 post-release update

fedora crypto-policies: initial support.

Fix RA6M jankins failure

Printing the rfc822Mailbox x509 attribute

fix: cast int operands to size_t in bio buffer size calc to prevent loss of precision

Fix C4333 warning by adjusting right shift operation on byte cast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants