Node.js v0.10.x(freebsd)"X509_STORE_add_cert:证书已在哈希表中" [英] Nodejs v0.10.x (freebsd) "X509_STORE_add_cert:cert already in hash table"

查看:170
本文介绍了Node.js v0.10.x(freebsd)"X509_STORE_add_cert:证书已在哈希表中"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用异步网络api,并且在高于v0.8.9的nodejs版本中存在问题

I'm work with async web api and have a problem in nodejs version higer than v0.8.9

$ uname -a FreeBSD主页9.1-稳定FreeBSD 9.1-稳定#0:星期五2月1日10:38:27 EET 2013 root @ home:/usr/obj/usr/src/sys/HOME amd64

$ uname -a FreeBSD home 9.1-STABLE FreeBSD 9.1-STABLE #0: Fri Feb 1 10:38:27 EET 2013 root@home:/usr/obj/usr/src/sys/HOME amd64

$节点-v v0.10.0

$ node -v v0.10.0

$节点./client.js

$ node ./client.js

    events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: 34401711104:error:0B07C065:x509 certificate routines:X509_STORE_add_cert:cert already in hash table:../deps/openssl/openssl/crypto/x509/x509_lu.c:357:
34401711104:error:0B07C065:x509 certificate routines:X509_STORE_add_cert:cert already in hash table:../deps/openssl/openssl/crypto/x509/x509_lu.c:357:

    at SlabBuffer.use (tls.js:221:18)
    at CleartextStream.read [as _read] (tls.js:408:29)
    at CleartextStream.Readable.read (_stream_readable.js:293:10)
    at tls.js:465:12
    at process._tickCallback (node.js:415:13)

代码(client.js):

Code (client.js):

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

var config={
    host:           'sample.host.com',
    port:           443,
    path:           '/worker.do',
    pfx:            fs.readFileSync('./client.pfx'),
    passphrase:     "passwordHere"
};

config.agent = new https.Agent({
    pfx: config.pfx,
    passphrase: config.passphrase
});

agent.config=config;

agent.makeRequest([{request:"search",query:"*"}],function(data){
    if(!data.success){
        console.log(data.error);
        return;
    }

    var items=[];

    for(var item in data.data){
        items.push(data.data[item][0]);
    }

    agent.makeRequest([{"request":"update","group":true,"arr":JSON.stringify(items)}],function(data){
        if(!data.success){
            console.log(data.error);
            return;
        }

        console.log('Done: '+data.result);
    });

}); 

代码(agent.js):

Code (agent.js):

var https = require('https');

var agent={
    config: {},
    getId: function() {
        return this.id || (this.id = new Date().getTime());
    },
    makeRequest: function(params,callback){
        var options = {
            host: this.config.host,
            port: this.config.port,
            path: '/worker.do',
            method: 'POST',
            agent: this.config.agent
        };

        var that=this;
        var req = https.request(options, function(res) {
            if(res.statusCode!='200'){
                callback({
                    success:    false,
                    error:      res.statusCode
                });
                return;
            }

            var body='';
            res.on('data', function(data) {
                body+=data.toString();
            });

            res.on('end', function(){
                try {
                    body=JSON.parse(body);
                } catch(e) {
                    callback({
                        success:    false,
                        error:      '[makeRequest] Cant parse body: '+body
                    });
                }

                var reqId=body[0];
                that.getContent(reqId,callback);
            });
        });

        req.on('error', function(e) {
            callback({
                success:    false,
                error:      e
            });
        });

        req.end(JSON.stringify(params)+'\n\n');
    },

    getContent: function(reqId,callback){
        var options = {
            path: '/worker.do?_dc='+this.getId(),
            method: 'GET',
            host: this.config.host,
            port: this.config.port,
            agent: this.config.agent
        };

        var req = https.request(options, function(res) {
            if(res.statusCode!='200'){
                callback({
                    success:    false,
                    error:      res.statusCode
                });
                return;
            }

            var body='';
            res.on('data', function(data) {
                body+=data.toString();
            });

            res.on('end', function(){
                try {
                    body=JSON.parse(body);
                } catch(e) {
                    callback({
                        success:    false,
                        error:      '[getContent] Cant parse body: '+body
                    });
                }           

                callback(body[reqId]);
            });
        });

        req.on('error', function(e) {
            callback({
                success:    false,
                error:      e
            });
        });

        req.end();

    }
}

exports.agent=agent;

在nodejs v0.6.x和v0.8.x上,它可以完美运行.在v0.10.x上-失败. 请帮助找到问题.

On nodejs v0.6.x and v0.8.x it works perfect. On v0.10.x -- fail. Please help to find the problem.

推荐答案

解决方案是隔离您的PEM,并将它们一个一个地添加回去,而不是捆绑在一起.在最低的叶子处,然后是父级,然后是父级,依此类推,并进行每次测试.

The solution is to isolate your PEMs and add them back one by one, not as a bundle. At the lowest leaf, then the parent, then the parent, etc and test each time.

请参见 https://github.com/iojs/io.js/issues/712

我认为这一定是node.js/io.js内部的一个错误,在此错误中,第一次使用重复证书就不会对其进行检查.

I'm thinking this must be a bug in the internals of node.js / io.js where duplicate certs aren't checked the very first time they're used.

奇怪的是,将证书添加到特定https服务器实例的链中会导致不相关的https请求(该请求应使用默认链,与https服务器无关).

What's odd is that adding a cert to the chain for a specific https server instance can cause an unrelated https request (which should be using the default chain, not anything to do with the https server).

这篇关于Node.js v0.10.x(freebsd)"X509_STORE_add_cert:证书已在哈希表中"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