Skip to content

Commit

Permalink
Merge branch 'main' into markowsky/json-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarkowsky committed Sep 12, 2023
2 parents ad90396 + d2e5aec commit 2587562
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 48 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build --copt=-Wno-unknown-warning-option
build --copt=-Wno-error=deprecated-non-prototype
build --per_file_copt=.*\.mm\$@-std=c++17
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17

build --copt=-DSANTA_OPEN_SOURCE=1
build --cxxopt=-DSANTA_OPEN_SOURCE=1
Expand Down
1 change: 1 addition & 0 deletions Source/santactl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ objc_library(
"//Source/common:SNTLogging",
"//Source/common:santa_cc_proto_library_wrapper",
"//Source/santad/Logs/EndpointSecurity/Writers/FSSpool:binaryproto_cc_proto_library_wrapper",
"@com_google_protobuf//src/google/protobuf/json",
],
)

Expand Down
6 changes: 3 additions & 3 deletions Source/santactl/Commands/SNTCommandPrintLog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// limitations under the License.

#import <Foundation/Foundation.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/json/json.h>
#include <stdlib.h>

#include <iostream>
Expand All @@ -26,8 +26,8 @@
#include "Source/santad/Logs/EndpointSecurity/Writers/FSSpool/binaryproto_proto_include_wrapper.h"
#include "google/protobuf/any.pb.h"

using google::protobuf::util::JsonPrintOptions;
using google::protobuf::util::MessageToJsonString;
using JsonPrintOptions = google::protobuf::json::PrintOptions;
using google::protobuf::json::MessageToJsonString;
using santa::fsspool::binaryproto::LogBatch;
namespace pbv1 = ::santa::pb::v1;

Expand Down
4 changes: 4 additions & 0 deletions Source/santad/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ objc_library(
"//Source/common:SNTStoredEvent",
"//Source/common:String",
"//Source/common:santa_cc_proto_library_wrapper",
"@com_google_absl//absl/status",
"@com_google_protobuf//src/google/protobuf/json",
],
)

Expand Down Expand Up @@ -987,7 +989,9 @@ santa_unit_test(
"//Source/common:TestUtils",
"//Source/common:santa_cc_proto_library_wrapper",
"@OCMock",
"@com_google_absl//absl/status",
"@com_google_googletest//:gtest",
"@com_google_protobuf//src/google/protobuf/json",
],
)

Expand Down
10 changes: 5 additions & 5 deletions Source/santad/Logs/EndpointSecurity/Serializers/Protobuf.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#include <EndpointSecurity/EndpointSecurity.h>
#include <Kernel/kern/cs_blobs.h>
#include <bsm/libbsm.h>
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/json/json.h>
#include <mach/message.h>
#include <math.h>
#include <sys/proc_info.h>
Expand All @@ -36,12 +35,13 @@
#include "Source/santad/EventProviders/EndpointSecurity/EndpointSecurityAPI.h"
#include "Source/santad/Logs/EndpointSecurity/Serializers/Utilities.h"
#import "Source/santad/SNTDecisionCache.h"
#include "absl/status/status.h"
#include "google/protobuf/timestamp.pb.h"

using google::protobuf::Arena;
using google::protobuf::Timestamp;
using google::protobuf::util::JsonPrintOptions;
using google::protobuf::util::MessageToJsonString;
using JsonPrintOptions = google::protobuf::json::PrintOptions;
using google::protobuf::json::MessageToJsonString;

