Skip to content

Commit f6f783b

Browse files
authored
Merge pull request #121 from carlopi/bump_n_patch
Bump duckdb and apply patches
2 parents 7ee09f4 + b0400ec commit f6f783b

File tree

4 files changed

+42
-27
lines changed

4 files changed

+42
-27
lines changed

.github/workflows/MainDistributionPipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
1818
with:
1919
extension_name: httpfs
20-
duckdb_version: main
20+
duckdb_version: v1.4-andium
2121
ci_tools_version: main
2222

2323

@@ -28,6 +28,6 @@ jobs:
2828
secrets: inherit
2929
with:
3030
extension_name: httpfs
31-
duckdb_version: main
31+
duckdb_version: v1.4-andium
3232
ci_tools_version: main
3333
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}

duckdb

Submodule duckdb updated 275 files

extension/httpfs/crypto.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
namespace duckdb {
2525

26-
AESStateSSL::AESStateSSL(EncryptionTypes::CipherType cipher_p, const std::string *key) : EncryptionState(cipher_p), context(EVP_CIPHER_CTX_new()), cipher(cipher_p) {
26+
AESStateSSL::AESStateSSL(EncryptionTypes::CipherType cipher_p, idx_t key_len) : EncryptionState(cipher_p, key_len), context(EVP_CIPHER_CTX_new()) {
2727
if (!(context)) {
28-
throw InternalException("AES GCM failed with initializing context");
28+
throw InternalException("OpenSSL AES failed with initializing context");
2929
}
3030
}
3131

@@ -46,7 +46,7 @@ const EVP_CIPHER *AESStateSSL::GetCipher(idx_t key_len) {
4646
case 32:
4747
return EVP_aes_256_gcm();
4848
default:
49-
throw InternalException("Invalid AES key length");
49+
throw InternalException("Invalid AES key length for GCM");
5050
}
5151
}
5252
case EncryptionTypes::CTR: {
@@ -58,7 +58,7 @@ const EVP_CIPHER *AESStateSSL::GetCipher(idx_t key_len) {
5858
case 32:
5959
return EVP_aes_256_ctr();
6060
default:
61-
throw InternalException("Invalid AES key length");
61+
throw InternalException("Invalid AES key length for CTR");
6262
}
6363
}
6464
case EncryptionTypes::CBC: {
@@ -70,11 +70,11 @@ const EVP_CIPHER *AESStateSSL::GetCipher(idx_t key_len) {
7070
case 32:
7171
return EVP_aes_256_cbc();
7272
default:
73-
throw InternalException("Invalid AES key length");
73+
throw InternalException("Invalid AES key length for CBC");
7474
}
7575
}
7676
default:
77-
throw duckdb::InternalException("Invalid Encryption/Decryption Cipher: %d", static_cast<int>(cipher));
77+
throw InternalException("Invalid Encryption/Decryption Cipher: %d", static_cast<int>(cipher));
7878
}
7979
}
8080

@@ -83,11 +83,21 @@ void AESStateSSL::GenerateRandomData(data_ptr_t data, idx_t len) {
8383
RAND_bytes(data, len);
8484
}
8585

