зеркало из https://github.com/microsoft/CCF.git
Initial commit of external executor app (#4173)
This commit is contained in:
Родитель
19994a52b1
Коммит
04b146a0f2
|
@ -241,6 +241,9 @@ add_custom_target(
|
|||
# Add sample apps
|
||||
add_subdirectory(${CCF_DIR}/samples)
|
||||
|
||||
# Add external_executor app
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/apps/external_executor)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
enable_testing()
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the Apache 2.0 License.
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(external_executor LANGUAGES C CXX)
|
||||
|
||||
set(CCF_PROJECT "ccf")
|
||||
|
||||
if(NOT TARGET ${CCF_PROJECT})
|
||||
find_package(${CCF_PROJECT} REQUIRED)
|
||||
endif()
|
||||
|
||||
add_ccf_app(external_executor SRCS external_executor.cpp)
|
||||
|
||||
# Generate an ephemeral signing key
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/signing_key.pem
|
||||
COMMAND openssl genrsa -out ${CMAKE_CURRENT_BINARY_DIR}/signing_key.pem -3
|
||||
3072
|
||||
)
|
||||
add_custom_target(
|
||||
external_executor_signing_key ALL
|
||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/signing_key.pem
|
||||
)
|
||||
|
||||
sign_app_library(
|
||||
external_executor.enclave ${CMAKE_CURRENT_SOURCE_DIR}/oe_sign.conf
|
||||
${CMAKE_CURRENT_BINARY_DIR}/signing_key.pem
|
||||
)
|
|
@ -0,0 +1,16 @@
|
|||
syntax = "proto3";
|
||||
|
||||
import "google/protobuf/any.proto";
|
||||
|
||||
package ccf;
|
||||
|
||||
message Test
|
||||
{
|
||||
string content = 1;
|
||||
}
|
||||
|
||||
service Echo
|
||||
{
|
||||
rpc Echo (google.protobuf.Any) returns (google.protobuf.Any) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the Apache 2.0 License.
|
||||
|
||||
#include "ccf/app_interface.h"
|
||||
#include "ccf/common_auth_policies.h"
|
||||
#include "ccf/http_consts.h"
|
||||
|
||||
#define FMT_HEADER_ONLY
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace externalexecutor
|
||||
{
|
||||
class EndpointRegistry : public ccf::UserEndpointRegistry
|
||||
{
|
||||
void install_registry_service() {}
|
||||
|
||||
void install_kv_service() {}
|
||||
|
||||
void echo_header(
|
||||
std::shared_ptr<ccf::RpcContext>& rpc_ctx, const std::string_view& sv)
|
||||
{
|
||||
const auto header_val = rpc_ctx->get_request_header(sv);
|
||||
if (header_val.has_value())
|
||||
{
|
||||
rpc_ctx->set_response_header(sv, *header_val);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
EndpointRegistry(ccfapp::AbstractNodeContext& context) :
|
||||
ccf::UserEndpointRegistry(context)
|
||||
{
|
||||
install_registry_service();
|
||||
|
||||
install_kv_service();
|
||||
|
||||
auto do_echo = [this](ccf::endpoints::EndpointContext& ctx) {
|
||||
CCF_APP_INFO("ECHO HANDLER BEGIN");
|
||||
|
||||
const auto headers = ctx.rpc_ctx->get_request_headers();
|
||||
CCF_APP_INFO("Request contains {} headers", headers.size());
|
||||
for (const auto& [k, v] : headers)
|
||||
{
|
||||
CCF_APP_INFO(" {} = {}", k, v);
|
||||
}
|
||||
|
||||
echo_header(ctx.rpc_ctx, http::headers::CONTENT_TYPE);
|
||||
|
||||
ctx.rpc_ctx->set_response_body(ctx.rpc_ctx->get_request_body());
|
||||
ctx.rpc_ctx->set_response_status(HTTP_STATUS_OK);
|
||||
CCF_APP_INFO("ECHO HANDLER END");
|
||||
};
|
||||
|
||||
make_endpoint("ccf.Echo/Echo", HTTP_POST, do_echo, ccf::no_auth_required)
|
||||
.install();
|
||||
}
|
||||
};
|
||||
} // namespace app
|
||||
|
||||
namespace ccfapp
|
||||
{
|
||||
std::unique_ptr<ccf::endpoints::EndpointRegistry> make_user_endpoints(
|
||||
ccfapp::AbstractNodeContext& context)
|
||||
{
|
||||
return std::make_unique<externalexecutor::EndpointRegistry>(context);
|
||||
}
|
||||
} // namespace ccfapp
|
|
@ -0,0 +1,7 @@
|
|||
# Enclave settings:
|
||||
NumHeapPages=131072
|
||||
NumStackPages=1024
|
||||
NumTCS=8
|
||||
ProductID=1
|
||||
SecurityVersion=1
|
||||
# The Debug setting is automatically inserted by sign_app_library in CMake, to build both debuggable and non-debuggable variants
|
Загрузка…
Ссылка в новой задаче