diff options
author | 2023-01-10 19:28:51 -0800 | |
---|---|---|
committer | 2023-01-10 19:29:27 -0800 | |
commit | 5e60a9363f68a35e546658a1cbdb5d9a3a8752be (patch) | |
tree | b8f41b5d5e80baa3b3ddd845a917438c61cc73fc | |
parent | cd20a84f187ec228a042aa73bcf154f1ab0b93e7 (diff) | |
download | bun-5e60a9363f68a35e546658a1cbdb5d9a3a8752be.tar.gz bun-5e60a9363f68a35e546658a1cbdb5d9a3a8752be.tar.zst bun-5e60a9363f68a35e546658a1cbdb5d9a3a8752be.zip |
[node:tls] Stub out just enough to make it load
-rw-r--r-- | src/bun.js/module_loader.zig | 13 | ||||
-rw-r--r-- | src/bun.js/node-tls.exports.js | 141 |
2 files changed, 154 insertions, 0 deletions
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index c4dea6fc4..e4ee611cf 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -1664,6 +1664,15 @@ pub const ModuleLoader = struct { .hash = 0, }; }, + .@"node:tls" => { + return ResolvedSource{ + .allocator = null, + .source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "node-tls.exports.js")), + .specifier = ZigString.init("node:tls"), + .source_url = ZigString.init("node:tls"), + .hash = 0, + }; + }, .@"node:dns/promises" => { return ResolvedSource{ .allocator = null, @@ -2026,6 +2035,7 @@ pub const HardcodedModule = enum { @"node:https", @"node:module", @"node:net", + @"node:tls", @"node:os", @"node:path", @"node:path/posix", @@ -2074,6 +2084,7 @@ pub const HardcodedModule = enum { .{ "node:dns", HardcodedModule.@"node:dns" }, .{ "node:net", HardcodedModule.@"node:net" }, .{ "node:os", HardcodedModule.@"node:os" }, + .{ "node:tls", HardcodedModule.@"node:tls" }, .{ "node:path", HardcodedModule.@"node:path" }, .{ "node:path/posix", HardcodedModule.@"node:path/posix" }, .{ "node:path/win32", HardcodedModule.@"node:path/win32" }, @@ -2142,6 +2153,8 @@ pub const HardcodedModule = enum { .{ "node:readline", "node:readline" }, .{ "node:readline/promises", "node:readline/promises" }, .{ "node:stream", "node:stream" }, + .{ "node:tls", "node:tls" }, + .{ "tls", "node:tls" }, .{ "node:stream/consumers", "node:stream/consumers" }, .{ "node:stream/web", "node:stream/web" }, .{ "node:string_decoder", "node:string_decoder" }, diff --git a/src/bun.js/node-tls.exports.js b/src/bun.js/node-tls.exports.js new file mode 100644 index 000000000..298fd490a --- /dev/null +++ b/src/bun.js/node-tls.exports.js @@ -0,0 +1,141 @@ +function parseCertString() { + throw Error("Not implemented"); +} + +var InternalSecureContext = class SecureContext {}; +function SecureContext() { + return new InternalSecureContext(); +} + +function createSecureContext(options) { + return new SecureContext(); +} + +const { [Symbol.for("::bunternal::")]: InternalTCPSocket } = + import.meta.require("net"); + +const buntls = Symbol.for("::buntls::"); + +var SocketClass; +const TLSSocket = (function (InternalTLSSocket) { + SocketClass = InternalTLSSocket; + Object.defineProperty(SocketClass.prototype, Symbol.toStringTag, { + value: "TLSSocket", + enumerable: false, + }); + + return Object.defineProperty( + function Socket(options) { + return new InternalTLSSocket(options); + }, + Symbol.hasInstance, + { + value(instance) { + return instance instanceof InternalTLSSocket; + }, + }, + ); +})( + class TLSSocket extends InternalTCPSocket { + constructor(options) { + super(options); + } + + _secureEstablished = false; + _securePending = true; + _newSessionPending; + _controlReleased; + secureConnecting = false; + _SNICallback; + servername; + alpnProtocol; + authorized = true; + authorizationError; + + encrypted = true; + + exportKeyingMaterial() { + throw Error("Not implented in Bun yet"); + } + setMaxSendFragment() { + throw Error("Not implented in Bun yet"); + } + setServername() { + throw Error("Not implented in Bun yet"); + } + setSession() { + throw Error("Not implented in Bun yet"); + } + getPeerCertificate() { + throw Error("Not implented in Bun yet"); + } + getCertificate() { + throw Error("Not implented in Bun yet"); + } + getPeerX509Certificate() { + throw Error("Not implented in Bun yet"); + } + getX509Certificate() { + throw Error("Not implented in Bun yet"); + } + + emit(event, args) { + super.emit(event, args); + + if (event === "connect" && !this._readableState?.destroyed) { + this.authorized = true; + this.secureConnecting = false; + this._secureEstablished = true; + this._securePending = false; + + super.emit("secureConnect", args); + } + } + + [buntls](port, host) { + var { servername } = this; + if (servername) { + return { + serverName: typeof servername === "string" ? servername : host, + }; + } + + return true; + } + }, +); +export const CLIENT_RENEG_LIMIT = 3, + CLIENT_RENEG_WINDOW = 600, + DEFAULT_ECDH_CURVE = "auto", + // https://github.com/Jarred-Sumner/uSockets/blob/fafc241e8664243fc0c51d69684d5d02b9805134/src/crypto/openssl.c#L519-L523 + DEFAULT_CIPHERS = + "DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256", + DEFAULT_MIN_VERSION = "TLSv1.2", + DEFAULT_MAX_VERSION = "TLSv1.3"; + +var exports = { + createSecureContext, + parseCertString, + + getCiphers() { + return DEFAULT_CIPHERS.split(":"); + }, + + getCurves() { + return; + }, + + convertALPNProtocols(protocols, out) {}, + TLSSocket, + SecureContext, + CLIENT_RENEG_LIMIT, + CLIENT_RENEG_WINDOW, + DEFAULT_ECDH_CURVE, + DEFAULT_CIPHERS, + DEFAULT_MIN_VERSION, + DEFAULT_MAX_VERSION, + [Symbol.for("CommonJS")]: 0, +}; + +export default exports; +export { createSecureContext, parseCertString, TLSSocket, SecureContext }; |