|
47 | 47 | #include "Source/common/String.h" |
48 | 48 | #include "Source/common/SystemResources.h" |
49 | 49 | #include "Source/common/Unit.h" |
| 50 | +#include "Source/santad/CELActivation.h" |
50 | 51 | #import "Source/santad/DataLayer/SNTEventTable.h" |
51 | 52 | #import "Source/santad/DataLayer/SNTRuleTable.h" |
52 | 53 | #include "Source/santad/EventProviders/EndpointSecurity/EndpointSecurityAPI.h" |
53 | | -#include "Source/santad/ProcessTree/process_tree_macos.h" |
54 | 54 | #import "Source/santad/SNTDecisionCache.h" |
55 | 55 | #import "Source/santad/SNTNotificationQueue.h" |
56 | 56 | #import "Source/santad/SNTSyncdQueue.h" |
@@ -263,10 +263,8 @@ - (void)validateExecEvent:(const Message &)esMsg postAction:(bool (^)(SNTAction) |
263 | 263 | decisionForFileInfo:binInfo |
264 | 264 | targetProcess:targetProc |
265 | 265 | configState:configState |
266 | | - activationCallback:[self |
267 | | - createActivationBlockForMessage:esMsg |
268 | | - andCSInfo:[binInfo |
269 | | - codesignCheckerWithError:NULL]]]; |
| 266 | + activationCallback:santa::CreateCELActivationBlock( |
| 267 | + esMsg, [binInfo codesignCheckerWithError:NULL], _processTree)]; |
270 | 268 |
|
271 | 269 | cd.codesigningFlags = targetProc->codesigning_flags; |
272 | 270 | cd.vnodeId = SantaVnode::VnodeForFile(targetProc->executable); |
@@ -649,117 +647,8 @@ - (void)createRuleForStandaloneModeEvent:(SNTStoredExecutionEvent *)se { |
649 | 647 | // TODO: Notify the sync service of the new rule. |
650 | 648 | } |
651 | 649 |
|
652 | | -// Create a block that returns a santa::cel::Activation object for the given Message |
653 | | -// and MOLCodesignChecker object. The block defines a bool parameter that determines |
654 | | -// whether to create a v1 or v2 activation object. |
655 | | -// |
656 | | -// Note: The returned block captures a reference to the Message object and must |
657 | | -// not use it after the Message object is destroyed. Care must be taken to not |
658 | | -// use this in an asynchronous context outside of the evaluation of that execution. |
659 | | -- (ActivationCallbackBlock)createActivationBlockForMessage:(const santa::Message &)esMsg |
660 | | - andCSInfo:(nullable MOLCodesignChecker *)csInfo { |
661 | | - std::shared_ptr<santa::EndpointSecurityAPI> esApi = esMsg.ESAPI(); |
662 | | - std::shared_ptr<santa::santad::process_tree::ProcessTree> processTree = _processTree; |
663 | | - |
664 | | - return ^std::unique_ptr<::google::api::expr::runtime::BaseActivation>(bool useV2) { |
665 | | - auto makeActivation = |
666 | | - [&]<bool IsV2>() -> std::unique_ptr<::google::api::expr::runtime::BaseActivation> { |
667 | | - using Traits = santa::cel::CELProtoTraits<IsV2>; |
668 | | - using ExecutableFileT = typename Traits::ExecutableFileT; |
669 | | - using AncestorT = typename Traits::AncestorT; |
670 | | - |
671 | | - auto f = std::make_unique<ExecutableFileT>(); |
672 | | - |
673 | | - if (csInfo.signingTime) { |
674 | | - f->mutable_signing_time()->set_seconds(csInfo.signingTime.timeIntervalSince1970); |
675 | | - } |
676 | | - if (csInfo.secureSigningTime) { |
677 | | - f->mutable_secure_signing_time()->set_seconds( |
678 | | - csInfo.secureSigningTime.timeIntervalSince1970); |
679 | | - } |
680 | | - |
681 | | - return std::make_unique<santa::cel::Activation<IsV2>>( |
682 | | - std::move(f), |
683 | | - ^std::vector<std::string>() { |
684 | | - return esApi->ExecArgs(&esMsg->event.exec); |
685 | | - }, |
686 | | - ^std::map<std::string, std::string>() { |
687 | | - return esApi->ExecEnvs(&esMsg->event.exec); |
688 | | - }, |
689 | | - ^uid_t() { |
690 | | - return audit_token_to_euid(esMsg->event.exec.target->audit_token); |
691 | | - }, |
692 | | - ^std::string() { |
693 | | - es_file_t *f = esMsg->event.exec.cwd; |
694 | | - return std::string(f->path.data, f->path.length); |
695 | | - }, |
696 | | - ^std::vector<AncestorT>() { |
697 | | - return Ancestors<IsV2>(processTree, esMsg); |
698 | | - }); |
699 | | - }; |
700 | | - |
701 | | - if (useV2) { |
702 | | - return makeActivation.operator()<true>(); |
703 | | - } else { |
704 | | - return makeActivation.operator()<false>(); |
705 | | - } |
706 | | - }; |
707 | | -} |
708 | | - |
709 | 650 | - (void)flushTouchIDApprovalCache { |
710 | 651 | _touchIDApprovalCache->clear(); |
711 | 652 | } |
712 | 653 |
|
713 | | -template <bool IsV2> |
714 | | -std::vector<typename santa::cel::CELProtoTraits<IsV2>::AncestorT> Ancestors( |
715 | | - const std::shared_ptr<santa::santad::process_tree::ProcessTree> &processTree, |
716 | | - const santa::Message &esMsg); |
717 | | - |
718 | | -template <> |
719 | | -std::vector<santa::cel::CELProtoTraits<true>::AncestorT> Ancestors<true>( |
720 | | - const std::shared_ptr<santa::santad::process_tree::ProcessTree> &processTree, |
721 | | - const santa::Message &esMsg) { |
722 | | - if (!processTree) return {}; |
723 | | - |
724 | | - using Traits = santa::cel::CELProtoTraits<true>; |
725 | | - using AncestorT = typename Traits::AncestorT; |
726 | | - |
727 | | - auto pid = santa::santad::process_tree::PidFromAuditToken(esMsg->process->parent_audit_token); |
728 | | - auto proc = processTree->Get(pid); |
729 | | - if (!proc) { |
730 | | - return {}; |
731 | | - } |
732 | | - |
733 | | - std::vector<santa::cel::CELProtoTraits<true>::AncestorT> ancestors; |
734 | | - for (const auto &p : processTree->RootSlice(*proc)) { |
735 | | - if (!p->program_) { |
736 | | - continue; |
737 | | - } |
738 | | - |
739 | | - AncestorT ancestor; |
740 | | - ancestor.set_path(p->program_->executable); |
741 | | - |
742 | | - if (p->program_->code_signing) { |
743 | | - const auto &cs = *p->program_->code_signing; |
744 | | - if (cs.is_platform_binary) { |
745 | | - ancestor.set_signing_id("platform:" + cs.signing_id); |
746 | | - } else { |
747 | | - ancestor.set_signing_id(cs.team_id + ":" + cs.signing_id); |
748 | | - } |
749 | | - ancestor.set_team_id(cs.team_id); |
750 | | - ancestor.set_cdhash(cs.cdhash); |
751 | | - } |
752 | | - |
753 | | - ancestors.push_back(std::move(ancestor)); |
754 | | - } |
755 | | - return ancestors; |
756 | | -} |
757 | | - |
758 | | -template <> |
759 | | -std::vector<santa::cel::CELProtoTraits<false>::AncestorT> Ancestors<false>( |
760 | | - const std::shared_ptr<santa::santad::process_tree::ProcessTree> &processTree, |
761 | | - const santa::Message &esMsg) { |
762 | | - return {}; |
763 | | -} |
764 | | - |
765 | 654 | @end |
0 commit comments