Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HostnameVerifier vs TrustManager?

Tags:

java

https

ssl

jsse

Under what circumstances would one use a HostnameVerifier over a TrustManager in Java? Is one recommended over the other? Looking at the Java docs (Interface HostnameVerifier and Interface TrustManager), I can't tell when its best to use either (though the TrustManager seems more versatile).

In the past, I have always used a custom TrustManager. However, I noticed Heartbleed exploit in java uses both (but I don't think its correct).

EDIT: when using HostnameVerifier, are the other customary X509 checks performed, like path building and expiration and revocation (if configured)? I think I am essentially asking if HostnameVerifier supplements the other checks (rather than replacing them).

For example, suppose a dev server is at dev.example.com and its signed by an internal CA. There's one DNS name in dev.example.com's certificate, and its dev.example.com. Further, suppose I connect to it as 192.168.1.10. Could I use a HostnameVerifier to allow both dev.example.com and 192.168.1.10? In this scenario, is the additional name allowed and are the other customary X509 checks are performed?

like image 687
jww Avatar asked May 11 '14 10:05

jww


People also ask

What is HostnameVerifier in Java?

public interface HostnameVerifier. This class is the base interface for hostname verification. During handshaking, if the URL's hostname and the server's identification hostname mismatch, the verification mechanism can call back to implementers of this interface to determine if this connection should be allowed.

What is TrustManager in Java?

TrustManager s are responsible for managing the trust material that is used when making trust decisions, and for deciding whether credentials presented by a peer should be accepted. TrustManager s are created by either using a TrustManagerFactory , or by implementing one of the TrustManager subclasses.


1 Answers

Under what circumstances would one use a HostnameVerifier over a TrustManager in Java?

Never. They do different things. TrustManage authenticates certificates as part of SSL. HostnameVerifier verifies host names as part of HTTPS. They're not in competition.

Is one recommended over the other?

No.

EDIT

  • The TrustManager runs during the TLS handshake. If it indicates failure, the handshake is aborted and the connect fails.
  • The HostnameVerifier runs after the TLS handshake, over a TLS connection that is already valid from the TLS point of view, so at that point you know that the certificate is valid, signed by a trusted issuer, non-expired (?), etc., and all you have to do is decide (a) whether it's from the correct server and (b) whether you trust that server. You might do (b) inside a TrustManager, but far more commonly you wouldn't provide your own TrustManager at all.
like image 110
user207421 Avatar answered Oct 11 '22 12:10

user207421