-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
CLI, Desktop: shim-init-node: add support for PQC TLS #15055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import BaseItem from './models/BaseItem'; | |
| import { Size } from '@joplin/utils/types'; | ||
| import { cpus } from 'os'; | ||
| import { pathToFileURL } from 'url'; | ||
| import * as tls from 'tls'; | ||
| import type PdfJs from './utils/types/pdfJs'; | ||
| const { _ } = require('./locale'); | ||
| const http = require('http'); | ||
|
|
@@ -529,7 +530,7 @@ function shimInit(options: ShimInitOptions = null) { | |
| throw new Error(`Not a valid URL: ${url}`); | ||
| } | ||
| const resolvedProxyUrl = resolveProxyUrl(proxySettings.proxyUrl); | ||
| options.agent = (resolvedProxyUrl && proxySettings.proxyEnabled) ? shim.proxyAgent(url, resolvedProxyUrl) : null; | ||
| options.agent = (resolvedProxyUrl && proxySettings.proxyEnabled) ? shim.proxyAgent(url, resolvedProxyUrl) : shim.httpAgent(url); | ||
| return shim.fetchWithRetry(() => { | ||
| return nodeFetch(url, options); | ||
| }, options); | ||
|
|
@@ -584,7 +585,7 @@ function shimInit(options: ShimInitOptions = null) { | |
| }; | ||
|
|
||
| const resolvedProxyUrl = resolveProxyUrl(proxySettings.proxyUrl); | ||
| requestOptions.agent = (resolvedProxyUrl && proxySettings.proxyEnabled) ? shim.proxyAgent(url.href, resolvedProxyUrl) : null; | ||
| requestOptions.agent = (resolvedProxyUrl && proxySettings.proxyEnabled) ? shim.proxyAgent(url.href, resolvedProxyUrl) : shim.httpAgent(url.href); | ||
|
Comment on lines
587
to
+588
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n packages/lib/shim-init-node.ts | sed -n '580,595p'Repository: laurent22/joplin Length of output: 907 🏁 Script executed: rg -A 10 "const resolvedProxyUrl = resolveProxyUrl" packages/lib/shim-init-node.tsRepository: laurent22/joplin Length of output: 1324 🏁 Script executed: rg "fetchBlob" packages/lib/shim-init-node.ts -B 5 -A 15Repository: laurent22/joplin Length of output: 1086 🏁 Script executed: rg "requestOptions" packages/lib/shim-init-node.ts -A 5 -B 2Repository: laurent22/joplin Length of output: 1675 🏁 Script executed: rg "http\.request\|https\.request" packages/lib/shim-init-node.ts -A 3 -B 2Repository: laurent22/joplin Length of output: 42 🌐 Web query:
💡 Result: In
Example: const { http, https } = require('follow-redirects');
https.request({
url: 'http://example.com',
agents: {
http: new (require('http')).Agent({ keepAlive: true }),
https: new (require('https')).Agent({ keepAlive: true }),
},
});Sources: [1] 🏁 Script executed: rg "shim\.httpAgent\s*=|shim\.proxyAgent\s*=" packages/lib/shim-init-node.ts -A 5 -B 1Repository: laurent22/joplin Length of output: 421 🏁 Script executed: rg "httpAgent|proxyAgent" packages/lib/shim-init-node.ts | head -20Repository: laurent22/joplin Length of output: 805 🏁 Script executed: rg "shim\.httpAgent\s*=" packages/lib/shim-init-node.ts -A 15Repository: laurent22/joplin Length of output: 443 🏁 Script executed: rg "shim\.proxyAgent\s*=" packages/lib/shim-init-node.ts -A 25Repository: laurent22/joplin Length of output: 1003 Use On line 587, a single agent is assigned to requestOptions.agents = { http: httpAgent, https: httpsAgent }This ensures each protocol gets its appropriate agent instance during the redirect chain. 🤖 Prompt for AI Agents |
||
|
|
||
| const doFetchOperation = async () => { | ||
| return new Promise((resolve, reject) => { | ||
|
|
@@ -701,12 +702,24 @@ function shimInit(options: ShimInitOptions = null) { | |
|
|
||
| shim.httpAgent_ = null; | ||
|
|
||
| // X25519MLKEM768 is a post-quantum cryptography key exchange, details: | ||
| // https://developers.cloudflare.com/ssl/post-quantum-cryptography/ | ||
| // Not supported on by all SSL stacks and versions, detect support at runtime. | ||
| let tlsEcdhCurve: string; | ||
| try { | ||
| tls.createSecureContext({ ecdhCurve: 'X25519MLKEM768:X25519:P-256:P-384' }); | ||
| tlsEcdhCurve = 'X25519MLKEM768:X25519:P-256:P-384'; | ||
| } catch { | ||
| tlsEcdhCurve = 'auto'; | ||
| } | ||
|
|
||
| shim.httpAgent = url => { | ||
| if (!shim.httpAgent_) { | ||
| const AgentSettings = { | ||
| keepAlive: true, | ||
| maxSockets: 1, | ||
| keepAliveMsecs: 5000, | ||
| ecdhCurve: tlsEcdhCurve, | ||
| }; | ||
| shim.httpAgent_ = { | ||
| http: new http.Agent(AgentSettings), | ||
|
|
@@ -723,6 +736,7 @@ function shimInit(options: ShimInitOptions = null) { | |
| keepAliveMsecs: 5000, | ||
| proxy: proxyUrl, | ||
| timeout: proxySettings.proxyTimeout * 1000, | ||
| ecdhCurve: tlsEcdhCurve, | ||
| }; | ||
|
|
||
| // Based on https://github.com/delvedor/hpagent#usage | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,6 +214,7 @@ mkdir | |
| mkdirp | ||
| mknote | ||
| mktodo | ||
| MLKEM | ||
| MMYY | ||
| mmproj | ||
| mnop | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: laurent22/joplin
Length of output: 10652
🏁 Script executed:
Repository: laurent22/joplin
Length of output: 3126
🏁 Script executed:
Repository: laurent22/joplin
Length of output: 195
🌐 Web query:
node-fetch agent option callback function support documentation💡 Result:
node-fetchdoes document support for anagent“callback” (i.e., a function) infetch(url, options):node-fetchREADME, theagentoption is documented as either anhttp(s).Agentinstance or a function that returns an Agent. The README further explains that this function is called with the currentURL(useful for redirects that switch betweenhttp:andhttps:). [1]node-fetch(DefinitelyTyped, as rendered by jsDocs) define it as:agent?: RequestOptions['agent'] | ((parsedUrl: URL) => RequestOptions['agent']);[2]Docs: see the
node-fetchREADME → API → Options → Custom Agent. [1]Sources
[1] node-fetch README (GitHub) (github.com)
[2]
@types/node-fetchRequestInit typings (jsDocs) (jsdocs.io)Citations:
Use an agent callback to support cross-protocol redirects.
node-fetchsupports passing a function for theagentoption, which is called with each redirect URL to allow protocol-specific agent selection. The current fixed agent on Line 532 means anhttp:URL that redirects tohttps:keeps the agent selected for the original scheme, causing the request to potentially fail.Suggested change
📝 Committable suggestion
🤖 Prompt for AI Agents