Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ Checks: >
-readability-magic-numbers,

WarningsAsErrors: '*'
HeaderFilterRegex: '(include\/ccf\/|src\/(udp|tcp|tls|tasks|snapshots|service|quic|pal|apps|clients|common|consensus|ds|enclave|endpoints|host|indexing|http)\/).*'
HeaderFilterRegex: '(include\/ccf|src)\/.*'
FormatStyle: 'file'
2 changes: 1 addition & 1 deletion doc/build_apps/crypto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Hashing
.. doxygenfunction:: ccf::crypto::sha256(const std::vector<uint8_t> &data)
:project: CCF

.. doxygenfunction:: ccf::crypto::hmac(MDType, const std::vector<uint8_t>&, const std::vector<uint8_t>&)
.. doxygenfunction:: ccf::crypto::hmac(MDType, const std::span<const uint8_t>&, const std::span<const uint8_t>&)
:project: CCF

.. doxygenClass:: ccf::crypto::HashProvider
Expand Down
4 changes: 2 additions & 2 deletions include/ccf/crypto/hmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace ccf::crypto
*/
HashBytes hmac(
MDType type,
const std::vector<uint8_t>& key,
const std::vector<uint8_t>& data);
const std::span<const uint8_t>& key,
const std::span<const uint8_t>& data);
}
8 changes: 4 additions & 4 deletions src/crypto/hmac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace ccf::crypto
{
HashBytes hmac(
MDType type,
const std::vector<uint8_t>& key,
const std::vector<uint8_t>& data)
const std::span<const uint8_t>& key,
const std::span<const uint8_t>& data)
{
const auto* o_md_type = OpenSSL::get_md_type(type);
HashBytes r(EVP_MD_size(o_md_type));
Expand Down Expand Up @@ -42,8 +42,8 @@ namespace ccf::crypto

HashBytes hmac(
MDType type,
const std::vector<uint8_t>& key,
const std::vector<uint8_t>& data)
const std::span<const uint8_t>& key,
const std::span<const uint8_t>& data)
{
return OpenSSL::hmac(type, key, data);
}
Expand Down
61 changes: 36 additions & 25 deletions src/js/extensions/ccf/kv_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace ccf::js::extensions::kvhelpers
static JSValue C_FUNC_NAME( \
JSContext* ctx, JSValueConst this_val, int, JSValueConst*) \
{ \
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx); \
js::core::Context& jsctx = \
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx)); \
const auto table_name = \
jsctx.to_str(JS_GetPropertyStr(jsctx, this_val, "_map_name")) \
.value_or(""); \
Expand Down Expand Up @@ -66,23 +67,24 @@ namespace ccf::js::extensions::kvhelpers
static JSValue js_kv_map_has(
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
{
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
js::core::Context& jsctx =
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));

if (argc != 1)
{
return JS_ThrowTypeError(
ctx, "Passed %d arguments, but expected 1", argc);
}

size_t key_size;
size_t key_size = 0;
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);

if (!key)
{
return JS_ThrowTypeError(ctx, "Argument must be an ArrayBuffer");
}

auto handle = GetReadOnlyHandle(jsctx, this_val);
auto* handle = GetReadOnlyHandle(jsctx, this_val);
JS_CHECK_HANDLE(handle);

auto has = handle->has({key, key + key_size});
Expand All @@ -94,23 +96,24 @@ namespace ccf::js::extensions::kvhelpers
static JSValue js_kv_map_get(
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
{
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
js::core::Context& jsctx =
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));

if (argc != 1)
{
return JS_ThrowTypeError(
ctx, "Passed %d arguments, but expected 1", argc);
}

size_t key_size;
size_t key_size = 0;
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);

if (!key)
{
return JS_ThrowTypeError(ctx, "Argument must be an ArrayBuffer");
}

auto handle = GetReadOnlyHandle(jsctx, this_val);
auto* handle = GetReadOnlyHandle(jsctx, this_val);
JS_CHECK_HANDLE(handle);

auto val = handle->get({key, key + key_size});
Expand All @@ -131,23 +134,24 @@ namespace ccf::js::extensions::kvhelpers
static JSValue js_kv_get_version_of_previous_write(
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
{
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
js::core::Context& jsctx =
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));

if (argc != 1)
{
return JS_ThrowTypeError(
ctx, "Passed %d arguments, but expected 1", argc);
}

size_t key_size;
size_t key_size = 0;
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);

if (!key)
{
return JS_ThrowTypeError(ctx, "Argument must be an ArrayBuffer");
}

auto handle = GetReadOnlyHandle(jsctx, this_val);
auto* handle = GetReadOnlyHandle(jsctx, this_val);
JS_CHECK_HANDLE(handle);

auto val = handle->get_version_of_previous_write({key, key + key_size});
Expand All @@ -162,11 +166,12 @@ namespace ccf::js::extensions::kvhelpers

template <ROHandleGetter GetReadOnlyHandle>
static JSValue js_kv_map_size_getter(
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst*)
JSContext* ctx, JSValueConst this_val, int /*argc*/, JSValueConst*)
{
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
js::core::Context& jsctx =
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));

auto handle = GetReadOnlyHandle(jsctx, this_val);
auto* handle = GetReadOnlyHandle(jsctx, this_val);
JS_CHECK_HANDLE(handle);

const uint64_t size = handle->size();
Expand All @@ -183,23 +188,24 @@ namespace ccf::js::extensions::kvhelpers
static JSValue js_kv_map_delete(
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
{
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
js::core::Context& jsctx =
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));

if (argc != 1)
{
return JS_ThrowTypeError(
ctx, "Passed %d arguments, but expected 1", argc);
}

