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

Allow useOpenSsl -> tlsEngineType to be configured by ClientFactoryBuilder #4962

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

seonWKim
Copy link
Contributor

@seonWKim seonWKim commented Jun 15, 2023

Motivation:

Let users configure tlsEngineType client option when using ClientFactoryBuilder or ServerBuilder

Example
Client

ClientFactory
  .builder()
  .tlsEngineType(TlsEngineType.OPENSSL)
  .build();

Server

Server.builder()
           .tlsSelfSigned()
           .service("/example", (ctx, req) -> HttpResponse.of(HttpStatus.OK))
           .tlsEngineType(TlsEngineType.JDK)
           .virtualHost("*.example1.com")
           .service("/example", (ctx, req) -> HttpResponse.of(HttpStatus.OK))
           .tlsSelfSigned()
           .tlsEngineType(TlsEngineType.OPENSSL)
           .and()
           .virtualHost("*.example2.com")
           .service("/example", (ctx, req) -> HttpResponse.of(HttpStatus.OK))
           .tlsSelfSigned()
           .tlsEngineType(TlsEngineType.JDK)
           .and()
           .virtualHost("*.example3.com")
           .service("/example", (ctx, req) -> HttpResponse.of(HttpStatus.OK))
           .and()
           .build();

Modifications:

  • Add tlsEngineType method in ClientFactoryBuilder to allow users choose whether to use openSsl.

Result:

  • Closes #<4949>. (If this resolves the issue.)
  • Users will be able to configure tlsEngineType using ClientFactoryBuilder or ServerBuilder

@seonWKim seonWKim marked this pull request as ready for review June 15, 2023 16:28
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Looks good! Left some minor comments on testing 🙇

