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: 0 additions & 2 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
extension_name: httpfs
duckdb_version: v1.3-ossivalis
ci_tools_version: main
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads'


duckdb-stable-deploy:
Expand All @@ -32,4 +31,3 @@ jobs:
duckdb_version: v1.3-ossivalis
ci_tools_version: main
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads'
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ add_extension_definitions()
include_directories(extension/httpfs/include
${DUCKDB_MODULE_BASE_DIR}/third_party/httplib)

if (NOT EMSCRIPTEN)
set(EXTRA_SOURCES extension/httpfs/crypto.cpp extension/httpfs/httpfs_client.cpp)
add_definitions(-DOVERRIDE_ENCRYPTION_UTILS=1)
else()
set(EXTRA_SOURCES extension/httpfs/httpfs_client_wasm.cpp)
endif()

build_static_extension(
httpfs
extension/httpfs/hffs.cpp
extension/httpfs/s3fs.cpp
extension/httpfs/httpfs.cpp
extension/httpfs/httpfs_client.cpp
extension/httpfs/http_state.cpp
extension/httpfs/crypto.cpp
extension/httpfs/hash_functions.cpp
extension/httpfs/create_secret_functions.cpp
extension/httpfs/httpfs_extension.cpp)
extension/httpfs/httpfs_extension.cpp
${EXTRA_SOURCES} )

set(PARAMETERS "-warnings")
build_loadable_extension(
Expand All @@ -27,11 +35,12 @@ build_loadable_extension(
extension/httpfs/hffs.cpp
extension/httpfs/s3fs.cpp
extension/httpfs/httpfs.cpp
extension/httpfs/httpfs_client.cpp
extension/httpfs/http_state.cpp
extension/httpfs/crypto.cpp
extension/httpfs/hash_functions.cpp
extension/httpfs/create_secret_functions.cpp
extension/httpfs/httpfs_extension.cpp)
extension/httpfs/httpfs_extension.cpp
${EXTRA_SOURCES} )

if(MINGW)
set(OPENSSL_USE_STATIC_LIBS TRUE)
Expand Down
23 changes: 1 addition & 22 deletions extension/httpfs/crypto.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "crypto.hpp"
#include "hash_functions.hpp"
#include "mbedtls_wrapper.hpp"
#include <iostream>
#include "duckdb/common/common.hpp"
Expand All @@ -9,28 +10,6 @@