size_t key_size;
size_t key_size = 0;
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);

if (!key)
{
return JS_ThrowTypeError(ctx, "Argument must be an ArrayBuffer");
}

auto handle = GetWriteHandle(jsctx, this_val);
auto* handle = GetWriteHandle(jsctx, this_val);
JS_CHECK_HANDLE(handle);

handle->remove({key, key + key_size});
Expand All @@ -211,26 +217,27 @@ namespace ccf::js::extensions::kvhelpers
static JSValue js_kv_map_set(
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
{
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
js::core::Context& jsctx =
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));

if (argc != 2)
{
return JS_ThrowTypeError(
ctx, "Passed %d arguments, but expected 2", argc);
}

size_t key_size;
size_t key_size = 0;
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);

size_t val_size;
size_t val_size = 0;
uint8_t* val = JS_GetArrayBuffer(ctx, &val_size, argv[1]);

if (!key || !val)
{
return JS_ThrowTypeError(ctx, "Arguments must be ArrayBuffers");
}

auto handle = GetWriteHandle(jsctx, this_val);
auto* handle = GetWriteHandle(jsctx, this_val);
JS_CHECK_HANDLE(handle);

handle->put({key, key + key_size}, {val, val + val_size});
Expand All @@ -240,17 +247,18 @@ namespace ccf::js::extensions::kvhelpers

template <RWHandleGetter GetWriteHandle>
static JSValue js_kv_map_clear(
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* /*argv*/)
{
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
js::core::Context& jsctx =
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));

if (argc != 0)
{
return JS_ThrowTypeError(
ctx, "Passed %d arguments, but expected 0", argc);
}

auto handle = GetWriteHandle(jsctx, this_val);
auto* handle = GetWriteHandle(jsctx, this_val);
JS_CHECK_HANDLE(handle);

handle->clear();
Expand All @@ -262,11 +270,14 @@ namespace ccf::js::extensions::kvhelpers
static JSValue js_kv_map_foreach(
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
{
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
js::core::Context& jsctx =
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));

if (argc != 1)
{
return JS_ThrowTypeError(
ctx, "Passed %d arguments, but expected 1", argc);
}

js::core::JSWrappedValue func(ctx, argv[0]);
js::core::JSWrappedValue obj(ctx, this_val);
Expand All @@ -276,7 +287,7 @@ namespace ccf::js::extensions::kvhelpers
return JS_ThrowTypeError(ctx, "Argument must be a function");
}

auto handle = GetReadOnlyHandle(jsctx, this_val);
auto* handle = GetReadOnlyHandle(jsctx, this_val);
JS_CHECK_HANDLE(handle);

bool failed = false;
Expand Down
2 changes: 1 addition & 1 deletion src/js/modules/chained_module_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ccf::js::modules
public:
ChainedModuleLoader(ModuleLoaders&& ml) : sub_loaders(std::move(ml)) {}

virtual std::optional<js::core::JSWrappedValue> get_module(
std::optional<js::core::JSWrappedValue> get_module(
std::string_view module_name, js::core::Context& ctx) override
{
for (auto& sub_loader : sub_loaders)
Expand Down
2 changes: 1 addition & 1 deletion src/js/modules/kv_bytecode_module_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace ccf::js::modules
}
}

virtual std::optional<js::core::JSWrappedValue> get_module(
std::optional<js::core::JSWrappedValue> get_module(
std::string_view module_name, js::core::Context& ctx) override
{
if (!version_ok)
Expand Down
4 changes: 2 additions & 2 deletions src/js/modules/kv_module_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ccf::js::modules
public:
KvModuleLoader(ccf::Modules::ReadOnlyHandle* mh) : modules_handle(mh) {}

virtual std::optional<js::core::JSWrappedValue> get_module(
std::optional<js::core::JSWrappedValue> get_module(
std::string_view module_name, js::core::Context& ctx) override
{
std::string module_name_kv(module_name);
Expand All @@ -38,7 +38,7 @@ namespace ccf::js::modules
return std::nullopt;
}

auto module_name_quickjs = module_name_kv.c_str() + 1;
const auto* module_name_quickjs = module_name_kv.c_str() + 1;
const char* buf = module_str->c_str();
size_t buf_len = module_str->size();
auto parsed_module = ctx.eval(
Expand Down
22 changes: 12 additions & 10 deletions src/js/permissions_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ namespace ccf::js
{
return KVAccessPermissions::READ_WRITE;
}
else if (

if (
execution_context == TxAccess::APP_RO &&
namespace_of_table == ccf::kv::AccessCategory::APPLICATION)
{
return KVAccessPermissions::READ_ONLY;
}
else
{
return KVAccessPermissions::ILLEGAL;
}

return KVAccessPermissions::ILLEGAL;
}

case (ccf::kv::SecurityDomain::PUBLIC):
Expand All @@ -60,10 +59,8 @@ namespace ccf::js
{
return KVAccessPermissions::READ_WRITE;
}
else
{
return KVAccessPermissions::READ_ONLY;
}

return KVAccessPermissions::READ_ONLY;
}

case ccf::kv::AccessCategory::APPLICATION:
Expand Down Expand Up @@ -106,7 +103,7 @@ namespace ccf::js
(permission == KVAccessPermissions::WRITE_ONLY ? "write-only" :
"inaccessible");

char const* exec_context = "unknown";
char const* exec_context = nullptr;
switch (access)
{
case (TxAccess::APP_RW):
Expand All @@ -129,6 +126,11 @@ namespace ccf::js
exec_context = "read-write governance";
break;
}
default:
{
exec_context = "unknown";
break;
}
}

static constexpr char const* access_permissions_explanation_url =
Expand Down
Loading