Code review request, JEP 114, 7068321 Support TLS Server Name Indication (SNI) Extension in JSSE Server
Brad Wetmore
bradford.wetmore at oracle.com
Wed Oct 10 23:38:52 UTC 2012
On 10/10/2012 5:47 AM, Xuelei Fan wrote:
> new webrev: http://cr.openjdk.java.net./~xuelei/7068321/webrev.13/
I guess you didn't need to have me as reviewer before going final with
the CCC?
>> javax/net/ssl/SSLSocketFactory.java
>> ===================================
>> Change look good.
>>
>> 216: I think you need a period at end of sentence here.
You got the others, but missed this one.
>> 231: Might suggest some reason text for the UnsupportedOperationException.
>>
> I think the exception name has say the exception clearly. I think it
> does not make sense to add additional message for it. I had a search in
> the packages of java.lang and java.uitl, most of the codes (39 of 42)
> use the default non-parameter constructor of
> UnsupportedOperationException. I will prefer to use the current style.
No problem.
>> sun/security/ssl/Utilities.java
>> ===============================
>> 46: Minor comment on method name, you might want to use
>> "addToSNIServerNameList" since you are adding.
>>
>> 84: Just wondering why you added this method here? This added a bit of
>> overhead in extra methods calls (well, maybe not with hotspot unrolling)
>> and added a few chars to the source. So given that you have added this,
>> why not update the remainder also?
>> EngineOutputRecord/InputRecord/OutputRecord.
>>
> Good point!
Or do it the way you did. This just adds a little extra source overhead.
>> See the below comment in SSLSocketImpl.java. If you decide to accept
>> it, you will want to remove the unmodifiable collection.
>>
> See the reply in SSLSocketImpl.java
Ok.
>> sun/security/ssl/Handshaker.java
>> ================================
>> 291: The change to allow for setting of SNI information has opened up a
>> race condition. It's probably not too bad for SSLSocket, but might be
>> more for SSLEngine. When we create ClientHandshaker/ServerHandshakers,
>> we normally grab all the parameters necessary for the handshaker, and
>> any future parameter modifications will apply to the next handshake. In
>> the past, our SNI information would never change, so it wasn't necessary
>> to pass it in on creation. That assumption no longer holds.
>>
>> So you could see something like this:
>>
>> sslEngine.beginHandshake();
>> SSLParameters sslp = new SSLParameters();
>> sslp.setHostnames("example.com");
>> sslEngine.setSSLParameters(sslp);
>> // do handshake...
>>
>> and you'll get the new value instead of old.
>>
> Good catch!
>
> Updated to store the local server name indication and matchers in
> Handshaker.
Just a comment:
459/468: Currently you have serverNames and sniMatchers as package
private variables, so the ClientHandshaker/ServerHandshaker *could*
inherit these variables rather than have a separate get methods. Or you
could make them private and keep the get calls.
>> sun/security/ssl/HelloExtensions.java
>> =====================================
>> 423: This behavior is currently underspecified.
>
> I think the behavior is specified in RFC 6066:
>
> ... If the server understood the ClientHello extension but
> does not recognize the server name, the server SHOULD take one of two
> actions: either abort the handshake by sending a fatal-level
> unrecognized_name(112) alert or continue the handshake.
>
> As means that the server will try to recognize every type of server
> name.
I'm just not seeing why this implies that it requires *EVERY* name must
match. This just says we can do one of two things upon receipt of an
unrecognized hostname: continue on, or alert/close. We can be very
restrictive (ALL/AND) or less so (at least one/OR), and still be within
the RFC, I think.
> In our spec, it is required that once a SNIMatcher is defined, it
> will be used to recognized the server name in the SNI extension.
Where? We do say in SNIMatcher:
Servers can use Server Name Indication (SNI) information to decide if
specific {@link SSLSocket} or {@link SSLEngine} instances should
accept a connection.
But I don't think we have ever said that it MUST match or must match all
or even what the implementation must do if there is a match failure.
Nor should we specify that in the API, IMHO. That's implementation
behavior.
> That's
> to say, every server name should be recognizable if the corresponding
> SNIMatcher is defined. I think the current spec is clear that SNIMather
> is used to match a particular server name type.
Not seeing it, sorry.
After this discussion, I think we are probably better off starting with
AND anyway, because it will be easier to loosen that condition than
starting with OR and having to tighten to AND. If you agree, can you
add a few words to that effect around 431?
>> Right now we have one
>> SNI match type, but eventually we might have more. Your current impl
>> requires that *ALL* SNI matchers match. What if you have more than one,
>> and more than one SNI hostnames are sent?
>>
>> SNIHostname: "example.com"
>> SNINickName: "www.example.com"
>>
>> SNIMatcher: "example.com"
>> SNINickNameMatcher: "www1.example.com
>>
>> Should this fail or succeed? That is, should it be an AND or an OR?
>> Whatever you decide, please document it at least here. Not sure if you
>> want to make the doc at the API level.
>>
> If it is a "OR", we need to doc the special behaviors in API level. But
> it is a "AND", I think the current API is clear that a defined
> SNIMatcher is used to match a particular server name type in SNI
> extension. I think the current spec is OK.
I think we can leave it unspecified for now, but please add a quick note
here. Thanks.
>> sun/security/ssl/SSLSocketImpl.java
>> ===================================
>> 561: If I'm remembering and understanding this code right:
>>
>> this.host = sock.getLocalAddress().getHostName(); // in server mode
>>
>> Don't ServerSockets generally creates Sockets with just local IP
>> addresses (no hostnames), so this getHostname() will trigger a reverse
>> hostname lookup? Is that right?
>>
> Right.
>
> It is not really necessary to set the "host" and "serverNames"
> variables, because in server mode the two variables are useless. I will
> remove the setting.
Ok.
561: // In server mode, it is not necessary to set host and serverNames.
Can you add "...and would require a reverse DNS lookup" or something
similar?
>> 2509: Something to investigate: you are depending on SSLParameters
>> returning an unmodifiable list. But a subclass might not do that. Can
>> you think of any situations where this might be a bad idea? If so, then
>> we might want to change the unmodifiable language in SSLParameters and
>> do regular cloning. This will have repercussions in other areas, like
>> around 2527/2532, where you'll need to pass a copy to the Handshaker.
>>
> Well, I understand that something bad would happen if the subclass does
> not follow the method spec while doing method implementation overriding.
Yes, it was just something to think about. Of course, I'm trying to
think of exploit situations, since you're really just hurting yourself
if tweak this in the middle of a handshake.
If I see Joe Darcy around, I'll check in with him.
> Let's have the spec and implementation as it is. We can update the spec
> and implementation if we have strong concerns or a common solution for
> the issue before JDK 8 officially release.
I'm fine with this.
>> sun/security/ssl/X509TrustManagerImpl.java
>> ==========================================
>> OK
>>
> All of other comments are accepted.
>
> I think there is no major concerns so far.
None still outstanding. I looked over the previous comments I've made
and what you've done to address them, and all looks good minus the
little points above.
> Thank you so much for the
> detailed evaluation and comments on both spec and implementation. TLS
> and its implementation is very complicated, your support is the critical
> success factor to deliver quality product.
Thanks, and be sure to give yourself a lot of that credit. With all the
back/forth and development this feature has seen, I think you've done a
great job.
Brad
More information about the security-dev
mailing list