2013-01-17 30 views
7

自己署名付きでクライアントの承認をしようとしています。node.jsのクライアントssl認証

まず、i`m作成証明書:

CA証明書

openssl genrsa -des3 -out ca.key 2048 
openssl req -new -x509 -days 365 -key ca.key -out ca.crt 

サーバ証明書

openssl genrsa -out server.key 1024 
openssl req -new -key server.key -out server.csr 
openssl x509 -req -in server.csr -out server.crt -CA ca.crt -CAkey ca.key -CAcreateserial -days 365 

クライアントsertificate

openssl genrsa -out client.key 1024 
openssl req -new -key client.key -out client.csr 
openssl x509 -req -in client.csr -out client.crt -CA ca.crt -CAkey ca.key -CAcreateserial -days 365 

変換クライアントCERTI P12

openssl pkcs12 -export -in client.crt -inkey client.key -name "My cert" -out client.p12 

オープンにficateとP12証明書 オープンclient.p12(express.jsを使用して)

私のNode.jsサーバー

var express = require('express') 
    , routes = require('./routes') 
    , user = require('./routes/user') 
    , http = require('http') 
    , path = require('path') 
    , https = require('https') 
    , fs = require('fs'); 

var app = express(); 

app.configure(function() { 
    app.set('port', process.env.PORT || 3000); 
    app.set('views', __dirname + '/views'); 
    app.set('view engine', 'ejs'); 
    app.use(express.favicon()); 
    app.use(express.logger('dev')); 
    app.use(express.bodyParser()); 
    app.use(express.methodOverride()); 
    app.use(app.router); 
    app.use(express.static(path.join(__dirname, 'public'))); 
}); 

app.configure('development', function() { 
    app.use(express.errorHandler()); 
}); 

app.get('/', function(req, res) { 
    console.log(req.client.authorized); 
    res.send(req.client.authorized) 
}); 

var options = { 
    key:fs.readFileSync('ssl/server.key'), 
    cert:fs.readFileSync('ssl/server.crt'), 
    ca:[fs.readFileSync('ssl/ca.crt')], 
    requestCert:true, 
    rejectUnauthorized:false, 
    passphrase: 'passphrase', 
    agent: false 
    }; 

    https.createServer(options,app).listen(app.get('port'), function() { 
     console.log("Express server listening on port " + app.get('port')); 
    }); 

サーバが実行されている場合、私はhttps://localhost:3000を開くをインストールChromeでは、認証は成功しません。req.client.authorizedはfalseです。

Chromeのメッセージは

です
The identity of this website has not been verified. 
• Server's certificate does not match the URL. 

私の間違いはどこですか?

答えて

2

HTTPSをサポートする場合は、request.connection.verifyPeer()request.connection.getPeerCertificate()を使用して、クライアントの認証の詳細を取得します。

http://nodejs.org/api/http.html#http_request_connection

+0

クライアント証明書リクエストは、 'requestCert:true'を介してコードサンプルで既にアクティブです。サーバーは要求ハンドラでクライアント証明書を要求できません。証明書交換はSSLハンドシェイクの一部として(要求が処理される前に)行われるため、サーバーオプションで設定する必要があります。 – ttreitlinger

3

サーバーのURLは、サーバ証明書の共通名部分と照合されます。

サーバー証明書要求を作成するときは、サーバーのホスト名をCommon Name(共通名)部分に入れてください。ローカルでテストする場合は(アドレスとしてhttps://localhostを使用)、localhostをCommon Nameとして使用します。

関連する問題