received handshake warning: unrecognized_name

前端 未结 1 1321
广开言路
广开言路 2021-01-25 20:12

Is there a way to deal in Java 11 with a \"javax.net.ssl.SSLHandshakeException: received handshake warning: unrecognized_name\" without disabling SNI system wide by using

<
相关标签:
1条回答
  • 2021-01-25 21:02

    Okay, I went through the source and found a way, although I'm not sure how enthusiastically I recommend it.

    Although the javadoc for SSLParameters.setServerNames doesn't say so, if the value set is an empty List (with no elements), then ClientHandshaker actually sends no SNI at all. I suspect this is because the RFCs e.g. for 1.2 specify the min size as 1, prohibiting an empty list. (Compare to certificate_list in the Certificate message in TLS vs SSL; in SSL the min size was 1, and a client with no cert&key suitable for a server request didn't send the message at all, while in TLS it is 0, and a client with no suitable cert&key is explicitly specified to send a message containing an empty list.) While this is logical, since it is neither documented nor explicitly commented, I wouldn't be really happy relying on it.

    Since it is pretty complicated (and fragile) to directly determine the other parameters needed, I think the best approach is to start from the existing parameters and modify, e.g. for SSLSocket:

    SSLSocket s = SSLSocketFactory.getDefault() /* or other */ .createSocket("host", 443);
    SSLParameters p = s.getSSLParameters();
    p.setServerNames( new ArrayList<SNIServerName>() );
    /* or j9+ p.setServerNames( List<SNIServerName>.of() ); */
    s.setSSLParameters(p);
    ...
    

    and for HttpsURLConnection, your original SSLSocketFactoryWrapper approach is quite close, except as above I would modify based on the actual parameters for the created SSLSocket and you must use the empty new ArrayList<SNIServerName>() and not .add anything to it.

    Something very similar should work for Apache HttpClient, but I haven't gone through it, because I find that annoyingly like a maze of twisty little classes all alike.

    PS: the source also confirms why varying sysprop jsse.enableSNIExtension won't work; that (like many others) is read and cached when JSSE is first loaded and not read subsequently. You could use reflection to break into the class and change the cached value, but let's not go there.

    0 讨论(0)
提交回复
热议问题