namespace duckdb {

void sha256(const char *in, size_t in_len, hash_bytes &out) {
duckdb_mbedtls::MbedTlsWrapper::ComputeSha256Hash(in, in_len, (char *)out);
}

void hmac256(const std::string &message, const char *secret, size_t secret_len, hash_bytes &out) {
duckdb_mbedtls::MbedTlsWrapper::Hmac256(secret, secret_len, message.data(), message.size(), (char *)out);
}

void hmac256(std::string message, hash_bytes secret, hash_bytes &out) {
hmac256(message, (char *)secret, sizeof(hash_bytes), out);
}

void hex256(hash_bytes &in, hash_str &out) {
const char *hex = "0123456789abcdef";
unsigned char *pin = in;
unsigned char *pout = out;
for (; pin < in + sizeof(in); pout += 2, pin++) {
pout[0] = hex[(*pin >> 4) & 0xF];
pout[1] = hex[*pin & 0xF];
}
}

AESStateSSL::AESStateSSL(const std::string *key) : context(EVP_CIPHER_CTX_new()) {
if (!(context)) {
throw InternalException("AES GCM failed with initializing context");
Expand Down
28 changes: 28 additions & 0 deletions extension/httpfs/hash_functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "mbedtls_wrapper.hpp"
#include "hash_functions.hpp"

namespace duckdb {

void sha256(const char *in, size_t in_len, hash_bytes &out) {
duckdb_mbedtls::MbedTlsWrapper::ComputeSha256Hash(in, in_len, (char *)out);
}

void hmac256(const std::string &message, const char *secret, size_t secret_len, hash_bytes &out) {
duckdb_mbedtls::MbedTlsWrapper::Hmac256(secret, secret_len, message.data(), message.size(), (char *)out);
}

void hmac256(std::string message, hash_bytes secret, hash_bytes &out) {
hmac256(message, (char *)secret, sizeof(hash_bytes), out);
}

void hex256(hash_bytes &in, hash_str &out) {
const char *hex = "0123456789abcdef";
unsigned char *pin = in;
unsigned char *pout = out;
for (; pin < in + sizeof(in); pout += 2, pin++) {
pout[0] = hex[(*pin >> 4) & 0xF];
pout[1] = hex[*pin & 0xF];
}
}

} // namespace duckdb
5 changes: 5 additions & 0 deletions extension/httpfs/httpfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,9 @@ void HTTPFileHandle::StoreClient(unique_ptr<HTTPClient> client) {
HTTPFileHandle::~HTTPFileHandle() {
DUCKDB_LOG_FILE_SYSTEM_CLOSE((*this));
};

string HTTPFSUtil::GetName() const {
return "HTTPFS";
}

} // namespace duckdb
4 changes: 0 additions & 4 deletions extension/httpfs/httpfs_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,4 @@ unordered_map<string, string> HTTPFSUtil::ParseGetParameters(const string &text)
return result;
}

string HTTPFSUtil::GetName() const {
return "HTTPFS";
}

} // namespace duckdb
16 changes: 16 additions & 0 deletions extension/httpfs/httpfs_client_wasm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "httpfs_client.hpp"
#include "http_state.hpp"

namespace duckdb {

unique_ptr<HTTPClient> HTTPFSUtil::InitializeClient(HTTPParams &http_params, const string &proto_host_port) {
throw InternalException("HTTPFSUtil::InitializeClient is not expected to be called");
}

unordered_map<string, string> HTTPFSUtil::ParseGetParameters(const string &text) {
unordered_map<string, string> result;
//TODO: HTTPFSUtil::ParseGetParameters is currently not implemented
return result;
}

} // namespace duckdb
11 changes: 10 additions & 1 deletion extension/httpfs/httpfs_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "duckdb.hpp"
#include "s3fs.hpp"
#include "hffs.hpp"
#ifdef OVERRIDE_ENCRYPTION_UTILS
#include "crypto.hpp"
#endif // OVERRIDE_ENCRYPTION_UTILS

namespace duckdb {

Expand Down Expand Up @@ -61,16 +63,23 @@ static void LoadInternal(DatabaseInstance &instance) {
// HuggingFace options
config.AddExtensionOption("hf_max_per_page", "Debug option to limit number of items returned in list requests",
LogicalType::UBIGINT, Value::UBIGINT(0));
config.http_util = make_shared_ptr<HTTPFSUtil>();

if (config.http_util && config.http_util->GetName() == "WasmHTTPUtils") {
// Already handled, do not override
} else {
config.http_util = make_shared_ptr<HTTPFSUtil>();
}

auto provider = make_uniq<AWSEnvironmentCredentialsProvider>(config);
provider->SetAll();

CreateS3SecretFunctions::Register(instance);
CreateBearerTokenFunctions::Register(instance);

#ifdef OVERRIDE_ENCRYPTION_UTILS
// set pointer to OpenSSL encryption state
config.encryption_util = make_shared_ptr<AESStateSSLFactory>();
#endif // OVERRIDE_ENCRYPTION_UTILS
}
void HttpfsExtension::Load(DuckDB &db) {
LoadInternal(*db.instance);
Expand Down
18 changes: 18 additions & 0 deletions extension/httpfs/include/hash_functions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "duckdb/common/helper.hpp"

namespace duckdb {

typedef unsigned char hash_bytes[32];
typedef unsigned char hash_str[64];

void sha256(const char *in, size_t in_len, hash_bytes &out);

void hmac256(const std::string &message, const char *secret, size_t secret_len, hash_bytes &out);

void hmac256(std::string message, hash_bytes secret, hash_bytes &out);

void hex256(hash_bytes &in, hash_str &out);

} // namespace duckdb
1 change: 1 addition & 0 deletions extension_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ duckdb_extension_load(httpfs
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/extension/httpfs/include
${LOAD_HTTPFS_TESTS}
LINKED_LIBS "../../third_party/mbedtls/libduckdb_mbedtls.a"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, yes, I have not found a clean way to clean this up.

It should picked up from CMake, but that requires some changes in duckdb/duckdb that are not there (and unsure if they can land today).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can fix this up, question is: it's a blocker?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what problems it causes but it seems hacky - maybe it's fine. I'll leave it up to you

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does smell badly, you are right, now triggered to find the actual fix.

)
Loading