{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/node/pulls/comments/86650400","pull_request_review_id":7301230,"id":86650400,"diff_hunk":"@@ -0,0 +1,63 @@\n+'use strict';\n+const common = require('../common');\n+const fs = require('fs');\n+\n+if (!common.hasCrypto) {\n+  common.skip('missing crypto');\n+  return;\n+}\n+const tls = require('tls');\n+\n+function filenamePEM(n) {\n+  return require('path').join(common.fixturesDir, 'keys', n + '.pem');\n+}\n+\n+function loadPEM(n) {\n+  return fs.readFileSync(filenamePEM(n));\n+}\n+\n+var caCert = loadPEM('ca1-cert');\n+var contextWithoutCert = tls.createSecureContext({});\n+var contextWithCert = tls.createSecureContext({});\n+// Adding a CA certificate to contextWithCert should not also add it to\n+// contextWithoutCert. This is tested by trying to connect to a server that\n+// depends on that CA using contextWithoutCert.\n+contextWithCert.context.addCACert(caCert);\n+\n+var serverOptions = {\n+  key: loadPEM('agent1-key'),\n+  cert: loadPEM('agent1-cert'),\n+};\n+var server = tls.createServer(serverOptions, function() { });\n+\n+var clientOptions = {\n+  port: undefined,\n+  ca: [caCert],\n+  servername: 'agent1',\n+  rejectUnauthorized: true,\n+};\n+\n+function startTest() {\n+  // This client should fail to connect because it doesn't trust the CA\n+  // certificate.\n+  clientOptions.secureContext = contextWithoutCert;\n+  clientOptions.port = server.address().port;\n+  var client = tls.connect(clientOptions, common.fail);\n+  client.on('error', function() {\n+    client.destroy();\n+\n+    // This time it should connect because contextWithCert includes the needed\n+    // CA certificate.\n+    clientOptions.secureContext = contextWithCert;\n+    var client2 = tls.connect(clientOptions, function() {","path":"test/parallel/test-tls-addca.js","position":52,"original_position":52,"commit_id":"dd784891fed42fad3fa2e61e782551252bf94c86","original_commit_id":"dd784891fed42fad3fa2e61e782551252bf94c86","user":{"login":"indutny","id":238531,"avatar_url":"https://avatars.githubusercontent.com/u/238531?v=3","gravatar_id":"","url":"https://api.github.com/users/indutny","html_url":"https://github.com/indutny","followers_url":"https://api.github.com/users/indutny/followers","following_url":"https://api.github.com/users/indutny/following{/other_user}","gists_url":"https://api.github.com/users/indutny/gists{/gist_id}","starred_url":"https://api.github.com/users/indutny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indutny/subscriptions","organizations_url":"https://api.github.com/users/indutny/orgs","repos_url":"https://api.github.com/users/indutny/repos","events_url":"https://api.github.com/users/indutny/events{/privacy}","received_events_url":"https://api.github.com/users/indutny/received_events","type":"User","site_admin":false},"body":"Also, `common.mustCall`.","created_at":"2016-11-04T23:45:17Z","updated_at":"2016-11-04T23:46:28Z","html_url":"https://github.com/nodejs/node/pull/9409#discussion_r86650400","pull_request_url":"https://api.github.com/repos/nodejs/node/pulls/9409","_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments/86650400"},"html":{"href":"https://github.com/nodejs/node/pull/9409#discussion_r86650400"},"pull_request":{"href":"https://api.github.com/repos/nodejs/node/pulls/9409"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/9409","id":91870261,"html_url":"https://github.com/nodejs/node/pull/9409","diff_url":"https://github.com/nodejs/node/pull/9409.diff","patch_url":"https://github.com/nodejs/node/pull/9409.patch","issue_url":"https://api.github.com/repos/nodejs/node/issues/9409","number":9409,"state":"open","locked":false,"title":"Certstore","user":{"login":"agl","id":21203,"avatar_url":"https://avatars.githubusercontent.com/u/21203?v=3","gravatar_id":"","url":"https://api.github.com/users/agl","html_url":"https://github.com/agl","followers_url":"https://api.github.com/users/agl/followers","following_url":"https://api.github.com/users/agl/following{/other_user}","gists_url":"https://api.github.com/users/agl/gists{/gist_id}","starred_url":"https://api.github.com/users/agl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agl/subscriptions","organizations_url":"https://api.github.com/users/agl/orgs","repos_url":"https://api.github.com/users/agl/repos","events_url":"https://api.github.com/users/agl/events{/privacy}","received_events_url":"https://api.github.com/users/agl/received_events","type":"User","site_admin":false},"body":"<!--\r\nThank you for your pull request. Please review below requirements.\r\n\r\nBug fixes and new features should include tests and possibly benchmarks.\r\n\r\nContributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\n##### Checklist\r\n<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->\r\n\r\n- [x] `make -j8 test` (UNIX), or `vcbuild test nosign` (Windows) passes\r\n- [ ] tests and/or benchmarks are included\r\n- [ ] documentation is changed or added\r\n- [x] commit message follows commit guidelines\r\n\r\n##### Affected core subsystem(s)\r\n<!-- Provide affected core subsystem(s) (like doc, cluster, crypto, etc). -->\r\ncrypto\r\n\r\n##### Description of change\r\n<!-- Provide a description of the change below this comment. -->\r\n\r\ncrypto: fix handling of root_cert_store.\r\n\r\nSecureContext::AddRootCerts only parses the root certificates once and keeps the result in root_cert_store, a global X509_STORE. This change addresses the following issues:\r\n\r\n1. SecureContext::AddCACert would add certificates to whatever X509_STORE was being used, even if that happened to be root_cert_store. Thus adding a CA certificate to a SecureContext would also cause it to be included in unrelated SecureContexts.\r\n\r\n2. AddCRL would crash if neither AddRootCerts nor AddCACert had been called first.\r\n\r\n3. Calling AddCACert without calling AddRootCerts first, and with an input that didn't contain any certificates, would leak an X509_STORE.\r\n\r\n4. AddCRL would add the CRL to whatever X509_STORE was being used. Thus, like AddCACert, unrelated SecureContext objects could be affected.\r\n\r\nThe following, non-obvious behaviour remains: calling AddRootCerts doesn't _add_ them, rather it sets the CA certs to be the root set and overrides any previous CA certificates.\r\n\r\nPoints 1–3 are probably unimportant because the SecureContext is typically configured by `createSecureContext` in `lib/_tls_common.js`. This function either calls AddCACert or AddRootCerts and only calls AddCRL after setting up CA certificates. Point four could still apply in the unlikely case that someone configures a CRL without explicitly configuring the CAs.","created_at":"2016-11-01T21:46:53Z","updated_at":"2016-11-04T23:46:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ebf99d3012cb78dc8f84baeb1e54b4ee3493aace","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/node/pulls/9409/commits","review_comments_url":"https://api.github.com/repos/nodejs/node/pulls/9409/comments","review_comment_url":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/node/issues/9409/comments","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/dd784891fed42fad3fa2e61e782551252bf94c86","head":{"label":"agl:certstore","ref":"certstore","sha":"dd784891fed42fad3fa2e61e782551252bf94c86","user":{"login":"agl","id":21203,"avatar_url":"https://avatars.githubusercontent.com/u/21203?v=3","gravatar_id":"","url":"https://api.github.com/users/agl","html_url":"https://github.com/agl","followers_url":"https://api.github.com/users/agl/followers","following_url":"https://api.github.com/users/agl/following{/other_user}","gists_url":"https://api.github.com/users/agl/gists{/gist_id}","starred_url":"https://api.github.com/users/agl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agl/subscriptions","organizations_url":"https://api.github.com/users/agl/orgs","repos_url":"https://api.github.com/users/agl/repos","events_url":"https://api.github.com/users/agl/events{/privacy}","received_events_url":"https://api.github.com/users/agl/received_events","type":"User","site_admin":false},"repo":{"id":50524956,"name":"node","full_name":"agl/node","owner":{"login":"agl","id":21203,"avatar_url":"https://avatars.githubusercontent.com/u/21203?v=3","gravatar_id":"","url":"https://api.github.com/users/agl","html_url":"https://github.com/agl","followers_url":"https://api.github.com/users/agl/followers","following_url":"https://api.github.com/users/agl/following{/other_user}","gists_url":"https://api.github.com/users/agl/gists{/gist_id}","starred_url":"https://api.github.com/users/agl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agl/subscriptions","organizations_url":"https://api.github.com/users/agl/orgs","repos_url":"https://api.github.com/users/agl/repos","events_url":"https://api.github.com/users/agl/events{/privacy}","received_events_url":"https://api.github.com/users/agl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/agl/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":true,"url":"https://api.github.com/repos/agl/node","forks_url":"https://api.github.com/repos/agl/node/forks","keys_url":"https://api.github.com/repos/agl/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/agl/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/agl/node/teams","hooks_url":"https://api.github.com/repos/agl/node/hooks","issue_events_url":"https://api.github.com/repos/agl/node/issues/events{/number}","events_url":"https://api.github.com/repos/agl/node/events","assignees_url":"https://api.github.com/repos/agl/node/assignees{/user}","branches_url":"https://api.github.com/repos/agl/node/branches{/branch}","tags_url":"https://api.github.com/repos/agl/node/tags","blobs_url":"https://api.github.com/repos/agl/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/agl/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/agl/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/agl/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/agl/node/statuses/{sha}","languages_url":"https://api.github.com/repos/agl/node/languages","stargazers_url":"https://api.github.com/repos/agl/node/stargazers","contributors_url":"https://api.github.com/repos/agl/node/contributors","subscribers_url":"https://api.github.com/repos/agl/node/subscribers","subscription_url":"https://api.github.com/repos/agl/node/subscription","commits_url":"https://api.github.com/repos/agl/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/agl/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/agl/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/agl/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/agl/node/contents/{+path}","compare_url":"https://api.github.com/repos/agl/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/agl/node/merges","archive_url":"https://api.github.com/repos/agl/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/agl/node/downloads","issues_url":"https://api.github.com/repos/agl/node/issues{/number}","pulls_url":"https://api.github.com/repos/agl/node/pulls{/number}","milestones_url":"https://api.github.com/repos/agl/node/milestones{/number}","notifications_url":"https://api.github.com/repos/agl/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/agl/node/labels{/name}","releases_url":"https://api.github.com/repos/agl/node/releases{/id}","deployments_url":"https://api.github.com/repos/agl/node/deployments","created_at":"2016-01-27T17:31:22Z","updated_at":"2016-01-27T17:31:31Z","pushed_at":"2016-11-04T21:13:30Z","git_url":"git://github.com/agl/node.git","ssh_url":"git@github.com:agl/node.git","clone_url":"https://github.com/agl/node.git","svn_url":"https://github.com/agl/node","homepage":"https://nodejs.org","size":229716,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nodejs:master","ref":"master","sha":"1a55e9a5672ec654a6cfdd694c20b7067368f5e9","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"node","full_name":"nodejs/node","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":false,"url":"https://api.github.com/repos/nodejs/node","forks_url":"https://api.github.com/repos/nodejs/node/forks","keys_url":"https://api.github.com/repos/nodejs/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node/teams","hooks_url":"https://api.github.com/repos/nodejs/node/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node/events","assignees_url":"https://api.github.com/repos/nodejs/node/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node/tags","blobs_url":"https://api.github.com/repos/nodejs/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node/languages","stargazers_url":"https://api.github.com/repos/nodejs/node/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node/subscription","commits_url":"https://api.github.com/repos/nodejs/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node/merges","archive_url":"https://api.github.com/repos/nodejs/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node/downloads","issues_url":"https://api.github.com/repos/nodejs/node/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node/deployments","created_at":"2014-11-26T19:57:11Z","updated_at":"2016-11-04T20:13:08Z","pushed_at":"2016-11-04T21:53:00Z","git_url":"git://github.com/nodejs/node.git","ssh_url":"git@github.com:nodejs/node.git","clone_url":"https://github.com/nodejs/node.git","svn_url":"https://github.com/nodejs/node","homepage":"https://nodejs.org","size":358669,"stargazers_count":28618,"watchers_count":28618,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4768,"mirror_url":null,"open_issues_count":884,"forks":4768,"open_issues":884,"watchers":28618,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/9409"},"html":{"href":"https://github.com/nodejs/node/pull/9409"},"issue":{"href":"https://api.github.com/repos/nodejs/node/issues/9409"},"comments":{"href":"https://api.github.com/repos/nodejs/node/issues/9409/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/node/pulls/9409/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/node/pulls/9409/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/node/statuses/dd784891fed42fad3fa2e61e782551252bf94c86"}}}}
{"actor":{"display_login":"indutny"}}