2017-03-15 2 views
4

Windows 10에서 Express.js의 자체 서명 인증서를 사용하여 localhost에 사이트를 설정하려고합니다. 다음은 Express.js 서버 코드입니다.SSL 자체 서명 인증서의 Chrome (net :: ERR_CERT_COMMON_NAME_INVALID) 오류

하는 index.js

const https = require('https') 
const express = require('express') 
const app = express() 
const fs = require('fs') 
const path = require('path') 

const httpsOptions = { 
    cert: fs.readFileSync(path.resolve(__dirname, 'ssl', 'ca.crt')), 
    key: fs.readFileSync(path.resolve(__dirname, 'ssl', 'ca.key')) 
} 

const router = require('./router') 

app.use('/people', router) 

https.createServer(httpsOptions, app) 
    .listen(3443) 

는 또한 인증 기관 ca.crt 크롬에 파일을 수입, 크롬을 다시 시작했다. 아래 그림과 같이하지만 난 여전히 크롬에 오류가 있습니다

enter image description here

이 문제를 감사


나는 다음과 같은 명령을 사용하여 키와 인증서를 만든을 해결하는 방법을 안내하시기 바랍니다.

# certificate authority key 
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out ca.key 

# server key 
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out server.key 

# certificate authority 
openssl req -new -x509 -days 365 -key ca.key -subj "/CN=Test CA/O=Test Organization" -out ca.crt 

# certificate signing request 
openssl req -new -key server.key -subj "/CN=localhost/O=Test Organization" -out server.csr 

# server certificate 
openssl x509 -days 365 -req -in server.csr -CAcreateserial -CA ca.crt -CAkey ca.key -out server.crt 

# verification 
openssl verify -verbose -CAfile ca.crt server.crt 

시스템 정보

  • 은 OpenSSL : 1.1.0e 2017년 2월 16일
  • 노드 : 7.7.1
  • 윈도우 10
+1

당신은 여기 [보고 할 수 있습니다 ] (http://stackoverflow.com/questions/27294589/creating-self-signed-certificate-for-domain-and-subdomains-neterr-cert-commo), 귀하의 문제와 비슷할 것으로 보입니다 – Frederic

+3

최종 개체/서버 인증서 형식이 잘못되었습니다. ***'CN = localhost' ***가 잘못되었습니다. 호스트 이름은 항상 * SAN *에 있습니다. * CN *에있는 경우, * SAN *에도 있어야합니다 (이 경우 두 번 나열해야합니다). 자세한 규칙 및 이유는 [인증 기관의 인증서 서명 요청 서명 방법] (http://stackoverflow.com/a/21340898/608639) 및 [openssl을 사용하여 자체 서명 된 인증서를 만드는 방법] (http://stackoverflow.com/q/10175812/608639) – jww

+1

@jww CN = Common Name, SAN은 무엇을 의미합니까? –

답변

0

몇 지출 이 문제를 해결하기 위해 노력하고 있습니다. 다음 방법은 나를 위해 일한 :

[req] 
distinguished_name = req_distinguished_name 
x509_extensions = v3_req 
prompt = no 
    [req_distinguished_name] 
C = US 
ST = VA 
L = SomeCity 
O = MyCompany 
OU = MyDivision 
CN = local.com 
    [v3_req] 
keyUsage = critical, digitalSignature, keyAgreement 
extendedKeyUsage = serverAuth 
subjectAltName = @alt_names 
    [alt_names] 
DNS.1 = local.com 
IP.1 = 127.0.0.1 

를 (예를 들어 req.cnf에 대한) 설정 파일을 작성하고 인증서를 생성 및 개인 키

openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout local.com.key -out local.com.cert -config req.cnf -sha256