endpoint_security 0.1.0-universal-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +44 -0
- data/LICENSE.txt +21 -0
- data/README.md +114 -0
- data/Rakefile +170 -0
- data/codegen/ast.rb +67 -0
- data/codegen/emit_c.rb +68 -0
- data/codegen/emit_ruby.rb +128 -0
- data/codegen/ir.rb +193 -0
- data/codegen/overlay/availability.yml +158 -0
- data/codegen/overlay/version_map.yml +92 -0
- data/codegen/run.rb +80 -0
- data/codegen/snapshots/26.5.json +5828 -0
- data/examples/eslogger_clone.rb +5 -0
- data/examples/execblock.rb +16 -0
- data/examples/filemon.rb +10 -0
- data/examples/procmon.rb +13 -0
- data/ext/endpoint_security/client.c +795 -0
- data/ext/endpoint_security/client.h +88 -0
- data/ext/endpoint_security/endpoint_security.c +17 -0
- data/ext/endpoint_security/extconf.rb +37 -0
- data/ext/endpoint_security/field.c +719 -0
- data/ext/endpoint_security/field.h +42 -0
- data/ext/endpoint_security/generated/es_schema.c +1233 -0
- data/ext/endpoint_security/message.c +426 -0
- data/ext/endpoint_security/message.h +13 -0
- data/ext/endpoint_security/mute.c +291 -0
- data/ext/endpoint_security/mute.h +8 -0
- data/ext/endpoint_security/queue.c +124 -0
- data/ext/endpoint_security/queue.h +46 -0
- data/ext/endpoint_security/watchdog.c +243 -0
- data/lib/endpoint_security/availability.rb +30 -0
- data/lib/endpoint_security/client.rb +280 -0
- data/lib/endpoint_security/diagnostics.rb +26 -0
- data/lib/endpoint_security/doctor.rb +35 -0
- data/lib/endpoint_security/errors.rb +42 -0
- data/lib/endpoint_security/generated/availability.rb +169 -0
- data/lib/endpoint_security/generated/enums.rb +409 -0
- data/lib/endpoint_security/generated/event_types.rb +520 -0
- data/lib/endpoint_security/message.rb +29 -0
- data/lib/endpoint_security/object_model.rb +170 -0
- data/lib/endpoint_security/recorder.rb +26 -0
- data/lib/endpoint_security/version.rb +6 -0
- data/lib/endpoint_security.rb +38 -0
- data/support/entitlements.plist +8 -0
- data/support/esmock/esmock.c +482 -0
- data/support/esmock/esmock.h +21 -0
- data/support/sign_ruby.sh +13 -0
- metadata +90 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#ifndef ESRB_CLIENT_H
|
|
2
|
+
#define ESRB_CLIENT_H
|
|
3
|
+
|
|
4
|
+
#include <EndpointSecurity/EndpointSecurity.h>
|
|
5
|
+
#include <pthread.h>
|
|
6
|
+
#include <ruby.h>
|
|
7
|
+
#include <stdatomic.h>
|
|
8
|
+
#include <stdbool.h>
|
|
9
|
+
|
|
10
|
+
#include "queue.h"
|
|
11
|
+
|
|
12
|
+
typedef struct {
|
|
13
|
+
_Atomic size_t sequence;
|
|
14
|
+
esrb_slot_t *slot;
|
|
15
|
+
size_t position;
|
|
16
|
+
uint64_t fire_at;
|
|
17
|
+
} esrb_watchdog_request_t;
|
|
18
|
+
|
|
19
|
+
typedef struct {
|
|
20
|
+
esrb_slot_t *slot;
|
|
21
|
+
size_t position;
|
|
22
|
+
uint64_t fire_at;
|
|
23
|
+
} esrb_watchdog_entry_t;
|
|
24
|
+
|
|
25
|
+
typedef struct {
|
|
26
|
+
size_t capacity;
|
|
27
|
+
size_t mask;
|
|
28
|
+
esrb_watchdog_request_t *requests;
|
|
29
|
+
_Atomic size_t enqueue_position;
|
|
30
|
+
_Atomic size_t dequeue_position;
|
|
31
|
+
esrb_watchdog_entry_t *heap;
|
|
32
|
+
size_t heap_size;
|
|
33
|
+
pthread_mutex_t mutex;
|
|
34
|
+
pthread_cond_t condition;
|
|
35
|
+
} esrb_watchdog_t;
|
|
36
|
+
|
|
37
|
+
typedef struct {
|
|
38
|
+
es_client_t *client;
|
|
39
|
+
esrb_queue_t queue;
|
|
40
|
+
int wakeup_fd[2];
|
|
41
|
+
pthread_t watchdog_thread;
|
|
42
|
+
esrb_watchdog_t watchdog;
|
|
43
|
+
bool watchdog_thread_started;
|
|
44
|
+
_Atomic bool watchdog_running;
|
|
45
|
+
_Atomic bool watchdog_stopped;
|
|
46
|
+
_Atomic bool delete_ready;
|
|
47
|
+
_Atomic bool client_ready;
|
|
48
|
+
_Atomic es_new_client_result_t creation_result;
|
|
49
|
+
_Atomic bool notified;
|
|
50
|
+
_Atomic bool closed;
|
|
51
|
+
_Atomic uint32_t active_callbacks;
|
|
52
|
+
_Atomic uint64_t dropped;
|
|
53
|
+
_Atomic uint64_t delivered;
|
|
54
|
+
_Atomic uint64_t timeouts;
|
|
55
|
+
_Atomic uint64_t response_errors;
|
|
56
|
+
_Atomic uint64_t delete_errors;
|
|
57
|
+
_Atomic uint64_t errors;
|
|
58
|
+
_Atomic uint64_t seq_gaps;
|
|
59
|
+
_Atomic uint64_t leaked_messages;
|
|
60
|
+
_Atomic uint64_t last_global_seq;
|
|
61
|
+
_Atomic bool seen_global_seq;
|
|
62
|
+
_Atomic uint64_t last_event_seq[ES_EVENT_TYPE_LAST];
|
|
63
|
+
_Atomic bool seen_event_seq[ES_EVENT_TYPE_LAST];
|
|
64
|
+
es_auth_result_t default_auth;
|
|
65
|
+
bool default_cache;
|
|
66
|
+
bool strict_cache;
|
|
67
|
+
bool strict_version;
|
|
68
|
+
bool warn_on_truncated_path;
|
|
69
|
+
double deadline_margin;
|
|
70
|
+
uint64_t min_margin_ticks;
|
|
71
|
+
pid_t owner_pid;
|
|
72
|
+
} esrb_client_t;
|
|
73
|
+
|
|
74
|
+
extern const rb_data_type_t esrb_client_type;
|
|
75
|
+
|
|
76
|
+
void esrb_init_client(VALUE endpoint_security);
|
|
77
|
+
void esrb_notify(esrb_client_t *client);
|
|
78
|
+
es_respond_result_t esrb_send_response(esrb_client_t *client, es_client_t *native_client,
|
|
79
|
+
const es_message_t *message, es_auth_result_t result, uint32_t flags, bool cache);
|
|
80
|
+
bool esrb_respond_slot(esrb_client_t *client, esrb_slot_t *slot, es_auth_result_t result, uint32_t flags, bool cache,
|
|
81
|
+
es_respond_result_t *response);
|
|
82
|
+
bool esrb_watchdog_init(esrb_watchdog_t *watchdog, size_t capacity);
|
|
83
|
+
void esrb_watchdog_destroy(esrb_watchdog_t *watchdog);
|
|
84
|
+
void esrb_watchdog_abandon(esrb_watchdog_t *watchdog);
|
|
85
|
+
bool esrb_watchdog_arm(esrb_watchdog_t *watchdog, esrb_slot_t *slot);
|
|
86
|
+
void *esrb_watchdog_main(void *argument);
|
|
87
|
+
|
|
88
|
+
#endif
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* endpoint_security.c
|
|
2
|
+
* Calling thread: Ruby VM thread with the GVL.
|
|
3
|
+
*/
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "client.h"
|
|
7
|
+
#include "field.h"
|
|
8
|
+
#include "message.h"
|
|
9
|
+
|
|
10
|
+
RUBY_FUNC_EXPORTED void
|
|
11
|
+
Init_endpoint_security(void)
|
|
12
|
+
{
|
|
13
|
+
VALUE endpoint_security = rb_define_module("EndpointSecurity");
|
|
14
|
+
esrb_init_field(endpoint_security);
|
|
15
|
+
esrb_init_message(endpoint_security);
|
|
16
|
+
esrb_init_client(endpoint_security);
|
|
17
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "mkmf"
|
|
4
|
+
require "open3"
|
|
5
|
+
require "shellwords"
|
|
6
|
+
|
|
7
|
+
abort "endpoint_security requires macOS 13 or newer" unless RUBY_PLATFORM.include?("darwin")
|
|
8
|
+
macos_version, macos_status = Open3.capture2("sw_vers", "-productVersion")
|
|
9
|
+
abort "endpoint_security requires macOS 13 or newer" unless macos_status.success? && macos_version.to_i >= 13
|
|
10
|
+
|
|
11
|
+
sdk, status = Open3.capture2("xcrun", "--show-sdk-path")
|
|
12
|
+
abort "xcrun could not locate the macOS SDK; install Xcode Command Line Tools" unless status.success?
|
|
13
|
+
|
|
14
|
+
sdk = sdk.strip
|
|
15
|
+
dir_config("endpoint_security", File.join(sdk, "usr/include"), File.join(sdk, "usr/lib"))
|
|
16
|
+
$CFLAGS << " -std=c11 -fblocks -Wall -Wextra -Wno-unused-parameter -Werror=implicit-function-declaration"
|
|
17
|
+
$CFLAGS << " -Wno-default-const-init-field-unsafe" if try_compile("int main(void) { return 0; }",
|
|
18
|
+
"-Werror -Wno-default-const-init-field-unsafe")
|
|
19
|
+
$CFLAGS << " -fvisibility=hidden -mmacosx-version-min=13.0"
|
|
20
|
+
$LDFLAGS << " -isysroot #{sdk.shellescape} -mmacosx-version-min=13.0"
|
|
21
|
+
$INCFLAGS << " -I#{File.expand_path("../../support/esmock", __dir__).shellescape}"
|
|
22
|
+
|
|
23
|
+
abort "EndpointSecurity headers are missing from #{sdk}" unless have_header("EndpointSecurity/EndpointSecurity.h")
|
|
24
|
+
if ENV["ES_MOCK"] == "1"
|
|
25
|
+
$defs << "-DESRB_MOCK"
|
|
26
|
+
$LDFLAGS << " -L#{File.expand_path("../../build", __dir__).shellescape} -Wl,-rpath,@loader_path/../../build"
|
|
27
|
+
endpoint_security_found = have_library("esmock")
|
|
28
|
+
else
|
|
29
|
+
endpoint_security_found = have_framework("EndpointSecurity") || have_library("EndpointSecurity")
|
|
30
|
+
end
|
|
31
|
+
abort "EndpointSecurity library is unavailable" unless endpoint_security_found
|
|
32
|
+
abort "libbsm is unavailable" unless have_library("bsm")
|
|
33
|
+
|
|
34
|
+
$VPATH << "$(srcdir)/generated"
|
|
35
|
+
$srcs = Dir[File.join(__dir__, "*.c")].map { |path| File.basename(path) }
|
|
36
|
+
$srcs << "es_schema.c" if File.exist?(File.join(__dir__, "generated/es_schema.c"))
|
|
37
|
+
create_makefile("endpoint_security/endpoint_security")
|