Compare commits

...

16 Commits

Author SHA1 Message Date
Alistair Smith
46ee588590 rm broken.js 2025-05-21 11:59:08 -07:00
alii
ee8dece4a0 bun run clang-format 2025-05-21 18:39:58 +00:00
Alistair Smith
7395073187 Merge branch 'main' of github.com:oven-sh/bun into ali/fix-tls-error-servername 2025-05-21 11:37:20 -07:00
alii
4c27e42ef9 bun run prettier 2025-05-21 00:26:55 +00:00
Alistair Smith
5c9f772dc3 cannot unref 2025-05-20 17:22:45 -07:00
Alistair Smith
98d3e6dec1 Merge branch 'main' of github.com:oven-sh/bun into ali/fix-tls-error-servername 2025-05-20 17:22:06 -07:00
Alistair Smith
d44b50d11e rm 2025-05-20 15:24:04 -07:00
Alistair Smith
76e0031a4d Merge branch 'ali/fix-tls-error-servername' of github.com:oven-sh/bun into ali/fix-tls-error-servername 2025-05-20 15:23:26 -07:00
Alistair Smith
7066043c79 unref?? 2025-05-20 15:23:22 -07:00
Alistair Smith
70bc20b3d2 fix bindgen 2025-05-20 15:14:00 -07:00
alii
5db1b3be61 bun run prettier 2025-05-20 20:51:26 +00:00
Alistair Smith
b498178ccb Merge branch 'main' of github.com:oven-sh/bun into ali/fix-tls-error-servername 2025-05-20 13:48:44 -07:00
Alistair Smith
0c97367890 changes 2025-05-20 12:56:24 -07:00
Alistair Smith
78a31efb1d no isServer prop on TLSSocket - hide as internal 2025-05-19 15:22:29 -07:00
Alistair Smith
75611169f4 pass test 2025-05-19 14:46:34 -07:00
Alistair Smith
11e6ca8c08 add test file 2025-05-19 14:45:40 -07:00
4 changed files with 72 additions and 16 deletions

View File

@@ -93,7 +93,7 @@ void CryptoAlgorithmX25519::deriveBits(const CryptoAlgorithmParameters& paramete
// https://github.com/WICG/webcrypto-secure-curves/pull/29
if (length && !(*length)) {
// Avoid executing the key-derivation, since we are going to return an empty string.
callback({ });
callback({});
return;
}
@@ -109,7 +109,7 @@ void CryptoAlgorithmX25519::deriveBits(const CryptoAlgorithmParameters& paramete
#if !HAVE(X25519_ZERO_CHECKS)
// https://datatracker.ietf.org/doc/html/rfc7748#section-6.1
constexpr auto expectedOutputSize = 32;
constexpr std::array<uint8_t, expectedOutputSize> zeros { };
constexpr std::array<uint8_t, expectedOutputSize> zeros {};
if (derivedKey->size() != expectedOutputSize || !constantTimeMemcmp(derivedKey->span(), zeros)) {
exceptionCallback(ExceptionCode::OperationError, ""_s);
return;
@@ -246,5 +246,4 @@ void CryptoAlgorithmX25519::exportKey(CryptoKeyFormat format, Ref<CryptoKey>&& k
} // namespace WebCore
#endif // ENABLE(WEB_CRYPTO)

View File

@@ -20,7 +20,6 @@
#include "config.h"
#if ENABLE(WEB_CRYPTO)
#include "JSX25519Params.h"
@@ -29,9 +28,6 @@
#include "JSDOMConvertStrings.h"
#include <JavaScriptCore/JSCInlines.h>
namespace WebCore {
using namespace JSC;
@@ -43,7 +39,7 @@ template<> CryptoAlgorithmX25519Params convertDictionary<CryptoAlgorithmX25519Pa
auto* object = isNullOrUndefined ? nullptr : value.getObject();
if (!isNullOrUndefined && !object) [[unlikely]] {
throwTypeError(&lexicalGlobalObject, throwScope);
return { };
return {};
}
CryptoAlgorithmX25519Params result;
JSValue nameValue;
@@ -51,11 +47,11 @@ template<> CryptoAlgorithmX25519Params convertDictionary<CryptoAlgorithmX25519Pa
nameValue = jsUndefined();
else {
nameValue = object->get(&lexicalGlobalObject, vm.propertyNames->name);
RETURN_IF_EXCEPTION(throwScope, { });
RETURN_IF_EXCEPTION(throwScope, {});
}
if (nameValue.isUndefined()) {
throwRequiredMemberTypeError(lexicalGlobalObject, throwScope, "name"_s, "X25519Params"_s, "DOMString"_s);
return { };
return {};
}
auto nameConversionResult = convert<IDLDOMString>(lexicalGlobalObject, nameValue);
RETURN_IF_EXCEPTION(throwScope, {});
@@ -65,19 +61,18 @@ template<> CryptoAlgorithmX25519Params convertDictionary<CryptoAlgorithmX25519Pa
publicKeyValue = jsUndefined();
else {
publicKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "publicKey"_s));
RETURN_IF_EXCEPTION(throwScope, { });
RETURN_IF_EXCEPTION(throwScope, {});
}
if (publicKeyValue.isUndefined()) {
throwRequiredMemberTypeError(lexicalGlobalObject, throwScope, "publicKey"_s, "X25519Params"_s, "CryptoKey"_s);
return { };
return {};
}
auto publicKeyConversionResult = convert<IDLInterface<CryptoKey>>(lexicalGlobalObject, publicKeyValue);
RETURN_IF_EXCEPTION(throwScope, { });
RETURN_IF_EXCEPTION(throwScope, {});
result.publicKey = publicKeyConversionResult;
return result;
}
} // namespace WebCore
#endif // ENABLE(WEB_CRYPTO)

