【问题标题】:https certificate issue with subdomain子域的 https 证书问题
【发布时间】:2016-06-24 01:28:39
【问题描述】:

我的应用程序在负载均衡器后面的 EC2 上运行。 已获得 www.example.com 和 *.example.com 的 https 证书。

应用程序在 http 上运行,但 https 已在负载均衡器中设置。

我已经根据公司在我的应用程序中添加了子域支持。

比如,https://XYZ.example.com 代表 XYZ 公司。

如果我使用 https://XYZ.example.com 访问,它工作正常。

如果我使用 https://www.XYZ.example.com 访问,浏览器会发出类似警告,

“www.arun.contactcentral.io 的所有者对其网站的配置不当。为了保护您的信息不被盗,Firefox 没有连接到该网站。”

但是,如果我访问https://www.example.com,它工作正常。

虽然,我已经获得了 *.example.com 的认证,但即使我访问 www.XYZ.example.com,它也不起作用。

我有一个过滤器来处理 http 到 https 的方向,但它仍然没有从 url 过滤 WWW。

public class HttpsFilter implements Filter {

    private static final String HTTP = "http";

    private static final String HTTPS = "https";

    private static final String X_FORWARDED_PROTO = "X-Forwarded-Proto";

    @Override
    public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException {


        HttpServletRequest request = (HttpServletRequest)req;

        HttpServletResponse httpResponse = (HttpServletResponse) res;

        String xfp = request.getHeader(X_FORWARDED_PROTO);

        if (HTTPS.equals(xfp)) {
            //httpResponse.setHeader("Strict-Transport-Security", "max-age=60");

            chain.doFilter(req, res);
            return;
        }
        else if (HTTP.equals(xfp)) {

            String serverUrl = HTTPS+"://"+req.getServerName()+((HttpServletRequest)req).getServletPath();

            httpResponse.sendRedirect(serverUrl);
            return;
        }

    }

}

谢谢, 巴斯卡尔.S

【问题讨论】:

    标签: ssl amazon-ec2


    【解决方案1】:

    通配符 SSL 证书将仅匹配 ONE 级别的子域(极少数且不受支持的情况除外)。通配符星号将不匹配。 (点)。

    因此,*.example.com 的证书将匹配

    • www.example.com
    • xyz.example.com
    • some-really-long-name.example.com

    但它不会匹配

    • example.com
    • www.xyz.example.com
    • abc.def.ghi.example.com

    如果要匹配 www.xyz.example.com 和 xyz.example.com,则需要两个不同的证书。

    https://en.wikipedia.org/wiki/Wildcard_certificate#Limitation

    【讨论】:

    • 我可以拥有 2 个证书。但是,不允许使用 www.*.example.com。我怎样才能做到这一点?我的子域是基于公司的。
    • 你不能。它不受任何公认标准的支持。如果您想在前面放一个“www”,则与 * 匹配的每个子域都需要自己的证书。
    • (同一个证书可以有多个子域,但需要明确命名,不能动态完成。)
    猜你喜欢
    • 2018-08-11
    • 2011-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多