86-
void AESStateSSL::InitializeEncryption(const_data_ptr_t iv, idx_t iv_len, const_data_ptr_t key, idx_t key_len, const_data_ptr_t aad, idx_t aad_len) {
86+
void AESStateSSL::InitializeEncryption(const_data_ptr_t iv, idx_t iv_len, const_data_ptr_t key, idx_t key_len_p, const_data_ptr_t aad, idx_t aad_len) {
8787
mode = EncryptionTypes::ENCRYPT;
8888

89-
if (1 != EVP_EncryptInit_ex(context, GetCipher(key_len), NULL, key, iv)) {
90-
throw InternalException("EncryptInit failed");
89+
if (key_len_p != key_len) {
90+
throw InternalException("Invalid encryption key length, expected %llu, got %llu", key_len, key_len_p);
91+
}
92+
if (1 != EVP_EncryptInit_ex(context, GetCipher(key_len), NULL, NULL, NULL)) {
93+
throw InternalException("EncryptInit failed (attempt 1)");
94+
}
95+
if (1 != EVP_CIPHER_CTX_ctrl(context, EVP_CTRL_GCM_SET_IVLEN, iv_len, NULL)) {
96+
throw InternalException("EVP_CIPHER_CTX_ctrl failed (EVP_CTRL_GCM_SET_IVLEN)");
97+
}
98+
99+
if (1 != EVP_EncryptInit_ex(context, NULL, NULL, key, iv)) {
100+
throw InternalException("EncryptInit failed (attempt 2)");
91101
}
92102

93103
int len;
@@ -98,13 +108,23 @@ void AESStateSSL::InitializeEncryption(const_data_ptr_t iv, idx_t iv_len, const_
98108
}
99109
}
100110

101-
void AESStateSSL::InitializeDecryption(const_data_ptr_t iv, idx_t iv_len, const_data_ptr_t key, idx_t key_len, const_data_ptr_t aad, idx_t aad_len) {
111+
void AESStateSSL::InitializeDecryption(const_data_ptr_t iv, idx_t iv_len, const_data_ptr_t key, idx_t key_len_p, const_data_ptr_t aad, idx_t aad_len) {
102112
mode = EncryptionTypes::DECRYPT;
103-
104-
if (1 != EVP_DecryptInit_ex(context, GetCipher(key_len), NULL, key, iv)) {
105-
throw InternalException("DecryptInit failed");
113+
if (key_len_p != key_len) {
114+
throw InternalException("Invalid encryption key length, expected %llu, got %llu", key_len, key_len_p);
115+
}
116+
if (1 != EVP_DecryptInit_ex(context, GetCipher(key_len), NULL, NULL, NULL)) {
117+
throw InternalException("EVP_DecryptInit_ex failed to set cipher");
118+
}
119+
// we use a bigger IV for GCM
120+
if (cipher == EncryptionTypes::GCM) {
121+
if (1 != EVP_CIPHER_CTX_ctrl(context, EVP_CTRL_GCM_SET_IVLEN, iv_len, NULL)) {
122+
throw InternalException("EVP_CIPHER_CTX_ctrl failed to set GCM iv len");
123+
}
124+
}
125+
if (1 != EVP_DecryptInit_ex(context, NULL, NULL, key, iv)) {
126+
throw InternalException("EVP_DecryptInit_ex failed to set iv/key");
106127
}
107-
108128
int len;
109129
if (aad_len > 0){
110130
if (!EVP_DecryptUpdate(context, NULL, &len, aad, aad_len)) {
@@ -114,7 +134,6 @@ void AESStateSSL::InitializeDecryption(const_data_ptr_t iv, idx_t iv_len, const_
114134
}
115135

116136
size_t AESStateSSL::Process(const_data_ptr_t in, idx_t in_len, data_ptr_t out, idx_t out_len) {
117-
118137
switch (mode) {
119138
case EncryptionTypes::ENCRYPT:
120139
if (1 != EVP_EncryptUpdate(context, data_ptr_cast(out), reinterpret_cast<int *>(&out_len),
@@ -135,7 +154,6 @@ size_t AESStateSSL::Process(const_data_ptr_t in, idx_t in_len, data_ptr_t out, i
135154
if (out_len != in_len) {
136155
throw InternalException("AES GCM failed, in- and output lengths differ");
137156
}
138-
139157
return out_len;
140158
}
141159

@@ -189,15 +207,13 @@ size_t AESStateSSL::Finalize(data_ptr_t out, idx_t out_len, data_ptr_t tag, idx_
189207
if (1 != EVP_EncryptFinal_ex(context, data_ptr_cast(out) + out_len, reinterpret_cast<int *>(&out_len))) {
190208
throw InternalException("EncryptFinal failed");
191209
}
192-
193210
return text_len += out_len;
194211
}
195212

196213
case EncryptionTypes::DECRYPT: {
197214
// EVP_DecryptFinal() will return an error code if final block is not correctly formatted.
198215
int ret = EVP_DecryptFinal_ex(context, data_ptr_cast(out) + out_len, reinterpret_cast<int *>(&out_len));
199216
text_len += out_len;
200-
201217
if (ret > 0) {
202218
// success
203219
return text_len;

extension/httpfs/include/crypto.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ void hmac256(std::string message, hash_bytes secret, hash_bytes &out);
2222

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

25-
class DUCKDB_EXTENSION_API AESStateSSL : public duckdb::EncryptionState {
25+
class DUCKDB_EXTENSION_API AESStateSSL : public EncryptionState {
2626

2727
public:
28-
explicit AESStateSSL(duckdb::EncryptionTypes::CipherType cipher_p, const std::string *key = nullptr);
28+
explicit AESStateSSL(EncryptionTypes::CipherType cipher_p, idx_t key_len_p);
2929
~AESStateSSL() override;
3030

3131
public:
@@ -40,8 +40,7 @@ class DUCKDB_EXTENSION_API AESStateSSL : public duckdb::EncryptionState {
4040

4141
private:
4242
EVP_CIPHER_CTX *context;
43-
duckdb::EncryptionTypes::Mode mode;
44-
duckdb::EncryptionTypes::CipherType cipher;
43+
EncryptionTypes::Mode mode;
4544
};
4645

4746
} // namespace duckdb
@@ -53,8 +52,8 @@ class DUCKDB_EXTENSION_API AESStateSSLFactory : public duckdb::EncryptionUtil {
5352
explicit AESStateSSLFactory() {
5453
}
5554

56-
duckdb::shared_ptr<duckdb::EncryptionState> CreateEncryptionState(duckdb::EncryptionTypes::CipherType cipher_p, duckdb::const_data_ptr_t key = nullptr, duckdb::idx_t key_len = 0) const override {
57-
return duckdb::make_shared_ptr<duckdb::AESStateSSL>(cipher_p);
55+
duckdb::shared_ptr<duckdb::EncryptionState> CreateEncryptionState(duckdb::EncryptionTypes::CipherType cipher_p, duckdb::idx_t key_len_p) const override {
56+
return duckdb::make_shared_ptr<duckdb::AESStateSSL>(cipher_p, key_len_p);
5857
}
5958

6059
~AESStateSSLFactory() override {

0 commit comments

Comments
 (0)