時間:2023-07-24 15:24:01 | 來源:網(wǎng)站運營
時間:2023-07-24 15:24:01 來源:網(wǎng)站運營
如何在私有網(wǎng)站使用并創(chuàng)建https的證書:證書是如何生成的及ssl加密原理是什么樣的?openssl req -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr
證書簽名請求輸出兩個文件。一個是[organization_domain_name].crt,另一個是intermediate.crt(如果您的中間 CA 是 GoDaddy,則稱為gd-bundle-g2-.crt)# Generate CA private key openssl genrsa -des3 -passout pass:demo -out ca.key 2048# Generate CSR openssl req -new -key ca.key -out ca.csr
系統(tǒng)將提示您輸入密碼,我建議不要跳過并確保安全。Generating RSA private key, 2048 bit long modulus.................................................................+++.....................................+++e is 65537 (0x10001)Enter pass phrase for ca.key:Verifying - Enter pass phrase for ca.key:
然后我們生成一個根證書:openssl req -x509 -new -nodes -key ca.key -sha256 -days 1825 -out ca.pem# 或者使用下面 生成crt文件# Generate Self Signed certificate(CA 根證書) openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt Enter pass phrase for ca.key:You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [AU]:CNState or Province Name (full name) [Some-State]:GuangdongLocality Name (eg, city) []:ShenZhengOrganization Name (eg, company) [Internet Widgits Pty Ltd]: demoOrganizational Unit Name (eg, section) []: demoCommon Name (e.g. server FQDN or YOUR name) []: demo1Email Address []:1062186165@qq.com
您現(xiàn)在應(yīng)該有兩個文件:ca.key(私鑰)和 ca.pem(根證書)還有一個 ca.csr。# private key openssl genrsa -aes256 -passout pass:111111 -out server.key 2048# generate csr openssl req -new -key server.key -out server.csr
使用 CA 證書及CA密鑰 對請求簽發(fā)證書進(jìn)行簽發(fā),生成 x509證書# generate certificate openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key # 或者使用openssl x509 -req -days 3650 -in server.csr -CA ca.pem -CAkey ca.key -passin pass:111111 -CAcreateserial -out server.crt
客戶端用戶證書:openssl genrsa -des3 -out client.key 1024 openssl req -new -key client.key -out client.csr openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key
生成pem格式證書:cat client.crt client.key> client.pemcat server.crt server.key > server.pem
* 客戶端證書包含 client.pem server.key server.csr server.crtopenssl genrsa -out private.key 2048
然后我們創(chuàng)建一個CSR:openssl req -new -key private.key -out cert.csr
您將得到與上述相同的所有步驟,而且您的輸出證書的內(nèi)容并不重要。openssl x509 -req -in cert.csr /-CA ca.pem -CAkey ca.key -CAcreateserial /-out server.crt -days 825 -sha256 /-extfile server.ext
配置文件 (server.ext) 包含以下內(nèi)容:subjectKeyIdentifier = hashbasicConstraints = critical, CA:truekeyUsage = critical, digitalSignature, nonRepudiation, keyEncipherment, keyCertSignsubjectAltName = @alt_names[alt_names]# 需要添加https的域名DNS.1 = www.baidu.com
我現(xiàn)在有三個文件:private.key(私鑰)、server.csr(證書簽名請求)和 server.crt(簽名證書)。import ( "fmt" "net/http")func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi, This is an example of https service in golang!")}func main() { http.HandleFunc("/", handler) err := http.ListenAndServeTLS(":443", "server.crt", "private.key", nil) if err != nil { panic(err) }}
訪問https://localhost, 此時訪問本地localhost因為不信任的問題訪問不通,需要在mac上面信任這個證書才行。關(guān)鍵詞:創(chuàng)建,證書,使用,私有
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。