René's URL Explorer Experiment


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

direct link

Domain: github.com

IPv4 address: 140.82.114.4


Hey, it has json ld scripts:
{"@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-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:7c412a3d-a0f3-f559-34ec-579969b201a4
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9078:2DB496:1CF6AE:24F96B:6B033DAA
html-safe-noncedc1a28db17e27fffe9ddfae92f9ba22609245c220a4ab4591643754bb43498a9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDc4OjJEQjQ5NjoxQ0Y2QUU6MjRGOTZCOjZCMDMzREFBIiwidmlzaXRvcl9pZCI6IjE1ODMyODYxMjAwNDM3MjQyMDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaccf9ad1f3870aa3bfe29f8ee979361a42508bb954c4241f6755a4447729383777
hovercard-subject-tagissue:1451990512
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/45485/issue_layout
twitter:imagehttps://opengraph.githubassets.com/634d9d1e1437bb42a03971360387b9231810fa04ef17db10d887887e5f472ec3/nodejs/node/issues/45485
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/634d9d1e1437bb42a03971360387b9231810fa04ef17db10d887887e5f472ec3/nodejs/node/issues/45485
og:image:altVersion 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametkarls
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/45485#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F45485
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F45485
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/45485
Reloadhttps://github.com/nodejs/node/issues/45485
Reloadhttps://github.com/nodejs/node/issues/45485
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues637 (637)https://github.com/nodejs/node/issues
Pull requests667 (667)https://github.com/nodejs/node/pulls
Actionshttps://github.com/nodejs/node/actions
Projectshttps://github.com/nodejs/node/projects
Security and qualityhttps://github.com/nodejs/node/security
Insightshttps://github.com/nodejs/node/insights
https://github.com/nodejs/node
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/45485
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/45485
#45495https://github.com/nodejs/node/pull/45495
Crypto: X509Certificate.checkPrivateKey() used with a non-matching key makes the next call to createPrivateKey() fail.https://github.com/nodejs/node/issues/45485#top
#45495https://github.com/nodejs/node/pull/45495
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
cryptoIssues and PRs related to the crypto subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22crypto%22
https://github.com/tkarls
tkarlshttps://github.com/tkarls
on Nov 16, 2022https://github.com/nodejs/node/issues/45485#issue-1451990512
https://github.com/tkarls
tkarlshttps://github.com/tkarls
on Nov 16, 2022https://github.com/nodejs/node/issues/45485#issuecomment-1317409346
#1https://github.com/nodejs/node/pull/1
https://github.com/mscdex
mscdexhttps://github.com/mscdex
on Nov 16, 2022https://github.com/nodejs/node/issues/45485#issuecomment-1317416774
#45377https://github.com/nodejs/node/pull/45377
VoltrexKeyvahttps://github.com/VoltrexKeyva
cryptoIssues and PRs related to the crypto subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22crypto%22
on Nov 16, 2022https://github.com/nodejs/node/issues/45485#event-7827068766
https://github.com/tkarls
tkarlshttps://github.com/tkarls
on Nov 16, 2022https://github.com/nodejs/node/issues/45485#issuecomment-1317670661
#45377https://github.com/nodejs/node/pull/45377
https://github.com/panva
panvahttps://github.com/panva
on Nov 17, 2022https://github.com/nodejs/node/issues/45485#issuecomment-1318749041
#45495https://github.com/nodejs/node/pull/45495
https://github.com/tkarls
tkarlshttps://github.com/tkarls
on Nov 17, 2022https://github.com/nodejs/node/issues/45485#issuecomment-1318768158
#45495https://github.com/nodejs/node/pull/45495
panvahttps://github.com/panva
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
on Nov 17, 2022https://github.com/nodejs/node/issues/45485#event-7834884656
panvahttps://github.com/panva
on Nov 17, 2022https://github.com/nodejs/node/issues/45485#event-7835921601
crypto: clear OpenSSL error queue after calling X509_check_private_key()https://github.com/panva/node/commit/5e3bd7f68101e4c63659f962ee935dad0ce7c563
5e3bd7fhttps://github.com/panva/node/commit/5e3bd7f68101e4c63659f962ee935dad0ce7c563
nodejs-github-bothttps://github.com/nodejs-github-bot
completedhttps://github.com/nodejs/node/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#45495https://github.com/nodejs/node/pull/45495
on Nov 19, 2022https://github.com/nodejs/node/issues/45485#event-7849771406
nodejs-github-bothttps://github.com/nodejs-github-bot
on Nov 19, 2022https://github.com/nodejs/node/issues/45485#event-7849771451
crypto: clear OpenSSL error queue after calling X509_check_private_key()https://github.com/nodejs/node/commit/b61603f120e5332d15e7d8726bed92f5e0706809
b61603fhttps://github.com/nodejs/node/commit/b61603f120e5332d15e7d8726bed92f5e0706809
ruyadornohttps://github.com/ruyadorno
on Nov 21, 2022https://github.com/nodejs/node/issues/45485#event-7861898438
crypto: clear OpenSSL error queue after calling X509_check_private_key()https://github.com/nodejs/node/commit/bd3accc7b26f0c7c2189888bd496c1b2e07ef45f
bd3accchttps://github.com/nodejs/node/commit/bd3accc7b26f0c7c2189888bd496c1b2e07ef45f
oralubenhttps://github.com/oraluben
on Mar 14, 2023https://github.com/nodejs/node/issues/45485#event-8739823085
crypto: clear OpenSSL error queue after calling X509_check_private_key()https://github.com/oraluben/node/commit/e67b5499b3532abbfd9464af1f1548aaa07dd25d
e67b549https://github.com/oraluben/node/commit/e67b5499b3532abbfd9464af1f1548aaa07dd25d
crypto: clear OpenSSL error queue after calling X509_check_private_key()https://github.com/oraluben/node/commit/5fbc980d4882d26832989ff10cc2c16b70a82beb
5fbc980https://github.com/oraluben/node/commit/5fbc980d4882d26832989ff10cc2c16b70a82beb
m0th3rch1phttps://github.com/m0th3rch1p
on Jul 20, 2025https://github.com/nodejs/node/issues/45485#event-18716237144
crypto: clear OpenSSL error queue after calling X509_check_private_key()https://github.com/m0th3rch1p/node/commit/160adb7ffc8048d12fe0599b8fb12e4236b9d21a
160adb7https://github.com/m0th3rch1p/node/commit/160adb7ffc8048d12fe0599b8fb12e4236b9d21a
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/45485
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/45485
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
cryptoIssues and PRs related to the crypto subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22crypto%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.