DEV Community

VINAYAK GOTE
VINAYAK GOTE

Posted on

A Maintainer Asked Me a Design Question on My Armeria PR. Here Is How I Answered It.

I recently opened a PR in Armeria, the Java microservice framework from LINE. A maintainer reviewed it and asked a design question I could not answer with a quick yes or no. This post is about how I worked through it.

The bug

Armeria has a check called validateHttp2Ciphers. HTTP/2 requires certain cipher suites, and the check makes sure your TLS configuration includes the required one.

The catch: it always asked for the TLS 1.2 cipher suite, even when the connection was configured for TLS 1.3 only. TLS 1.3 has its own, different cipher suites. So a perfectly valid TLS 1.3-only setup could be judged wrong. That is issue #7112.

My fix

The check now looks at which TLS protocols are actually enabled and picks the right required cipher suite:

  • TLS 1.3 only: require TLS_AES_128_GCM_SHA256
  • TLS 1.2 (alone or with 1.3): behavior and error message unchanged

I read the protocols from the built SslContext, not from the TLS settings, because a customizer can change the protocols after they are set. I also added tests for TLS 1.3 only, TLS 1.2 only, both enabled, and the unsafe-cipher case. That is PR #7120.

The maintainer's question

My first version created a temporary SSLEngine just to read the enabled protocols. A maintainer asked: for connections where the TLS spec is decided dynamically, would that create an extra engine each time? He suggested wrapping the SslContext in a DelegatingSslContext and doing the check when an engine is created.

It was a fair question, and I did not want to answer from a guess. So I looked into it.

What I found

  1. How often it really runs. The validation runs once or twice per client factory or virtual host at startup. Contexts are cached, so it runs again only when a new TLS spec is created, such as certificate rotation with dynamic providers. It is per new context, not per connection.
  2. A problem with the wrapper. I checked the Netty classes with javap. DelegatingSslContext does not implement ReferenceCounted, but the code that releases contexts expects that. A wrapper would silently skip the release unless it forwarded those methods too.
  3. Failing fast still matters. Building a client factory or server is expected to fail early on a bad cipher setup, so a temporary engine would still be needed for that moment.

So instead of the wrapper, I pushed a smaller change: look up the protocols only when needed. If the cipher list already contains both required suites, no engine is created at all. Simplified, the idea is:

// If the list already has both required suites, we are done.
// No temporary SSLEngine is created on this path.
if (hasBothEssentialCiphers(ciphers)) {
    return;
}

// Only now do we look at the enabled protocols (this is where the
// temporary engine is created, and it is always released afterwards).
Set<String> protocols = enabledProtocols.get();
boolean tls13Only = protocols.contains("TLSv1.3") && !protocols.contains("TLSv1.2");

String required = tls13Only
        ? "TLS_AES_128_GCM_SHA256"
        : "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256";
Enter fullscreen mode Exit fullscreen mode

I explained all of this in a comment, and added that if the maintainer still prefers the wrapper, I would switch.

One more thing: scope

An automated reviewer also suggested changing how the cipher blacklist check works for TLS 1.3-only setups. The maintainer agreed it made sense but said it was optional and not part of this issue. I left it out of the PR on purpose, to keep the change focused on #7112.

What I took from it

  1. Answer design questions with evidence. Looking up how often the code really runs, and checking the class with javap, turned a debate into facts.
  2. Offer the other option. Saying "if you still prefer the wrapper, I will switch" keeps the decision with the maintainer.
  3. Keep the PR small. A good suggestion that belongs to a different issue can wait for its own PR.
  4. Explain the tradeoff, not just the result. The maintainer can now see why I chose what I chose.

As I write this, the PR is still open and under review, and I will share how it ends.

Proof of my work

Everything here is public, so you can check it yourself:

Connect with me: LinkedIn | X

If you are a maintainer, a recruiter or a team looking for someone who backs his design choices with evidence, my DMs are open. Tell me in the comments how you decide between a quick fix and a bigger refactor.

Top comments (0)