Skip to content

Commit

Permalink
Add ja4
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Mar 20, 2024
1 parent d0f41df commit a3d6277
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Sources/Compute/Fastly/FastlyRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,10 @@ extension Fastly.Request {
try wasi(fastly_http_req__downstream_tls_ja3_md5(buffer.baseAddress, &length))
}
}

public static func downstreamTLSJA4() throws -> String? {
return try wasiString(maxBufferLength: 1024) {
fastly_http_req__downstream_tls_ja4($0, $1, &$2)
}
}
}
6 changes: 6 additions & 0 deletions Sources/Compute/Fastly/FastlyStubs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func fastly_http_req__register_dynamic_backend(_ name: UnsafePointer<CChar>!, _

func fastly_http_req__downstream_tls_ja3_md5(_ value: UnsafeMutablePointer<UInt8>!, _ nwritten: UnsafeMutablePointer<Int>!) -> Int32 { fatalError() }

func fastly_http_req__downstream_tls_ja4(
_ value: UnsafeMutablePointer<UInt8>!,
_ max_len: Int,
_ nwritten_out: UnsafeMutablePointer<Int>!
) -> Int32 { fatalError() }

/* FASTLY_HTTP_RESP */

func fastly_http_resp__new(_ handle: UnsafeMutablePointer<WasiHandle>!) -> Int32 { fatalError() }
Expand Down
14 changes: 12 additions & 2 deletions Sources/Compute/IncomingRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ public struct IncomingRequest: Sendable {

extension IncomingRequest {

public func clientFingerprint() -> String? {
return try? Fastly.Request.downstreamTLSJA3MD5().hex
public enum ClientFingerprintMethod: Sendable {
case ja3
case ja4
}

public func clientFingerprint(_ method: ClientFingerprintMethod = .ja3) -> String? {
switch method {
case .ja3:
return try? Fastly.Request.downstreamTLSJA3MD5().hex
case .ja4:
return try? Fastly.Request.downstreamTLSJA4()
}
}
}
3 changes: 3 additions & 0 deletions Sources/ComputeRuntime/include/ComputeRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ int fastly_http_req__redirect_to_grip_proxy(const char *backend, size_t backend_
WASM_IMPORT("fastly_http_req", "downstream_tls_ja3_md5")
int fastly_http_req__downstream_tls_ja3_md5(uint8_t *value, size_t *nwritten);

WASM_IMPORT("fastly_http_req", "downstream_tls_ja4")
int fastly_http_req__downstream_tls_ja4(uint8_t *value, size_t max_len, size_t* nwritten_out);

typedef struct DynamicBackendConfig {
const char* host_override;
size_t host_override_len;
Expand Down

0 comments on commit a3d6277

Please sign in to comment.