Skip to content

support mbedtls#1028

Merged
azat merged 9 commits intolibevent:masterfrom
okhowang:mbedtls-master
Jul 22, 2020
Merged

support mbedtls#1028
azat merged 9 commits intolibevent:masterfrom
okhowang:mbedtls-master

Conversation

@okhowang
Copy link
Copy Markdown
Contributor

close #421
I based on boytm's work, and fix warning and error

@okhowang
Copy link
Copy Markdown
Contributor Author

I notice github actions's environment has no mbedtls, may I build mbedtls in CI too?

@ploxiln
Copy link
Copy Markdown
Contributor

ploxiln commented May 27, 2020

You should be able to just add something like apt-get -q -y install mbedtls-dev to the github-actions build prep steps.

@okhowang
Copy link
Copy Markdown
Contributor Author

https://github.com/libevent/libevent/pull/1028/checks?check_run_id=712190097
It seem like cmake build dir shouldn't be cache?
because source dir may be different.

@azat
Copy link
Copy Markdown
Member

azat commented May 27, 2020

It seem like cmake build dir shouldn't be cache?

It should, otherwise it will make build significantly slower (especially on CI)
@ygj6 working on fixing this

As a workaround for this PR you can change cache key

@okhowang okhowang force-pushed the mbedtls-master branch 5 times, most recently from bb89a55 to bff1982 Compare May 28, 2020 15:30
@azat azat added the subsystem:ssl SSL Related issue label Jun 1, 2020
Copy link
Copy Markdown
Member

@azat azat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks good, but lots of copy-paste in bufferevent_mbedtls.c can you reduce it please? (and it is not only to make code clean but also bufferevent_openssl.c contains some quirks/issues that I would love to keep in one place to avoid out-of-sync problems)

@okhowang
Copy link
Copy Markdown
Contributor Author

okhowang commented Jun 7, 2020

In general looks good, but lots of copy-paste in bufferevent_mbedtls.c can you reduce it please? (and it is not only to make code clean but also bufferevent_openssl.c contains some quirks/issues that I would love to keep in one place to avoid out-of-sync problems)

I also think that current implementation is ugly, and need to reuse some logic from openssl.
but how can I locate all issue/quirks from bufferevent_openssl.c?
sorry for unfamiliar.

@azat
Copy link
Copy Markdown
Member

azat commented Jun 7, 2020

but how can I locate all issue/quirks from bufferevent_openssl.c?

How about move generic code out from the bufferevent_openssl and use it for both openssl and mbedtls, thus you will avoid copy-pasting?
And after this that generic parts can be cleaned up, separately

@okhowang
Copy link
Copy Markdown
Contributor Author

okhowang commented Jun 8, 2020

but how can I locate all issue/quirks from bufferevent_openssl.c?

How about move generic code out from the bufferevent_openssl and use it for both openssl and mbedtls, thus you will avoid copy-pasting?
And after this that generic parts can be cleaned up, separately

there is a problem when reuse code with openssl and mbedtls.
that is we can't link libevent_openssl and libevent_mbedtls together,
although this situation is rarely.
or we have to add one more library like libevent_ssl_common

@azat
Copy link
Copy Markdown
Member

azat commented Jun 8, 2020

or we have to add one more library like libevent_ssl_common

Sound ok, but this library should not be exported, only archive or cmake object

@okhowang
Copy link
Copy Markdown
Contributor Author

okhowang commented Jun 8, 2020

If we don't export libevent_ssl_common, we can't link libevent_openssl and libevent_mbedtls together.
May I mistake something?

@azat
Copy link
Copy Markdown
Member

azat commented Jun 8, 2020

If we don't export libevent_ssl_common, we can't link libevent_openssl and libevent_mbedtls together

They will just both contains the same code in the library, this is how archive library works

P.S. maybe I misunderstand you?

@okhowang
Copy link
Copy Markdown
Contributor Author

okhowang commented Jun 8, 2020

I review code of bufferevent_openssl.c and bufferevent_mbedtls.c.
And I found that it's too hard to reuse some code in two file directly.
they has similar but different struct/function/error code.
If we want reuse code between SSL library, we must make an abstract layer of SSL which encapsulation implementation of OpenSSL and mbedtls.
That's a little bigger for this PR.
can we do it after this PR?

@azat
Copy link
Copy Markdown
Member

