diff options
-rw-r--r-- | docs/runtime/nodejs-apis.md | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 21 | ||||
m--------- | src/deps/uws | 0 | ||||
-rw-r--r-- | src/js/node/tls.js | 4 | ||||
-rw-r--r-- | src/js/out/modules/node/tls.js | 6 | ||||
-rw-r--r-- | test/js/node/tls/node-tls-server.test.ts | 14 |
6 files changed, 42 insertions, 5 deletions
diff --git a/docs/runtime/nodejs-apis.md b/docs/runtime/nodejs-apis.md index fdb50f180..e2d35ec6a 100644 --- a/docs/runtime/nodejs-apis.md +++ b/docs/runtime/nodejs-apis.md @@ -200,7 +200,7 @@ This page is updated regularly to reflect compatibility status of the latest ver - {% anchor id="node_tls" %} [`node:tls`](https://nodejs.org/api/tls.html) {% /anchor %} - 🟡 -- Missing `tls.createSecurePair` `tls.rootCertificates` +- Missing `tls.createSecurePair` --- diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 0262050ff..34ef5e38a 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -199,6 +199,7 @@ namespace JSCastingHelpers = JSC::JSCastingHelpers; #include <wtf/RAMSize.h> #include <wtf/text/Base64.h> #include "simdutf.h" +#include "libusockets.h" constexpr size_t DEFAULT_ERROR_STACK_TRACE_LIMIT = 10; @@ -1641,6 +1642,26 @@ JSC: return JSValue::encode(obj); } + if(string == "rootCertificates"_s) { + auto sourceOrigin = callFrame->callerSourceOrigin(vm).url(); + bool isBuiltin = sourceOrigin.protocolIs("builtin"_s); + if (!isBuiltin) { + return JSC::JSValue::encode(JSC::jsUndefined()); + } + struct us_cert_string_t* out; + auto size = us_raw_root_certs(&out); + if (size < 0) { + return JSValue::encode(JSC::jsUndefined()); + } + auto rootCertificates = JSC::JSArray::create(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(JSC::ArrayWithContiguous), size); + for(auto i = 0; i < size; i++) { + auto raw = out[i]; + auto str = WTF::String::fromUTF8(raw.str, raw.len); + rootCertificates->putDirectIndex(globalObject, i, JSC::jsString(vm, str)); + } + return JSValue::encode(rootCertificates); + } + if (string == "masqueradesAsUndefined"_s) { return JSValue::encode(InternalFunction::createFunctionThatMasqueradesAsUndefined(vm, globalObject, 0, String(), functionCallNotImplemented)); } diff --git a/src/deps/uws b/src/deps/uws -Subproject 875948226eede72861a5170212ff6b43c4b7d7f +Subproject f29c6e24c33483c342bbc83c41cc032f42fbf77 diff --git a/src/js/node/tls.js b/src/js/node/tls.js index 0966b584b..e8c2dd998 100644 --- a/src/js/node/tls.js +++ b/src/js/node/tls.js @@ -677,7 +677,7 @@ function convertALPNProtocols(protocols, out) { out.ALPNProtocols = protocols; } } - +var rootCertificates = $lazy("rootCertificates"); var exports = { [Symbol.for("CommonJS")]: 0, CLIENT_RENEG_LIMIT, @@ -698,6 +698,7 @@ var exports = { Server, TLSSocket, checkServerIdentity, + rootCertificates, }; export { @@ -719,5 +720,6 @@ export { checkServerIdentity, Server, TLSSocket, + rootCertificates, exports as default, }; diff --git a/src/js/out/modules/node/tls.js b/src/js/out/modules/node/tls.js index d994a6244..fba1e413a 100644 --- a/src/js/out/modules/node/tls.js +++ b/src/js/out/modules/node/tls.js @@ -414,7 +414,7 @@ var CLIENT_RENEG_LIMIT = 3, CLIENT_RENEG_WINDOW = 600, DEFAULT_ECDH_CURVE = "aut return new TLSSocket(port).connect(port, host2, connectListener); } return new TLSSocket().connect(port, host2, connectListener); -}, connect = createConnection, exports = { +}, connect = createConnection, rootCertificates = globalThis[Symbol.for("Bun.lazy")]("rootCertificates"), exports = { [Symbol.for("CommonJS")]: 0, CLIENT_RENEG_LIMIT, CLIENT_RENEG_WINDOW, @@ -433,9 +433,11 @@ var CLIENT_RENEG_LIMIT = 3, CLIENT_RENEG_WINDOW = 600, DEFAULT_ECDH_CURVE = "aut SecureContext, Server, TLSSocket, - checkServerIdentity + checkServerIdentity, + rootCertificates }; export { + rootCertificates, parseCertString, getCurves, getCiphers, diff --git a/test/js/node/tls/node-tls-server.test.ts b/test/js/node/tls/node-tls-server.test.ts index 051458488..246ec7709 100644 --- a/test/js/node/tls/node-tls-server.test.ts +++ b/test/js/node/tls/node-tls-server.test.ts @@ -1,4 +1,4 @@ -import { connect, createServer, Server, TLSSocket } from "tls"; +import tls, { rootCertificates, connect, createServer, Server, TLSSocket } from "tls"; import type { PeerCertificate } from "tls"; import { realpathSync, readFileSync } from "fs"; import { tmpdir } from "os"; @@ -645,3 +645,15 @@ describe("tls.createServer events", () => { ); }); }); + +it("tls.rootCertificates should exists", () => { + expect(tls.rootCertificates).toBeDefined(); + expect(tls.rootCertificates).toBeInstanceOf(Array); + expect(tls.rootCertificates.length).toBeGreaterThan(0); + expect(typeof tls.rootCertificates[0]).toBe("string"); + + expect(rootCertificates).toBeDefined(); + expect(rootCertificates).toBeInstanceOf(Array); + expect(rootCertificates.length).toBeGreaterThan(0); + expect(typeof rootCertificates[0]).toBe("string"); +}); |