Skip to content

Commit 49b0c99

Browse files
Jake ChampionJakeChampion
authored andcommitted
feat: add event.client.tlsCipherOpensslName
1 parent d80baa8 commit 49b0c99

File tree

9 files changed

+49
-7
lines changed

9 files changed

+49
-7
lines changed

runtime/js-compute-runtime/builtins/client-info.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ bool ClientInfo::geo_get(JSContext *cx, unsigned argc, JS::Value *vp) {
110110
return JS_ParseJSON(cx, geo_info_str, args.rval());
111111
}
112112

113+
bool ClientInfo::tls_cipher_openssl_name_get(JSContext *cx, unsigned argc, JS::Value *vp) {
114+
METHOD_HEADER(0);
115+
116+
auto res = HttpReq::http_req_downstream_tls_cipher_openssl_name();
117+
if (auto *err = res.to_err()) {
118+
HANDLE_ERROR(cx, *err);
119+
return false;
120+
}
121+
122+
HostString cipher = std::move(res.unwrap());
123+
JS::RootedString result(cx, JS_NewStringCopyN(cx, cipher.ptr.get(), cipher.len));
124+
125+
args.rval().setString(result);
126+
return true;
127+
}
113128
const JSFunctionSpec ClientInfo::static_methods[] = {
114129
JS_FS_END,
115130
};
@@ -125,6 +140,7 @@ const JSFunctionSpec ClientInfo::methods[] = {
125140
const JSPropertySpec ClientInfo::properties[] = {
126141
JS_PSG("address", address_get, JSPROP_ENUMERATE),
127142
JS_PSG("geo", geo_get, JSPROP_ENUMERATE),
143+
JS_PSG("tlsCipherOpensslName", tls_cipher_openssl_name_get, JSPROP_ENUMERATE),
128144
JS_PS_END,
129145
};
130146

runtime/js-compute-runtime/builtins/client-info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace builtins {
88
class ClientInfo final : public BuiltinNoConstructor<ClientInfo> {
99
static bool address_get(JSContext *cx, unsigned argc, JS::Value *vp);
1010
static bool geo_get(JSContext *cx, unsigned argc, JS::Value *vp);
11+
static bool tls_cipher_openssl_name_get(JSContext *cx, unsigned argc, JS::Value *vp);
1112

1213
public:
1314
static constexpr const char *class_name = "FetchEvent";

runtime/js-compute-runtime/fastly-world/fastly_world.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ void __wasm_import_fastly_http_req_downstream_tls_protocol(int32_t);
284284
__attribute__((__import_module__("fastly"), __import_name__("http-req-downstream-tls-client-hello")))
285285
void __wasm_import_fastly_http_req_downstream_tls_client_hello(int32_t);
286286

287-
__attribute__((__import_module__("fastly"), __import_name__("http-req-downstream-tls-client-certificate")))
288-
void __wasm_import_fastly_http_req_downstream_tls_client_certificate(int32_t);
287+
__attribute__((__import_module__("fastly"), __import_name__("http-req-downstream-tls-raw-client-certificate")))
288+
void __wasm_import_fastly_http_req_downstream_tls_raw_client_certificate(int32_t);
289289

290290
__attribute__((__import_module__("fastly"), __import_name__("http-req-downstream-tls-client-cert-verify-result")))
291291
void __wasm_import_fastly_http_req_downstream_tls_client_cert_verify_result(int32_t);
@@ -937,11 +937,11 @@ bool fastly_http_req_downstream_tls_client_hello(fastly_world_list_u8_t *ret, fa
937937
}
938938
}
939939

940-
bool fastly_http_req_downstream_tls_client_certificate(fastly_world_list_u8_t *ret, fastly_error_t *err) {
940+
bool fastly_http_req_downstream_tls_raw_client_certificate(fastly_world_list_u8_t *ret, fastly_error_t *err) {
941941
__attribute__((__aligned__(4)))
942942
uint8_t ret_area[12];
943943
int32_t ptr = (int32_t) &ret_area;
944-
__wasm_import_fastly_http_req_downstream_tls_client_certificate(ptr);
944+
__wasm_import_fastly_http_req_downstream_tls_raw_client_certificate(ptr);
945945
fastly_world_result_list_u8_error_t result;
946946
switch ((int32_t) (*((uint8_t*) (ptr + 0)))) {
947947
case 0: {

runtime/js-compute-runtime/fastly-world/fastly_world.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ bool fastly_http_req_downstream_tls_cipher_openssl_name(fastly_world_string_t *r
437437
fastly_error_t *err);
438438
bool fastly_http_req_downstream_tls_protocol(fastly_world_string_t *ret, fastly_error_t *err);
439439
bool fastly_http_req_downstream_tls_client_hello(fastly_world_list_u8_t *ret, fastly_error_t *err);
440-
bool fastly_http_req_downstream_tls_client_certificate(fastly_world_list_u8_t *ret,
441-
fastly_error_t *err);
440+
bool fastly_http_req_downstream_tls_raw_client_certificate(fastly_world_list_u8_t *ret,
441+
fastly_error_t *err);
442442
bool fastly_http_req_downstream_tls_client_cert_verify_result(fastly_error_t *err);
443443
bool fastly_http_req_downstream_tls_ja3_md5(fastly_world_list_u8_t *ret, fastly_error_t *err);
444444
bool fastly_http_req_new(fastly_request_handle_t *ret, fastly_error_t *err);

runtime/js-compute-runtime/fastly-world/fastly_world_adapter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ bool fastly_http_req_downstream_client_ip_addr(fastly_world_list_u8_t *ret, fast
186186
err);
187187
}
188188

189+
bool fastly_http_req_downstream_tls_cipher_openssl_name(fastly_world_string_t *ret,
190+
fastly_error_t *err) {
191+
ret->ptr = static_cast<char *>(cabi_malloc(128, 1));
192+
return convert_result(fastly::req_downstream_tls_cipher_openssl_name(
193+
reinterpret_cast<char *>(ret->ptr), 128, &ret->len),
194+
err);
195+
}
196+
189197
bool fastly_http_req_new(fastly_request_handle_t *ret, fastly_error_t *err) {
190198
return convert_result(fastly::req_new(ret), err);
191199
}
Binary file not shown.

runtime/js-compute-runtime/host_interface/fastly.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ int req_cache_override_v2_set(fastly_request_handle_t req_handle, int tag, uint3
149149
WASM_IMPORT("fastly_http_req", "downstream_client_ip_addr")
150150
int req_downstream_client_ip_addr_get(char *octets, size_t *nwritten);
151151

152-
// TODO:
152+
WASM_IMPORT("fastly_http_req", "downstream_tls_cipher_openssl_name")
153+
int req_downstream_tls_cipher_openssl_name(char *ret, size_t ret_len, size_t *nwritten);
153154

154155
// (@interface func (export "downstream_tls_cipher_openssl_name")
155156
// (param $cipher_out (@witx pointer char8))

runtime/js-compute-runtime/host_interface/host_api.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,20 @@ Result<HostBytes> HttpReq::downstream_client_ip_addr() {
502502
return res;
503503
}
504504

505+
// http-req-downstream-tls-cipher-openssl-name: func() -> result<string, error>
506+
Result<HostString> HttpReq::http_req_downstream_tls_cipher_openssl_name() {
507+
Result<HostString> res;
508+
509+
fastly_error_t err;
510+
fastly_world_string_t ret;
511+
if (!fastly_http_req_downstream_tls_cipher_openssl_name(&ret, &err)) {
512+
res.emplace_err(err);
513+
} else {
514+
res.emplace(ret);
515+
}
516+
517+
return res;
518+
}
505519
bool HttpReq::is_valid() const { return this->handle != HttpReq::invalid; }
506520

507521
Result<fastly_http_version_t> HttpReq::get_version() const {

runtime/js-compute-runtime/host_interface/host_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ class HttpReq final : public HttpBase {
255255
/// Get the downstream ip address.
256256
static Result<HostBytes> downstream_client_ip_addr();
257257

258+
static Result<HostString> http_req_downstream_tls_cipher_openssl_name();
259+
258260
/// Send this request synchronously, and wait for the response.
259261
Result<Response> send(HttpBody body, std::string_view backend);
260262

0 commit comments

Comments
 (0)