Is it possible to have SSL certificate for IP address, not domain name?

后端 未结 7 1811
南旧
南旧 2020-11-22 15:53

I want my site to use URLs like http://192.0.2.2/... and https://192.0.2.2/... for static content to avoid unnecessary cookies in request AND avoid

7条回答
  •  梦谈多话
    2020-11-22 16:46

    The answer is yes. In short, it is a subject alternative name (SAN) certificate that contains IPs where you would typically see DNS entries. The certificate type is not limited to Public IPs - that restriction is only imposed by a signing authority rather than the technology. I just wanted to clarify that point. I suspect you really just want to get rid of that pesky insecure prompt on your internal websites and devices without the cost and hassle of giving them DNS names then paying for a CA to issue a cert every year or two. You should NOT be trying to convince the world that your IP address is a reputable website and folks should feel comfortable providing their payment information. Now that we have established why no reputable organization wants to issue this type of certificate, lets just do it ourselves with a self signed SAN certificate. Internally I have a trusted certificate that is deployed to all of our hosts, then I sign this type of certificate with it and all devices become trusted. Doing that here is beyond the scope of the question but I think it relevant to the discussion as the question and solution go hand in hand. To be concise, here is how to generate an individual self signed SAN certificate with IP addresses. Expand the IP list to include your entire subnet and use one cert for everything.

    #!/bin/bash
    #using: OpenSSL 1.1.1c FIPS  28 May 2019 / CentOS Linux release 8.2.2004
    
    C=US ; ST=Confusion ; L=Anywhere ; O=Private\ Subnet ; EMAIL=admin@company.com
    BITS=2048
    CN=RFC1918
    DOM=company.com
    SUBJ="/C=$C/ST=$ST/L=$L/O=$O/CN=$CN.$DOM"
    
    openssl genrsa -out ip.key $BITS
    
    SAN='\n[SAN]\nsubjectAltName=IP:192.168.1.0,IP:192.168.1.1,IP:192.168.1.2,IP:192.168.1.3,IP:192.168.1.4,IP:192.168.1.5,IP:192.168.1.6,IP:192.168.1.7,IP:192.168.1.8,IP:192.168.1.9,IP:192.168.1.10'
    
    cp /etc/pki/tls/openssl.cnf /tmp/openssl.cnf
    echo -e "$SAN" >> /tmp/openssl.cnf
    
    openssl req -subj "$SUBJ" -new -x509 -days 10950 \
        -key ip.key -out ip.crt -batch \
        -set_serial 168933982 \
        -config /tmp/openssl.cnf \
        -extensions SAN
    
    openssl x509 -in ip.crt -noout -text
    

提交回复
热议问题