using santa::common::NSStringToUTF8StringView;
using santa::santad::event_providers::endpoint_security::EndpointSecurityAPI;
Expand Down Expand Up @@ -401,7 +401,7 @@ static inline void EncodeCertificateInfo(::pbv1::CertificateInfo *pb_cert_info,
options.preserve_proto_field_names = true;
std::string json;

google::protobuf::util::Status status = MessageToJsonString(*santa_msg, &json, options);
absl::Status status = MessageToJsonString(*santa_msg, &json, options);

if (!status.ok()) {
LOGE(@"Failed to convert protobuf to JSON: %s", status.ToString().c_str());
Expand Down
16 changes: 10 additions & 6 deletions Source/santad/Logs/EndpointSecurity/Serializers/ProtobufTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>
#include <gmock/gmock.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/json/json.h>
#include <gtest/gtest.h>
#include <sys/proc_info.h>
#include <sys/signal.h>
Expand All @@ -40,12 +40,15 @@
#include "Source/santad/Logs/EndpointSecurity/Serializers/Protobuf.h"
#include "Source/santad/Logs/EndpointSecurity/Serializers/Serializer.h"
#import "Source/santad/SNTDecisionCache.h"
#include "absl/status/status.h"
#include "google/protobuf/any.pb.h"
#include "google/protobuf/timestamp.pb.h"

using google::protobuf::Timestamp;
using google::protobuf::util::JsonPrintOptions;
using google::protobuf::util::JsonStringToMessage;
using JsonPrintOptions = google::protobuf::json::PrintOptions;
using JsonParseOptions = ::google::protobuf::json::ParseOptions;
using google::protobuf::json::JsonStringToMessage;
using google::protobuf::json::MessageToJsonString;
using santa::santad::event_providers::endpoint_security::EnrichedEventType;
using santa::santad::event_providers::endpoint_security::EnrichedMessage;
using santa::santad::event_providers::endpoint_security::Enricher;
Expand Down Expand Up @@ -157,7 +160,7 @@ bool CompareTime(const Timestamp &timestamp, struct timespec ts) {
const google::protobuf::Message &message = SantaMessageEvent(santaMsg);

std::string json;
XCTAssertTrue(google::protobuf::util::MessageToJsonString(message, &json, options).ok());
XCTAssertTrue(MessageToJsonString(message, &json, options).ok());
return json;
}

Expand Down Expand Up @@ -236,9 +239,10 @@ void SerializeAndCheck(es_event_type_t eventType,
if (json) {
// Parse the jsonified string into the protobuf
// gotData = protoStr;
google::protobuf::util::JsonParseOptions options;
JsonParseOptions options;
options.ignore_unknown_fields = true;
google::protobuf::util::Status status = JsonStringToMessage(protoStr, &santaMsg, options);
absl::Status status = JsonStringToMessage(protoStr, &santaMsg, options);
XCTAssertTrue(status.ok());
gotData = ConvertMessageToJsonString(santaMsg);
} else {
XCTAssertTrue(santaMsg.ParseFromString(protoStr));
Expand Down
1 change: 1 addition & 0 deletions Source/santad/Logs/EndpointSecurity/Writers/FSSpool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ proto_library(
srcs = ["binaryproto.proto"],
deps = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:timestamp_proto",
],
)

Expand Down
15 changes: 7 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ load(
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Abseil - Abseil LTS branch, June 2022, Patch 1
# Abseil LTS branch, Aug 2023
http_archive(
name = "com_google_absl",
sha256 = "b9f490fae1c0d89a19073a081c3c588452461e5586e4ae31bc50a8f36339135e",
strip_prefix = "abseil-cpp-8c0b94e793a66495e0b1f34a5eb26bd7dc672db0",
urls = ["https://github.com/abseil/abseil-cpp/archive/8c0b94e793a66495e0b1f34a5eb26bd7dc672db0.zip"],
strip_prefix = "abseil-cpp-20230802.0",
urls = ["https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.0.tar.gz"],
)

http_archive(
name = "com_google_protobuf",
patch_args = ["-p1"],
patches = ["//external_patches/com_google_protobuf:10120.patch"],
sha256 = "73c95c7b0c13f597a6a1fec7121b07e90fd12b4ed7ff5a781253b3afe07fc077",
strip_prefix = "protobuf-3.21.6",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.21.6.tar.gz"],
patches = ["//external_patches/com_google_protobuf:13636.patch"],
sha256 = "07d69502e58248927b58c7d7e7424135272ba5b2852a753ab6b67e62d2d29355",
strip_prefix = "protobuf-24.3",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v24.3.tar.gz"],
)

# We don't directly use rules_python but several dependencies do and they disagree
Expand Down
26 changes: 0 additions & 26 deletions external_patches/com_google_protobuf/10120.patch

This file was deleted.

15 changes: 15 additions & 0 deletions external_patches/com_google_protobuf/13636.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl
index ee552c13e..f0bba0385 100644
--- a/protobuf_deps.bzl
+++ b/protobuf_deps.bzl
@@ -70,8 +70,8 @@ def protobuf_deps():
_github_archive(
name = "utf8_range",
repo = "https://github.com/protocolbuffers/utf8_range",
- commit = "de0b4a8ff9b5d4c98108bdfe723291a33c52c54f",
- sha256 = "5da960e5e5d92394c809629a03af3c7709d2d3d0ca731dacb3a9fb4bf28f7702",
+ commit = "d863bc33e15cba6d873c878dcca9e6fe52b2f8cb",
+ sha256 = "568988b5f7261ca181468dba38849fabf59dd9200fb2ed4b2823da187ef84d8c",
)

if not native.existing_rule("rules_cc"):

0 comments on commit 2587562

Please sign in to comment.