Title: Crypto: X509Certificate.checkPrivateKey() used with a non-matching key makes the next call to createPrivateKey() fail. · Issue #45485 · nodejs/node · GitHub
Open Graph Title: Crypto: X509Certificate.checkPrivateKey() used with a non-matching key makes the next call to createPrivateKey() fail. · Issue #45485 · nodejs/node
X Title: Crypto: X509Certificate.checkPrivateKey() used with a non-matching key makes the next call to createPrivateKey() fail. · Issue #45485 · nodejs/node
Description: Version 18.12.1 Platform Microsoft Windows NT 10.0.19044.0 x64 Subsystem crypto What steps will reproduce the bug? Run the following script using node I have tested with node 16, 17 and 18 with the same behaviour. The script contain a ce...
Open Graph Description: Version 18.12.1 Platform Microsoft Windows NT 10.0.19044.0 x64 Subsystem crypto What steps will reproduce the bug? Run the following script using node I have tested with node 16, 17 and 18 with the...
X Description: Version 18.12.1 Platform Microsoft Windows NT 10.0.19044.0 x64 Subsystem crypto What steps will reproduce the bug? Run the following script using node I have tested with node 16, 17 and 18 with the...
Opengraph URL: https://github.com/nodejs/node/issues/45485
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crypto: X509Certificate.checkPrivateKey() used with a non-matching key makes the next call to createPrivateKey() fail.","articleBody":"### Version\n\n18.12.1\n\n### Platform\n\nMicrosoft Windows NT 10.0.19044.0 x64\n\n### Subsystem\n\ncrypto\n\n### What steps will reproduce the bug?\n\nRun the following script using node\r\nI have tested with node 16, 17 and 18 with the same behaviour.\r\n\r\nThe script contain a certificate and a private key that does NOT match.\r\nI'm using `X509Certificate.checkPrivateKey()` to verify the combination.\r\n\r\nThe validation returns false (as expected).\r\nThen the next line creates a new private key again using `createPrivateKey`\r\n\r\nThis should work as the key itself is OK (and it is the same indata that was used the first time `createPrivateKey` was used)\r\n\r\nInstead an exception is thrown.\r\n\r\n```js\r\nconst { X509Certificate, createPrivateKey } = require('node:crypto');\r\n\r\nconst certificate = `-----BEGIN CERTIFICATE-----\r\nMIICGjCCAb+gAwIBAgIQPBumDEVNCS1HVGGqmK2K5TAKBggqhkjOPQQDAjAfMR0w\r\nGwYDVQQDExRTdGVwIENBIGludGVybWVkaWF0ZTAeFw0yMjExMTYxMjA3MDhaFw0y\r\nMzExMTYxODA4MDhaMBgxFjAUBgNVBAMTDW15LmRvbWFpbi5leHQwWTATBgcqhkjO\r\nPQIBBggqhkjOPQMBBwNCAAQx3ReMlvFMR6CvXth5cgdyvH5K1PVBLL6077wgn3KH\r\noZngq2Qdegx/uOiKv6zU2NWUyGQzq5aBZQAhgKYT3eaio4HjMIHgMA4GA1UdDwEB\r\n/wQEAwIHgDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwHQYDVR0OBBYE\r\nFLg8zUDxW06swsdeZ/WNpK7bWMysMB8GA1UdIwQYMBaAFE0eDYW1uSFCr8tbOgbr\r\nUpCwapXYMBgGA1UdEQQRMA+CDW15LmRvbWFpbi5leHQwVQYMKwYBBAGCpGTGKEAB\r\nBEUwQwIBAQQRc3VwcG9ydEBwYW5lZGEuc2UEKzRZOUpvR1RfWWNiVlhfR09UX2Fk\r\nNmk1cGZ6S2hpVDdVckE4ZU05TFZuVXMwCgYIKoZIzj0EAwIDSQAwRgIhAO3U+GsY\r\nfKbRZKIWypOaWcOjREg9xD3KnsTwS5TGfMprAiEArEZowGfEzr2v6VjWJTh1+UUi\r\nM54YrQa7Vdvp0DblvCo=\r\n-----END CERTIFICATE-----`;\r\n\r\nconst key = `-----BEGIN EC PRIVATE KEY-----\r\nMHcCAQEEIKeq1Bx1/6rRuHbNze/UQV1JchO5QasI17Abf+Tb8QqeoAoGCCqGSM49\r\nAwEHoUQDQgAEsCYBL0B7tjzdx0unix2qKy+Mv3/RCmelFY91pR3EGdQGDmBYpAGN\r\np9WxWgJIIkdLlEVju/kD1Q55+dYWOlR/Wg==\r\n-----END EC PRIVATE KEY-----`;\r\n\r\nconst cryptoCrt = new X509Certificate(certificate);\r\nconst cryptoKey = createPrivateKey(key);\r\n\r\nconst isMatching = cryptoCrt.checkPrivateKey(cryptoKey);\r\nconsole.log(isMatching);\r\n\r\ncreatePrivateKey(key);\r\nconsole.log('done');\r\n\r\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior?\n\nConsole output should be:\r\n\r\n```\r\nfalse\r\ndone\r\n```\r\n\n\n### What do you see instead?\n\nconsole output is:\r\n\r\n```\r\nfalse\r\nnode:internal/crypto/keys:620\r\n handle.init(kKeyTypePrivate, data, format, type, passphrase);\r\n ^\r\n\r\nError: error:05800074:x509 certificate routines::key values mismatch\r\n at createPrivateKey (node:internal/crypto/keys:620:12)\r\n at Object.\u003canonymous> (C:\\work\\gitwork\\monorepo\\applications\\orchestration_service\\src\\orchestrationHandlers\\cryptotest.js:30:1)\r\n at Module._compile (node:internal/modules/cjs/loader:1159:14)\r\n at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)\r\n at Module.load (node:internal/modules/cjs/loader:1037:32)\r\n at Module._load (node:internal/modules/cjs/loader:878:12)\r\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\r\n at node:internal/main/run_main_module:23:47 {\r\n library: 'x509 certificate routines',\r\n reason: 'key values mismatch',\r\n code: 'ERR_OSSL_X509_KEY_VALUES_MISMATCH'\r\n}\r\n\r\nNode.js v18.12.1\r\n```\n\n### Additional information\n\nIt looks to me, that the exception thrown on the second createPrivateKey is the actual error that occured in the `checkPrivateKey` function, causing it to return false.\r\nIn fact receiving that info instead as a plain `false` would have been nice.\r\n\r\nBut now it looks like the error is \"queued\" and then thrown when using `createPrivateKey` again.\r\n","author":{"url":"https://github.com/tkarls","@type":"Person","name":"tkarls"},"datePublished":"2022-11-16T17:24:23Z","url":"https://github.com/nodejs/node/issues/45485"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7c412a3d-a0f3-f559-34ec-579969b201a4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9078:2DB496:1CF6AE:24F96B:6B033DAA |
| html-safe-nonce | dc1a28db17e27fffe9ddfae92f9ba22609245c220a4ab4591643754bb43498a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDc4OjJEQjQ5NjoxQ0Y2QUU6MjRGOTZCOjZCMDMzREFBIiwidmlzaXRvcl9pZCI6IjE1ODMyODYxMjAwNDM3MjQyMDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | cf9ad1f3870aa3bfe29f8ee979361a42508bb954c4241f6755a4447729383777 |
| hovercard-subject-tag | issue:1451990512 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/45485/issue_layout |
| twitter:image | https://opengraph.githubassets.com/634d9d1e1437bb42a03971360387b9231810fa04ef17db10d887887e5f472ec3/nodejs/node/issues/45485 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/634d9d1e1437bb42a03971360387b9231810fa04ef17db10d887887e5f472ec3/nodejs/node/issues/45485 |
| og:image:alt | Version 18.12.1 Platform Microsoft Windows NT 10.0.19044.0 x64 Subsystem crypto What steps will reproduce the bug? Run the following script using node I have tested with node 16, 17 and 18 with the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tkarls |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width