# create a root authority cert./create_root_cert_and_key.sh
# create a wildcard cert for mysite.com./create_certificate_for_domain.sh mysite.com
# or create a cert for www.mysite.com, no wildcards./create_certificate_for_domain.sh www.mysite.com www.mysite.com
#!/usr/bin/env bash
if [ -z "$1" ]thenecho "Please supply a subdomain to create a certificate for";echo "e.g. www.mysite.com"exit;fi
if [ ! -f rootCA.pem ]; thenecho 'Please run "create_root_cert_and_key.sh" first, and try again!'exit;fiif [ ! -f v3.ext ]; thenecho 'Please download the "v3.ext" file and try again!'exit;fi
# Create a new private key if one doesnt exist, or use the xeisting one if it doesif [ -f device.key ]; thenKEY_OPT="-key"elseKEY_OPT="-keyout"fi
DOMAIN=$1COMMON_NAME=${2:-*.$1}SUBJECT="/C=CA/ST=None/L=NB/O=None/CN=$COMMON_NAME"NUM_OF_DAYS=825openssl req -new -newkey rsa:2048 -sha256 -nodes $KEY_OPT device.key -subj "$SUBJECT" -out device.csrcat v3.ext | sed s/%%DOMAIN%%/"$COMMON_NAME"/g > /tmp/__v3.extopenssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days $NUM_OF_DAYS -sha256 -extfile /tmp/__v3.ext
# move output files to final filenamesmv device.csr "$DOMAIN.csr"cp device.crt "$DOMAIN.crt"
# remove temp filerm -f device.crt;
echoecho "###########################################################################"echo Done!echo "###########################################################################"echo "To use these files on your server, simply copy both $DOMAIN.csr and"echo "device.key to your webserver, and use like so (if Apache, for example)"echoecho " SSLCertificateFile /path_to_your_files/$DOMAIN.crt"echo " SSLCertificateKeyFile /path_to_your_files/device.key"
[ req ]default_bits = 4096distinguished_name = req_distinguished_namereq_extensions = req_ext
[ req_distinguished_name ]countryName = Country Name (2 letter code)stateOrProvinceName = State or Province Name (full name)localityName = Locality Name (eg, city)organizationName = Organization Name (eg, company)commonName = Common Name (e.g. server FQDN or YOUR name)commonName_max = 64
[ req_ext ]subjectAltName = @alt_names
[alt_names]DNS.1 = localhost
对于Fedora,Ubuntu,Linux,如果您在使用gui添加证书以添加新的根权限时遇到example.com Not a Certification authority错误。如果您想信任服务器自签名证书,它不能提及无效的权威…即使它本身。我只能通过信任我的权限并使用该权限密钥签署服务器证书来使其工作。
New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -Subject "fruity.local" -DnsName "fruity.local", "*.fruity.local" -FriendlyName "FruityCert" -NotAfter (Get-Date).AddYears(10)#notes:# -subject "*.fruity.local" = Sets the string subject name to the wildcard *.fruity.local# -DnsName "fruity.local", "*.fruity.local"# ^ Sets the subject alternative name to fruity.local, *.fruity.local. (Required by Chrome v58 and later)# -NotAfter (Get-Date).AddYears(10) = make the certificate last 10 years. Note: only works from Windows Server 2016 / Windows 10 onwards!!
Created a new local CA at "/Users/filippo/Library/Application Support/mkcert" 💥The local CA is now installed in the system trust store! ⚡️The local CA is now installed in the Firefox trust store (requires browser restart)! 🦊
Using the local CA at "/Users/filippo/Library/Application Support/mkcert" ✨
Created a new certificate valid for the following names 📜- "example.com"- "*.example.com"- "example.test"- "localhost"- "127.0.0.1"- "::1"
The certificate is at "./example.com+5.pem" and the key at "./example.com+5-key.pem" ✅
####################### Become a Certificate Authority######################
# Generate private keyopenssl genrsa -des3 -out myCA.key 2048# Generate root certificateopenssl req -x509 -new -nodes -key myCA.key -sha256 -days 825 -out myCA.pem
####################### Create CA-signed certs######################
NAME=mydomain.example # Use your own domain name# Generate a private keyopenssl genrsa -out $NAME.key 2048# Create a certificate-signing requestopenssl req -new -key $NAME.key -out $NAME.csr# Create a config file for the extensions>$NAME.ext cat <<-EOFauthorityKeyIdentifier=keyid,issuerbasicConstraints=CA:FALSEkeyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEnciphermentsubjectAltName = @alt_names[alt_names]DNS.1 = $NAME # Be sure to include the domain name here because Common Name is not so commonly honoured by itselfDNS.2 = bar.$NAME # Optionally, add additional domains (I've added a subdomain here)IP.1 = 192.168.0.13 # Optionally, add an IP address (if the connection which you have planned requires it)EOF# Create the signed certificateopenssl x509 -req -in $NAME.csr -CA myCA.pem -CAkey myCA.key -CAcreateserial \-out $NAME.crt -days 825 -sha256 -extfile $NAME.ext
好的,假设您创建了一个“有效”的自签名证书。它在chrome ver 94上安装正确。但是当您访问该站点时,您不会收到ssl锁并收到“无效证书颁发机构”错误。事实上,这是一个有效的证书。但是如果您没有正确浏览该站点,您将收到此错误。我的证书的DNS是DNS1:TFDM,DNS2:TFDM.local,DNS3:172.31.42.251,DNS4:192.168.20.50。