azat commented Jun 8, 2020

can we do it after this PR?

Ok

@okhowang
Copy link
Copy Markdown
Contributor Author

windows CI is OK all now, maybe you mistake link? https://github.com/libevent/libevent/actions/runs/168370501

Copy link
Copy Markdown
Member

@azat azat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this looks way more better in general right now, @okhowang thank you for being so patient!

There are some small bits left that I would prefer to fix before merge, I was going to do this by myself (to merge it faster), but if you want to address them by yourself (besides maybe you will have another opinion on that bits) give me a note and I will leave comments instead.

@azat
Copy link
Copy Markdown
Member

azat commented Jul 22, 2020

@okhowang Ok, will address those minor bits by myself

boytm and others added 9 commits July 22, 2020 22:52
prototype is libevent-2.1.11-stable libevent_openssl.c
Based on mbedtls's source code programs/ssl/ssl_client1.c
This patch splits common part out to avoid copy-paste from the
- bufferevent_openssl.c
- bufferevent_mbedtls.c

It uses VFS/bufferevent-like approach, i.e. structure of callbacks.
@azat azat force-pushed the mbedtls-master branch from c0eae5b to 1bfbbdf Compare July 22, 2020 21:14
@azat azat merged commit 0e339b0 into libevent:master Jul 22, 2020
@azat
Copy link
Copy Markdown
Member

azat commented Jul 22, 2020

@okhowang thanks a lot for this functionality!

BTW can you also add:

  • tests for https using mbed TLS layer?
  • https-client mbed TLS support

@okhowang
Copy link
Copy Markdown
Contributor Author

@okhowang thanks a lot for this functionality!

BTW can you also add:

  • tests for https using mbed TLS layer?
  • https-client mbed TLS support

I will do it later.

@okhowang okhowang deleted the mbedtls-master branch July 23, 2020 03:33
@azat
Copy link
Copy Markdown
Member

azat commented Jul 23, 2020

Plus there are also the following warnings:

[26/195] Building C object CMakeFiles/event_openssl_static.dir/bufferevent_openssl.c.o
../bufferevent_openssl.c:402:2: warning: cast between incompatible function types from ‘int (*)(const SSL *)’ {aka ‘int (*)(const struct
 ssl_st *)’} to ‘size_t (*)(void *)’ {aka ‘long unsigned int (*)(void *)’} [-Wcast-function-type]
  402 |  (size_t(*)(void *))SSL_pending,
      |  ^
[27/195] Building C object CMakeFiles/event_openssl_shared.dir/bufferevent_openssl.c.o
../bufferevent_openssl.c:402:2: warning: cast between incompatible function types from ‘int (*)(const SSL *)’ {aka ‘int (*)(const struct
 ssl_st *)’} to ‘size_t (*)(void *)’ {aka ‘long unsigned int (*)(void *)’} [-Wcast-function-type]
  402 |  (size_t(*)(void *))SSL_pending,

azat added a commit that referenced this pull request Jul 23, 2020
The bufferevent_get_openssl_error() returns unsigned long, so returning
-1 on error in unclear. Let's use 0.

Fixes: #1028
okhowang added a commit to okhowang/libevent that referenced this pull request Sep 6, 2020
@okhowang
Copy link
Copy Markdown
Contributor Author

okhowang commented Sep 6, 2020

https-client mbed TLS support

https-client is based on OpenSSL currently,
and there is a ssl-client-mbedtls.c.
you mean I need add a https-client-mbedtls?
@azat

@azat
Copy link
Copy Markdown
Member

azat commented Sep 8, 2020

you mean I need add a https-client-mbedtls?

@okhowang This will be okay too (if this will be done w/o copy-paste, or with minimal copy-paste)

P.S. sorry for the delay

azat pushed a commit to okhowang/libevent that referenced this pull request Sep 8, 2020
azat added a commit that referenced this pull request Sep 14, 2020
This pure build w/o SSL has been removed in mbedtls PR - #1028
azat added a commit that referenced this pull request Oct 31, 2020
* ssl-fixes-after-mbedtls:
  Fix BEV_IS_SSL() macro
  Fix preprocessor condition for BEV_IS_SSL()
  Remove reduntant BEV_IS_MBEDTLS

Refs: #1028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

subsystem:ssl SSL Related issue

Development

Successfully merging this pull request may close these issues.

Support mbedtls

4 participants