正确configurationCouchdb + SSL Ubuntu。 获取错误:curl:(35)连接到127.0.0.1:6984的未知的SSL协议错误

我正在寻找使用SSL和nodejs的CouchDB,我刚刚从自签名证书(这是工作一个多月)转换到一个真正的SSL证书,现在我遇到了configuration问题。 一路上我分散了几个问题,因为有很多部分,但主要的问题是节点和沙发不再说话。

我有nodejs运行,我正在使用node-spdy扩展( https://www.npmjs.org/package/spdy )

我有SSL证书configuration:

var options = { key: fs.readFileSync(__dirname + '/keys/spdy-key.pem'), cert: fs.readFileSync(__dirname + '/keys/spdy-cert.pem'), ca: fs.readFileSync(__dirname + '/keys/spdy-ca.pem'), }; 

第一个问题:我现在有一个中间证书,我怎么告诉nodejs这个?以前我的证书是自签名的,所以我把csr文件放在ca点(上面),并且正在工作。 实际上,今天尝试一下,csr文件和中间证书似乎在那个地方工作,但这不可能是正确的,因此我的问题。 所以如果是csr,那我该如何正确configuration中间证书呢? 我已经看到这个线程︰https: //stackoverflow.com/questions/19104215/node-js-express-js-chain-certificate-not-working

接下来,当我有自签名证书时,couchdb正在使用SSL。 为了让节点和沙发玩SSL好,我不得不在节点上设置此标志:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

这样就停止了节点退出“自签名”证书的错误。 现在我想删除那个标志。 (原来我从这里得到这个技巧: https : //github.com/mikeal/request/issues/418 )

现在到了主要的问题。 在CouchDB中,我的local.ini有:

 [httpd] ;port = 5984 ;bind_address = 127.0.0.1 ; Options for the MochiWeb HTTP server. ;server_options = [{backlog, 128}, {acceptor_pool_size, 16}] ; For more socket options, consult Erlang's module 'inet' man page. ;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}] ; Uncomment next line to trigger basic-auth popup on unauthorized requests. WWW-Authenticate = Basic realm="administrator" ; Uncomment next line to set the configuration modification whitelist. Only ; whitelisted values may be changed via the /_config URLs. To allow the admin ; to change this value over HTTP, remember to include {httpd,config_whitelist} ; itself. Excluding it from the list would require editing this file to update ; the whitelist. ;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}] [httpd_global_handlers] ;_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>} [couch_httpd_auth] ; If you set this to true, you should also uncomment the WWW-Authenticate line ; above. If you don't configure a WWW-Authenticate header, CouchDB will send ; Basic realm="server" in order to prevent you getting logged out. require_valid_user = true [log] ;level = debug [log_level_by_module] ; In this section you can specify any of the four log levels 'none', 'info', ; 'error' or 'debug' on a per-module basis. See src/*/*.erl for various ; modules. ;couch_httpd = error [os_daemons] ; For any commands listed here, CouchDB will attempt to ensure that ; the process remains alive. Daemons should monitor their environment ; to know when to exit. This can most easily be accomplished by exiting ; when stdin is closed. ;foo = /path/to/command -with args [daemons] ; enable SSL support by uncommenting the following line and supply the PEM's below. ; the default ssl port CouchDB listens on is 6984 httpsd = {couch_httpd, start_link, [https]} [ssl] cert_file = /srv/www/[appname]/keys/cert.pem key_file = /srv/www/[appname]/keys/key.pem ;password = somepassword ; set to true to validate peer certificates ;verify_ssl_certificates = true ; Path to file containing PEM encoded CA certificates (trusted ; certificates used for verifying a peer certificate). May be omitted if ; you do not want to verify the peer. ; cacert_file = /srv/www/[appname]/keys/ca.pem ; The verification fun (optional) if not specified, the default ; verification fun will be used. ;verify_fun = {Module, VerifyFun} ; maximum peer certificate depth ssl_certificate_max_depth = 1 

这个设置是否正确? 我遵循( http://guide.couchdb.org/draft/security.html )和( http://wiki.apache.org/couchdb/How_to_enable_SSL )

但是,当我连接时,我在节点日志中得到这个:

error { [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

当连接的另一端早于nodejs结束时,这通常是一个错误。 所以couchDB正在退出。 而当我运行curl -k -v https://127.0.0.1:6984/来查看是怎么回事,我得到:

 * About to connect() to 127.0.0.1 port 6984 (#0) * Trying 127.0.0.1... * Adding handle: conn: 0x181eab0 * Adding handle: send: 0 * Adding handle: recv: 0 * Curl_addHandleToPipeline: length: 1 * - Conn 0 (0x181eab0) send_pipe: 1, recv_pipe: 0 * Connected to 127.0.0.1 (127.0.0.1) port 6984 (#0) * successfully set certificate verify locations: * CAfile: none CApath: /etc/ssl/certs * SSLv3, TLS handshake, Client hello (1): * Unknown SSL protocol error in connection to 127.0.0.1:6984 * Closing connection 0 curl: (35) Unknown SSL protocol error in connection to 127.0.0.1:6984 

这一切都发生在新的SSL文件之后。 我听说CouchDB不喜欢一些SSLconfiguration? (请参阅https://leap.se/code/issues/883#note-10 )

看起来像一个奇怪的错误输出,如果它只是权限,但你永远不能太确定。 所以,对于pem文件 – 我有/ keys文件夹上的权限设置为700,pem文件上的权限设置为600。 用户是部署用户,沙发在沙发上运行。 所以沙发实际上不能访问这些,正确的? 这是问题吗? 如果是解决scheme,将couchdb用户添加到部署组是最好的行动scheme吗? 这是修复吗? 我总是喜欢在处理权限时进行双重确认。

另外,无论如何,我似乎无法得到validationSSL证书,所以我已经把这个configurationclosures了。 那是问题吗? 我听说沙发需要证书有一个密码才能使这个设置工作。 真的吗? ( http://thinkinginsoftware.blogspot.ca/2012/12/couchdb-unknown-ssl-protocol-error-in.html )我甚至需要这个configuration吗?

最后,在couch.uri文件中,它同时包含http和httpsurl。 所以它启动了2个实例。 现在我可以安全地删除启动的http URL吗?我正在使用SSL还是两者都需要?

保罗

所以,如果有人在他们自己的旅程中遇到这个问题,这里有答案:

当您在节点中设置SSL时,特别是在SPDY中,它要求:

 var options = { key: fs.readFileSync(__dirname + '/keys/spdy-key.pem'), cert: fs.readFileSync(__dirname + '/keys/spdy-cert.pem'), ca: fs.readFileSync(__dirname + '/keys/spdy-ca.pem'), }; 

似乎您可以使用csr(证书签名请求)作为自签名证书的SSL设置中的ca。 但是,在生产服务器上这样做,意味着证书链存在问题(您购买的证书,例如RapidSSL,被链接到GeoTrust等较低级别的证书),因为GeoTrust是一个被浏览器信任)如果你不做ca文件(中间证书文件)在大多数情况下是可以的 – 它会说https://www.ssllabs.com/ssltest中的链断了,但是浏览器似乎不在乎&#x3002; 但正确的方法是把中间证书放在ca点。

至于节点和沙发,问题一定是权限。 我将couchdb用户添加到部署用户组,但由于密钥文件的权限是600,所以该组仍然无法访问。 就我而言,我刚刚为couchDB创build了一个自签名证书。

这意味着我必须通过使用此configuration标志来告诉节点来信任它:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

所以现在沙发和节点谈话和使用SSL。

至于其他一些问题:

基本的openssl用法似乎与couchdb正常工作,所以没有问题与某些证书types或类似的东西,我遇到过

在这个设置中我似乎无法打开沙发的证书validation。 我只是得到SSL: hello: tls_handshake.erl:285:Fatal error: internal error所以留下设置为false工程

看来,你可以安全地从couchdb的couch.uri文件(在/var/run/couchdb/couch.urifind)中删除http服务器,只需要一个。

希望这可以帮助别人,

保罗

couchdbssl是绝望的(至less现在是这样)。 这似乎是在基础erlang库中的一个错误。 我花了两天没有运气。 现在我尝试使用nginx作为代理…