* Allow the use of JNI-based TLS support with OpenSSL.
* @param useOpenSsl Whether to allow the use of JNI-based TLS support with OpenSSL
*/
public ClientFactoryBuilder useOpenSsl(boolean useOpenSsl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that currently, we already have the ability to set this per server/clientFactory via tlsCustomizer

I have no problem with adding this API for now, but I slightly worry that this API will become obsolete if a different SslProvider is added in the future.
What do you think other maintainers?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. It is a possible situation but we may need to provide users a workaround to selectively use JDK SSL over Open SSL.

When SslProvider is made, I think, we have them mutually exclusive.

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about adding a new enum first, then? @seonwoo960000, how about creating a new PR that deprecates Flags.useOpenSsl() and adding Flags.tlsEngineType() and enum TlsEngineType { JDK, OPENSSL }? You might want to check Flags.useEpoll() and Flags.transportType()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@trustin thank you for the detailed comment. So by adding a enum TlsEngineType, armeria should be able to allow users select tls engine not only JDK and OPENSSL but also other engines which might be added in the future. Did I understand correctly 🤔 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you understand it correctly. If a new TLS engine is added, Flags.useOpenSsl() == false could be vague.

Comment on lines 133 to 145
final AggregatedHttpResponse response3 = WebClient.builder(SessionProtocol.HTTP,
server.httpEndpoint())
.factory(sslDisabledClient).build()
.get("/hello").aggregate().join();
assertThat(response3.status()).isEqualTo(HttpStatus.OK);
assertThat(response3.contentUtf8()).isEqualTo("hello");

assertThatThrownBy(() -> WebClient.builder(SessionProtocol.HTTPS, server.httpsEndpoint())
.factory(sslDisabledClient).build()
.get("/hello").aggregate().join())
.isInstanceOfSatisfying(CompletionException.class, e -> {
assertThat(e).hasCauseInstanceOf(UnprocessedRequestException.class);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what these lines are testing 😅 Can we just test once with tlsVerify disabled for each ClientFactory?

ClientFactory sslDisabledClient = ClientFactory.builder().useOpenSsl(false).tlsNoVerify().build();
...
final AggregatedHttpResponse response3 = WebClient.builder(SessionProtocol.HTTPS,
                                                           server.httpsEndpoint())
                                                  .factory(sslDisabledClient).build()
                                                  .get("/hello").aggregate().join();
assertThat(response3.status()).isEqualTo(HttpStatus.OK);
assertThat(response3.contentUtf8()).isEqualTo("hello");

Copy link
Contributor Author

@seonWKim seonWKim Jun 16, 2023

Choose a reason for hiding this comment

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

Please correct me if my understanding is wrong.

  • If client doesn't use openSsl, request sent using https protocol will fail(because https require ssl/tls)

The purpose of useOpenSsl() was to test above scenario🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

If OpenSSL is disabled, the JDK SSL engine is used instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, then it seems that above mentioned scenario isn't valid. I'll remove the test 👍

@seonWKim seonWKim force-pushed the enable-disable-openssl-4949 branch 3 times, most recently from b396271 to d378831 Compare June 23, 2023 16:59
@seonWKim seonWKim changed the title Allow useOpenSsl to be configured by ClientFactoryBuilder Allow useOpenSsl to be configured by ClientFactoryBuilder Jun 30, 2023
@seonWKim seonWKim force-pushed the enable-disable-openssl-4949 branch from d378831 to 5b6a2d1 Compare July 2, 2023 09:21
This was referenced Jul 12, 2023
jrhee17 added a commit that referenced this pull request Apr 3, 2024
Motivation:

Add `TlsEngineType` to let users choose the type of tls engine. (Using
`Flags`)

Modifications:

- Add `TlsEngineType` enum 
- Deprecate `useOpenSsl` 

Result:

- Related to #<[4949](#4949)>.
- Related to
#4962 (comment)
- `TlsEngineType` is added 
- `useOpenSsl` is deprecated 

<!--
Visit this URL to learn more about how to write a pull request
description:

https://armeria.dev/community/developer-guide#how-to-write-pull-request-description
-->

---------

Co-authored-by: Ikhun Um <ih.pert@gmail.com>
Co-authored-by: Ikhun Um <ikhun.um@linecorp.com>
Co-authored-by: jrhee17 <guins_j@guins.org>
Co-authored-by: minwoox <songmw725@gmail.com>
Co-authored-by: minux <minu.song@linecorp.com>
@seonWKim
Copy link
Contributor Author

seonWKim commented Apr 9, 2024

I'll start working on this issue again 🏃

@github-actions github-actions bot added the Stale label May 16, 2024
@seonWKim seonWKim force-pushed the enable-disable-openssl-4949 branch from c2a3d34 to 1800360 Compare May 19, 2024 06:35
@seonWKim seonWKim changed the title Allow useOpenSsl to be configured by ClientFactoryBuilder Allow useOpenSsl -> tlsEngineType to be configured by ClientFactoryBuilder May 19, 2024
@@ -94,13 +98,26 @@ static SSLSession validateSslContext(SslContext sslContext) {
return sslSession;
}

private static TlsEngineType determineTlsEngineType(SslContext sslContext) {
Copy link
Contributor Author

@seonWKim seonWKim May 19, 2024

Choose a reason for hiding this comment

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

Determining which TlsEngineType should be matched is based on io.netty.handler.ssl.SslContext#newServerContextInternal.

switch (provider) {
  case JDK:
      if (enableOcsp) {
          throw new IllegalArgumentException("OCSP is not supported with this SslProvider: " + provider);
      }
      return new JdkSslServerContext(sslContextProvider,
              trustCertCollection, trustManagerFactory, keyCertChain, key, keyPassword,
              keyManagerFactory, ciphers, cipherFilter, apn, sessionCacheSize, sessionTimeout,
              clientAuth, protocols, startTls, keyStoreType);
  case OPENSSL:
      verifyNullSslContextProvider(provider, sslContextProvider);
      return new OpenSslServerContext(
              trustCertCollection, trustManagerFactory, keyCertChain, key, keyPassword,
              keyManagerFactory, ciphers, cipherFilter, apn, sessionCacheSize, sessionTimeout,
              clientAuth, protocols, startTls, enableOcsp, keyStoreType, ctxOptions);
  case OPENSSL_REFCNT:
      verifyNullSslContextProvider(provider, sslContextProvider);
      return new ReferenceCountedOpenSslServerContext(
              trustCertCollection, trustManagerFactory, keyCertChain, key, keyPassword,
              keyManagerFactory, ciphers, cipherFilter, apn, sessionCacheSize, sessionTimeout,
              clientAuth, protocols, startTls, enableOcsp, keyStoreType, ctxOptions);
  default:
      throw new Error(provider.toString());
}

@seonWKim seonWKim force-pushed the enable-disable-openssl-4949 branch from efc86ba to 8b1ddf0 Compare May 19, 2024 06:51
@seonWKim
Copy link
Contributor Author

seonWKim commented May 19, 2024

I've not added useOpenSsl because tlsEngineType should be a better alternative to useOpenSsl.

Please let me know if we should add support for both tlsEngineType and useOpenSsl in the ClientFactoryBuilder.

Copy link

codecov bot commented May 19, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 74.10%. Comparing base (14c5566) to head (6438c82).
Report is 14 commits behind head on main.

Current head 6438c82 differs from pull request most recent head e6d3fcb

Please upload reports for the commit e6d3fcb to get more accurate results.

Files Patch % Lines
.../linecorp/armeria/client/ClientFactoryBuilder.java 0.00% 2 Missing ⚠️
.../linecorp/armeria/server/ServerSslContextUtil.java 75.00% 1 Missing and 1 partial ⚠️
...p/armeria/internal/common/util/SslContextUtil.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4962      +/-   ##
============================================
+ Coverage     74.05%   74.10%   +0.04%     
- Complexity    21253    21313      +60     
============================================
  Files          1850     1853       +3     
  Lines         78600    78775     +175     
  Branches      10032    10067      +35     
============================================
+ Hits          58209    58376     +167     
+ Misses        15686    15682       -4     
- Partials       4705     4717      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Just left nits. Thanks! 👍

- Add @UnstableApi
- set `Flags.tlsEngineType()` as default virtualHostTemplate's tlsEngineType
@github-actions github-actions bot removed the Stale label May 24, 2024
@minwoox minwoox added this to the 1.29.0 milestone Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants