Getting Chrome to accept self-signed localhost certificate

后端 未结 30 2920
小蘑菇
小蘑菇 2020-11-21 11:30

I have created a self-signed SSL certificate for the localhost CN. Firefox accepts this certificate after initially complaining about it, as expected. Chrome and IE, however

30条回答
  •  盖世英雄少女心
    2020-11-21 12:09

    UPDATE FOR CHROME 58+ (RELEASED 2017-04-19)

    As of Chrome 58, the ability to identify the host using only commonName was removed. Certificates must now use subjectAltName to identify their host(s). See further discussion here and bug tracker here. In the past, subjectAltName was used only for multi-host certs so some internal CA tools don't include them.

    If your self-signed certs worked fine in the past but suddenly started generating errors in Chrome 58, this is why.

    So whatever method you are using to generate your self-signed cert (or cert signed by a self-signed CA), ensure that the server's cert contains a subjectAltName with the proper DNS and/or IP entry/entries, even if it's just for a single host.

    For openssl, this means your OpenSSL config (/etc/ssl/openssl.cnf on Ubuntu) should have something similar to the following for a single host:

    [v3_ca]   # and/or [v3_req], if you are generating a CSR
    subjectAltName = DNS:example.com
    

    or for multiple hosts:

    [v3_ca]   # and/or [v3_req], if you are generating a CSR
    subjectAltName = DNS:example.com, DNS:host1.example.com, DNS:*.host2.example.com, IP:10.1.2.3
    

    In Chrome's cert viewer (which has moved to "Security" tab under F12) you should see it listed under Extensions as Certificate Subject Alternative Name:

提交回复
热议问题