问题原文
原帖链接 · bug_2 · CC BY-SA 4.0
I would like to ask how to generate end entity certificate based on my own CA root certificate? I've generated root CA this way:
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout example.key -out example.crt -subj /CN=MyCompany \
-addext subjectAltName=IP:192.168.100.82
openssl pkcs12 -export -out cert.pfx -inkey example.key -in example.crt
I have imported cer file to Windows Trusted Root Certification Authorities and pfx file into IIS Server Certificates.
It works well with Chrome, IE and Edge, but Firefox reports a problem with my cert: MOZILLA_PKIX_ERROR_CA_CERT_USED_AS_END_ENTITY
I googled it and I learnt that I should have end-entity cert signed by my CA root cert. I was trying to generate end-entity cert with:
openssl genrsa -out server.key 4096
openssl req -new -key server.key -out server.csr -subj /CN=MyCompanyEE -addext subjectAltName=IP:192.168.100.82
openssl x509 -req -in server.csr -CA cert.pem -CAkey example.key -CAcreateserial -out server.crt -days 3650 -sha256
openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt
OpenSSL response:
Signature ok
subject=CN = MyCompanyEE
Getting CA Private Key
I have imported server.pfx into IIS Server Certificates too, and changed bindings for my web app to use server cert, but now it doesn't work in either Firefox or Chrome.
Firefox says: SSL_ERROR_BAD_CERT_DOMAIN,
Chrome says: NET::ERR_CERT_COMMON_NAME_INVALID.
What I'm doing wrong?
已采纳解答
原帖链接 · bug_2 · CC BY-SA 4.0
I wasn't able to generate certificate with OpenSSL for local website (available in intranet at 192.168.100.82:997) so - according to @Crypt32 advice - I changed approach and I've used PowerShell. You can find my working solution below:
- Run PowerShell as administartor.
Use below code for generating selfsigned root authority (MyCompany CA) and server (MyCompany) certificates:
$authorityCert = New-SelfSignedCertificate ` -Subject "CN=MyCompany CA,OU=IT,O=MyCompany Certificate Authority,C=US" ` -KeyAlgorithm RSA ` -KeyLength 4096 ` -KeyUsage CertSign, CRLSign, DigitalSignature, KeyEncipherment, DataEncipherment ` -KeyExportPolicy Exportable ` -NotBefore (Get-Date) ` -NotAfter (Get-Date).AddYears(10) ` -HashAlgorithm SHA256 ` -CertStoreLocation "Cert:\LocalMachine\My" ` -FriendlyName "MyCompany CA" ` -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1", "2.5.29.19={critical}{text}ca=1") $devCert = New-SelfSignedCertificate ` -Subject "CN=MyCompany,OU=App Test,O=MyCompany,C=US" ` -KeyAlgorithm RSA ` -KeyLength 4096 ` -KeyUsage DigitalSignature, KeyEncipherment, DataEncipherment ` -KeyExportPolicy Exportable ` -NotBefore (Get-Date) ` -NotAfter (Get-Date).AddYears(10) ` -HashAlgorithm SHA256 ` -CertStoreLocation "Cert:\LocalMachine\My" ` -FriendlyName "MyCompany" ` -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1", "2.5.29.17={text}IPAddress=192.168.100.82") ` -Signer $authorityCert $directory = "C:\Users\bug_2\Certificates\" if(!(test-path $directory)) { New-Item -ItemType Directory -Force -Path $directory } $authorityCertPath = 'Cert:\LocalMachine\My\' + ($authorityCert.ThumbPrint) $authorityCertFilename = $directory + "Authority.cer" Export-Certificate -Cert $authorityCertPath -FilePath $authorityCertFilename $devCertPath = 'Cert:\LocalMachine\My\' + ($devCert.ThumbPrint) $devCertFilename = $directory + "Dev.cer" Export-Certificate -Cert $devCertPath -FilePath $devCertFilenameAdd root certificate to Trusted Root Certification Authorities in your system by press WIN+R, type: mmc, hit ENTER. In Microsoft Management Console choose
File->Add or Remove Snap-insand then, in new window,Certificates -> Add -> OK. ExpandCertificates->Trusted Root Certification Authorities. Right click on Certificates catalog placed inside Trusted Root Certification Authorities and chooseAll Tasks->Import...and selectAuthority.cerfile fromC:\Users\bug_2\Certificates\. Apply changes and close Microsoft Management Console.You can finds your new certificates (root and server) in IIS without any extra steps. Choose your website in IIS, click
Bindings...->Editand select server certificate (MyCompany). Apply changes.My website is available now at
https://192.168.100.82:997on every web browsers (like Chrome, IE, Edge) except Firefox. For fix that run Firefox, typeabout:configin address bar and setsecurity.enterprise_roots.enabledto true. Restart Firefox.
Now my localwebsite is available in intranet at https://192.168.100.82:997.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
