Should applications accessing a user-specified host over HTTPS attempt to provide assistance by looking up its FQDN?

WBOY
Release: 2024-02-14 14:42:07
forward
799 people have browsed it

通过 HTTPS 访问用户指定主机的应用程序是否应该尝试通过查找其 FQDN 来提供帮助?

Accessing applications on user-specified hosts through HTTPS is a common requirement, but some confusion may be encountered in actual applications. For this problem, PHP editor Banana thinks we should try to help by looking up the FQDN. FQDN (Fully Qualified Domain Name) is a fully qualified domain name, including the host name and domain name. By looking up the FQDN, you can ensure that the host specified by the user is accurately located, thereby providing accurate help and services. Therefore, looking up the FQDN is a beneficial strategy when making HTTPS access.

Question content

I am using a golang application that communicates with the server over HTTPS on another host. Specifically, if context matters: Communicate with a Dataproc cluster from a GCE instance in the same Google Cloud project (no special domain setup required).

The server generates a self-signed certificate, which I have manually installed on the client.

Both the server and client are GCE instances on my Google Cloud project (their FQDN is <hostname>.c.<project_id>.internal)

If I try to connect to the server from the client using golang's http.Client, I get an error like this:

failed to verify certificate: x509: certificate is valid for *.c.<project_id>.internal, not <server_hostname>
Copy after login

However, if I pass it its FQDN (<server_hostname>.c.<project_id>.internal), it works out of the box.

FYI, this behavior is consistent with what I see when running cURL:

curl: (60) SSL: no alternative certificate subject name matches target host name '<server_hostname>'
Copy after login

So my question is:

  1. Why doesn't it work with short/partial hostnames? It's in the same domain, so it's part of *.c.<project_id>.internal and it works out of the box, no? Or does it always require that the string passed in be used to actually match the wildcard string (meaning it doesn't do a lookup and only works if you pass in an fqdn)?
  2. What are the best practices when building applications for distribution? Should I add some logic to have it calculate the FQDN so that it can convert the short name into a long name that is more likely to be used with a self-signed certificate, or leave it up to the caller to figure out the cryptic error message? Li>

NOTE: I don't want to skip validation - I just want to better understand what's going on and know what the best practices are here.

Thanks!

Solution

  1. Certificates are matched against domains/hosts based on the names contained within them, so even if <server_hostname> and <server_hostname>.c.<project_id>.internal resolve to Same content, the certificate only contains the second one (or a wildcard matching it). Since these are self-generated, you can add short names in them as SANs (Subject Alternative Names). Additional flags for OpenSSL:
-addext "subjectAltName = DNS:localhost,DNS:<server_hostname>"
Copy after login

It is unlikely that a public CA will provide you with a certificate with a SAN that is not publicly resolvable. (Some possibilities, I haven’t tried it)

As an example, you don't want to serve or trust google.com from google.com.someevildomain.org, so this is a security feature.

  1. It depends on the situation. If you have control over the certificate, just add the name you wish to use. This may end up being a single certificate with many SANs, in which case it may be cleaner to have everyone talk using an FQDN. If you can import many certificates, it's better to have each service have its own certificate with FQDN and short name.

The above is the detailed content of Should applications accessing a user-specified host over HTTPS attempt to provide assistance by looking up its FQDN?. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template