Skip to content

Commit 9043103

Browse files
authored
chore: Add client-cert and client-key to dynamic-backend-config (#622)
1 parent 87bf840 commit 9043103

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

runtime/js-compute-runtime/host_interface/component/fastly_world.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ bool fastly_compute_at_edge_http_req_framing_headers_mode_set(fastly_compute_at_
29182918

29192919
bool fastly_compute_at_edge_http_req_register_dynamic_backend(fastly_world_string_t *prefix, fastly_world_string_t *target, fastly_compute_at_edge_http_req_dynamic_backend_config_t *config, fastly_compute_at_edge_http_req_error_t *err) {
29202920
__attribute__((__aligned__(4)))
2921-
uint8_t ret_area[108];
2921+
uint8_t ret_area[124];
29222922
int32_t ptr = (int32_t) &ret_area;
29232923
*((int32_t*)(ptr + 4)) = (int32_t) (*prefix).len;
29242924
*((int32_t*)(ptr + 0)) = (int32_t) (*prefix).ptr;
@@ -3013,17 +3013,26 @@ bool fastly_compute_at_edge_http_req_register_dynamic_backend(fastly_world_strin
30133013
} else {
30143014
*((int8_t*)(ptr + 96)) = 0;
30153015
}
3016-
int32_t ptr23 = (int32_t) &ret_area;
3017-
__wasm_import_fastly_compute_at_edge_http_req_register_dynamic_backend(ptr, ptr23);
3016+
if (((*config).client_cert).is_some) {
3017+
const fastly_compute_at_edge_http_types_client_cert_config_t *payload24 = &((*config).client_cert).val;
3018+
*((int8_t*)(ptr + 108)) = 1;
3019+
*((int32_t*)(ptr + 116)) = (int32_t) ((*payload24).client_cert).len;
3020+
*((int32_t*)(ptr + 112)) = (int32_t) ((*payload24).client_cert).ptr;
3021+
*((int32_t*)(ptr + 120)) = (int32_t) ((*payload24).client_key);
3022+
} else {
3023+
*((int8_t*)(ptr + 108)) = 0;
3024+
}
3025+
int32_t ptr25 = (int32_t) &ret_area;
3026+
__wasm_import_fastly_compute_at_edge_http_req_register_dynamic_backend(ptr, ptr25);
30183027
fastly_world_result_void_fastly_compute_at_edge_http_req_error_t result;
3019-
switch ((int32_t) (*((uint8_t*) (ptr23 + 0)))) {
3028+
switch ((int32_t) (*((uint8_t*) (ptr25 + 0)))) {
30203029
case 0: {
30213030
result.is_err = false;
30223031
break;
30233032
}
30243033
case 1: {
30253034
result.is_err = true;
3026-
result.val.err = (int32_t) (*((uint8_t*) (ptr23 + 1)));
3035+
result.val.err = (int32_t) (*((uint8_t*) (ptr25 + 1)));
30273036
break;
30283037
}
30293038
}

runtime/js-compute-runtime/host_interface/component/fastly_world.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ typedef uint8_t fastly_compute_at_edge_types_error_t;
6464
// resources permitted. For example, creating too many response handles.
6565
#define FASTLY_COMPUTE_AT_EDGE_TYPES_ERROR_LIMIT_EXCEEDED 13
6666

67+
typedef uint32_t fastly_compute_at_edge_types_secret_handle_t;
68+
69+
typedef fastly_compute_at_edge_types_secret_handle_t fastly_compute_at_edge_http_types_secret_handle_t;
70+
6771
typedef uint32_t fastly_compute_at_edge_http_types_body_handle_t;
6872

6973
typedef uint32_t fastly_compute_at_edge_http_types_request_handle_t;
@@ -107,6 +111,11 @@ typedef uint8_t fastly_compute_at_edge_http_types_tls_version_t;
107111
#define FASTLY_COMPUTE_AT_EDGE_HTTP_TYPES_TLS_VERSION_TLS12 2
108112
#define FASTLY_COMPUTE_AT_EDGE_HTTP_TYPES_TLS_VERSION_TLS13 3
109113

114+
typedef struct {
115+
fastly_world_string_t client_cert;
116+
fastly_compute_at_edge_http_types_secret_handle_t client_key;
117+
} fastly_compute_at_edge_http_types_client_cert_config_t;
118+
110119
typedef struct {
111120
bool is_some;
112121
fastly_world_string_t val;
@@ -127,6 +136,11 @@ typedef struct {
127136
fastly_compute_at_edge_http_types_tls_version_t val;
128137
} fastly_world_option_fastly_compute_at_edge_http_types_tls_version_t;
129138

139+
typedef struct {
140+
bool is_some;
141+
fastly_compute_at_edge_http_types_client_cert_config_t val;
142+
} fastly_world_option_fastly_compute_at_edge_http_types_client_cert_config_t;
143+
130144
// Create a backend for later use
131145
typedef struct {
132146
fastly_world_option_string_t host_override;
@@ -141,6 +155,7 @@ typedef struct {
141155
fastly_world_option_string_t ca_cert;
142156
fastly_world_option_string_t ciphers;
143157
fastly_world_option_string_t sni_hostname;
158+
fastly_world_option_fastly_compute_at_edge_http_types_client_cert_config_t client_cert;
144159
} fastly_compute_at_edge_http_types_dynamic_backend_config_t;
145160

146161
typedef uint16_t fastly_compute_at_edge_http_types_http_status_t;
@@ -331,9 +346,9 @@ typedef struct {
331346

332347
typedef fastly_compute_at_edge_types_error_t fastly_compute_at_edge_secret_store_error_t;
333348

334-
typedef uint32_t fastly_compute_at_edge_secret_store_store_handle_t;
349+
typedef fastly_compute_at_edge_types_secret_handle_t fastly_compute_at_edge_secret_store_secret_handle_t;
335350

336-
typedef uint32_t fastly_compute_at_edge_secret_store_secret_handle_t;
351+
typedef uint32_t fastly_compute_at_edge_secret_store_store_handle_t;
337352

338353
typedef struct {
339354
bool is_some;
Binary file not shown.

runtime/js-compute-runtime/host_interface/wit/deps/fastly/compute-at-edge.wit

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ interface types {
5050
/// resources permitted. For example, creating too many response handles.
5151
limit-exceeded
5252
}
53+
54+
type secret-handle = u32
5355
}
5456

5557
interface http-types {
5658

59+
use types.{secret-handle}
60+
5761
type body-handle = u32
5862

5963
type request-handle = u32
@@ -87,6 +91,11 @@ interface http-types {
8791
tls13
8892
}
8993

94+
record client-cert-config {
95+
client-cert: string,
96+
client-key: secret-handle,
97+
}
98+
9099
/// Create a backend for later use
91100
record dynamic-backend-config {
92101
host-override: option<string>,
@@ -101,6 +110,7 @@ interface http-types {
101110
ca-cert: option<string>,
102111
ciphers: option<string>,
103112
sni-hostname: option<string>,
113+
client-cert: option<client-cert-config>,
104114
}
105115

106116
type http-status = u16
@@ -488,12 +498,10 @@ interface object-store {
488498
*/
489499
interface secret-store {
490500

491-
use types.{error}
501+
use types.{error, secret-handle}
492502

493503
type store-handle = u32
494504

495-
type secret-handle = u32
496-
497505
open: func(name: string) -> result<store-handle, error>
498506

499507
get: func(store: store-handle, key: string) -> result<option<secret-handle>, error>

0 commit comments

Comments
 (0)