View File

@@ -8,7 +8,10 @@ const { throwOnInvalidTLSArray } = require("internal/tls");
const { Server: NetServer, Socket: NetSocket } = net;
const { rootCertificates, canonicalizeIP } = $cpp("NodeTLS.cpp", "createNodeTLSBinding");
const { rootCertificates, canonicalizeIP } = $cpp("NodeTLS.cpp", "createNodeTLSBinding") as {
rootCertificates: readonly string[];
canonicalizeIP: (ip: string) => string;
};
const SymbolReplace = Symbol.replace;
const RegExpPrototypeSymbolReplace = RegExp.prototype[SymbolReplace];
@@ -283,6 +286,7 @@ const ksecureContext = Symbol("ksecureContext");
const kcheckServerIdentity = Symbol("kcheckServerIdentity");
const ksession = Symbol("ksession");
const krenegotiationDisabled = Symbol("renegotiationDisabled");
const kIsServer = Symbol("kIsServer");
const buntls = Symbol.for("::buntls::");
@@ -322,7 +326,10 @@ function TLSSocket(socket?, options?) {
// keep compatibility with http2-wrapper or other places that try to grab JSStreamSocket in node.js, with here is just the TLSSocket
this._handle._parentWrap = this;
}
this[kIsServer] = options.isServer;
}
this[ksecureContext] = options.secureContext || createSecureContext(options);
this.authorized = false;
this.secureConnecting = true;
@@ -433,9 +440,14 @@ TLSSocket.prototype.enableTrace = function enableTrace() {
};
TLSSocket.prototype.setServername = function setServername(name) {
if (this.isServer) {
if (typeof name !== "string") {
throw $ERR_INVALID_ARG_TYPE("name", "string", name);
}
if (this[kIsServer]) {
throw $ERR_TLS_SNI_FROM_SERVER();
}
// if the socket is detached we can't set the servername but we set this property so when open will auto set to it
this.servername = name;
this._handle?.setServername?.(name);

View File

@@ -0,0 +1,50 @@
'use strict';
// This tests the errors thrown from TLSSocket.prototype.setServername
const common = require('../common');
const fixtures = require('../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { connect, TLSSocket } = require('tls');
const { duplexPair } = require('stream');
const [ clientSide, serverSide ] = duplexPair();
const key = fixtures.readKey('agent1-key.pem');
const cert = fixtures.readKey('agent1-cert.pem');
const ca = fixtures.readKey('ca1-cert.pem');
const client = connect({
socket: clientSide,
ca,
host: 'agent1' // Hostname from certificate
});
[undefined, null, 1, true, {}].forEach((value) => {
assert.throws(() => {
client.setServername(value);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "name" argument must be of type string.' +
common.invalidArgTypeHelper(value)
});
});
const server = new TLSSocket(serverSide, {
isServer: true,
key,
cert,
ca
});
assert.throws(() => {
server.setServername('localhost');
}, {
code: 'ERR_TLS_SNI_FROM_SERVER',
message: 'Cannot issue SNI from a TLS server-side socket'
});
process.exit(0); // TODO: Bun hangs - something not being unref'd?