2014-04-04 16 views
9

như được chỉ định trong tài liệu api của nút mà tôi đã thử đầu tiên với chứng chỉ tự tạo và ký bằng cách sử dụng openssl. Tất cả mọi thứ đã đi tốt ngoại trừ thực tế là không thể kiểm tra phía khách hàng từ một android bởi vì nó là cần thiết một chứng chỉ ca. Khi tôi cố gắng phương pháp thứ hai (nghĩa với PFX và không có chìa khóa, cert) https.createserver ném một lỗimac xác minh lỗi bằng cách sử dụng Node với chứng chỉ ssl

crypto.js:145 
     c.context.loadPKCS12(pfx); 
       ^
Error: mac verify failure 
    at Object.exports.createCredentials (crypto.js:145:17) 
    at Server (tls.js:1130:28) 
    at new Server (https.js:35:14) 
    at Object.exports.createServer (https.js:54:10) 
    at Object.<anonymous> (C:\iTollonServer\iTollonServer\iTollonServer\app.js:105:7) 
    at Module._compile (module.js:456:26) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Function.Module.runMain (module.js:497:10) 

mã từ Node Api:

// curl -k https://localhost:8000/ 
var https = require('https'); 
var fs = require('fs'); 

var options = { 
    key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), 
    cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem') 
}; 

https.createServer(options, function (req, res) { 
    res.writeHead(200); 
    res.end("hello world\n"); 
}).listen(8000); 
Or 

var https = require('https'); 
var fs = require('fs'); 

var options = { 
    pfx: fs.readFileSync('server.pfx') 
}; 

https.createServer(options, function (req, res) { 
    res.writeHead(200); 
    res.end("hello world\n"); 
}).listen(8000); 

Trả lời

27

cũng trong trường hợp PFX bạn nên thêm tùy chọn

+7

trong trường hợp bạn đang tìm mẫu mẫu tạm thời để triển khai node.js trong mac, như tôi, tệp mẫu ban đầu không hoàn thành bằng cách chỉ đặt ** agent.set ('pfx file', pfx); **, bạn cũng cần phải thêm một li ne as: ** agent.set ("cụm mật khẩu", ); ** để tránh lỗi xác minh mac –

+0

Dưới đây là các tài liệu liên quan cho các thông số: https://nodejs.org/api/tls .html # tls_tls_createserver_options_securecông cụ kết nối – Coreus

Các vấn đề liên quan