From 3c9f2ae6695ffebe41e39b6bf6544077698f1ced Mon Sep 17 00:00:00 2001 From: lide-reed Date: Tue, 12 Jun 2018 17:26:21 +0800 Subject: [PATCH] remove aes encrypt and decrypt which used GPL --- be/src/common/daemon.cpp | 2 + be/src/exprs/CMakeLists.txt | 1 + be/src/exprs/encryption_functions.cpp | 115 +++++++++++++++++++++++ be/src/exprs/encryption_functions.h | 49 ++++++++++ gensrc/script/palo_builtins_functions.py | 6 -- 5 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 be/src/exprs/encryption_functions.cpp create mode 100644 be/src/exprs/encryption_functions.h diff --git a/be/src/common/daemon.cpp b/be/src/common/daemon.cpp index 0ef622e84e..82f5b8e105 100644 --- a/be/src/common/daemon.cpp +++ b/be/src/common/daemon.cpp @@ -44,6 +44,7 @@ #include "exprs/string_functions.h" #include "exprs/cast_functions.h" #include "exprs/math_functions.h" +#include "exprs/encryption_functions.h" #include "exprs/timestamp_functions.h" #include "exprs/decimal_operators.h" #include "exprs/utility_functions.h" @@ -153,6 +154,7 @@ void init_daemon(int argc, char** argv) { CastFunctions::init(); InPredicate::init(); MathFunctions::init(); + EncryptionFunctions::init(); TimestampFunctions::init(); DecimalOperators::init(); UtilityFunctions::init(); diff --git a/be/src/exprs/CMakeLists.txt b/be/src/exprs/CMakeLists.txt index 3d4e42a914..2670e332d5 100644 --- a/be/src/exprs/CMakeLists.txt +++ b/be/src/exprs/CMakeLists.txt @@ -26,6 +26,7 @@ set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/src/exprs") add_library(Exprs base64.cpp + encryption_functions.cpp aggregate_functions.cpp agg_fn_evaluator.cpp anyval_util.cpp diff --git a/be/src/exprs/encryption_functions.cpp b/be/src/exprs/encryption_functions.cpp new file mode 100644 index 0000000000..67d75e5dce --- /dev/null +++ b/be/src/exprs/encryption_functions.cpp @@ -0,0 +1,115 @@ +// Modifications copyright (C) 2017, Baidu.com, Inc. +// Copyright 2017 The Apache Software Foundation + +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "exprs/encryption_functions.h" + +#include +#include "exprs/anyval_util.h" +#include "exprs/expr.h" +#include "util/debug_util.h" +#include "runtime/tuple_row.h" +#include "exprs/base64.h" +#include +#include "runtime/string_value.h" + +namespace palo { +void EncryptionFunctions::init() { +} + +StringVal EncryptionFunctions::from_base64(FunctionContext* ctx, const StringVal &src) { + if (src.len == 0) { + return StringVal::null(); + } + + int cipher_len = src.len; + boost::scoped_array p; + p.reset(new char[cipher_len]); + + int ret_code = base64_decode2((const char *)src.ptr, src.len, p.get()); + if (ret_code < 0) { + return StringVal::null(); + } + return AnyValUtil::from_buffer_temp(ctx, p.get(), ret_code); +} + +StringVal EncryptionFunctions::to_base64(FunctionContext* ctx, const StringVal &src) { + if (src.len == 0) { + return StringVal::null(); + } + + int cipher_len = src.len * 4 / 3 + 1; + boost::scoped_array p; + p.reset(new char[cipher_len]); + + int ret_code = base64_encode2((unsigned char *)src.ptr, src.len, (unsigned char *)p.get()); + if (ret_code < 0) { + return StringVal::null(); + } + return AnyValUtil::from_buffer_temp(ctx, p.get(), ret_code); +} + +StringVal EncryptionFunctions::md5sum( + FunctionContext* ctx, int num_args, const StringVal* args) { + MD5_CTX md5_ctx; + MD5_Init(&md5_ctx); + for (int i = 0; i < num_args; ++i) { + const StringVal& arg = args[i]; + if (arg.is_null) { + continue; + } + MD5_Update(&md5_ctx, arg.ptr, arg.len); + } + unsigned char buf[MD5_DIGEST_LENGTH]; + MD5_Final(buf, &md5_ctx); + unsigned char hex_buf[2 * MD5_DIGEST_LENGTH]; + + static char dig_vec_lower[] = "0123456789abcdef"; + unsigned char* to = hex_buf; + for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) { + *to++= dig_vec_lower[buf[i] >> 4]; + *to++= dig_vec_lower[buf[i] & 0x0F]; + } + + return AnyValUtil::from_buffer_temp(ctx, (char*)hex_buf, 2 * MD5_DIGEST_LENGTH); +} + +StringVal EncryptionFunctions::md5(FunctionContext* ctx, const StringVal& src) { + if (src.is_null) { + return StringVal::null(); + } + MD5_CTX md5_ctx; + MD5_Init(&md5_ctx); + MD5_Update(&md5_ctx, src.ptr, src.len); + + unsigned char buf[MD5_DIGEST_LENGTH]; + MD5_Final(buf, &md5_ctx); + unsigned char hex_buf[2 * MD5_DIGEST_LENGTH]; + + static char dig_vec_lower[] = "0123456789abcdef"; + unsigned char* to = hex_buf; + for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) { + *to++= dig_vec_lower[buf[i] >> 4]; + *to++= dig_vec_lower[buf[i] & 0x0F]; + } + + return AnyValUtil::from_buffer_temp(ctx, (char*)hex_buf, 2 * MD5_DIGEST_LENGTH); +} + +} diff --git a/be/src/exprs/encryption_functions.h b/be/src/exprs/encryption_functions.h new file mode 100644 index 0000000000..bb57e7b32c --- /dev/null +++ b/be/src/exprs/encryption_functions.h @@ -0,0 +1,49 @@ +// Modifications copyright (C) 2017, Baidu.com, Inc. +// Copyright 2017 The Apache Software Foundation + +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef BDG_PALO_BE_SRC_QUERY_EXPRS_ENCRYPTION_FUNCTIONS_H +#define BDG_PALO_BE_SRC_QUERY_EXPRS_ENCRYPTION_FUNCTIONS_H + +#include +#include "udf/udf.h" +#include "udf/udf_internal.h" + +namespace palo { + +class Expr; +struct ExprValue; +class TupleRow; + +class EncryptionFunctions { +public: + static void init(); + static palo_udf::StringVal from_base64(palo_udf::FunctionContext* context, + const palo_udf::StringVal& val1); + static palo_udf::StringVal to_base64(palo_udf::FunctionContext* context, + const palo_udf::StringVal& val1); + static palo_udf::StringVal md5sum(palo_udf::FunctionContext* ctx, + int num_args, const palo_udf::StringVal* args); + static palo_udf::StringVal md5(palo_udf::FunctionContext* ctx, + const palo_udf::StringVal& src); +}; + +} + +#endif diff --git a/gensrc/script/palo_builtins_functions.py b/gensrc/script/palo_builtins_functions.py index bd37d10e48..dd421c9de9 100644 --- a/gensrc/script/palo_builtins_functions.py +++ b/gensrc/script/palo_builtins_functions.py @@ -549,12 +549,6 @@ visible_functions = [ '_ZN4palo16HllHashFunctions8hll_hashEPN8palo_udf15FunctionContextERKNS1_9StringValE'], # aes and base64 function - [['aes_encrypt'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], - '_ZN4palo19EncryptionFunctions11aes_encryptEPN8palo_udf' - '15FunctionContextERKNS1_9StringValES6_'], - [['aes_decrypt'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], - '_ZN4palo19EncryptionFunctions11aes_decryptEPN8palo_udf' - '15FunctionContextERKNS1_9StringValES6_'], [['from_base64'], 'VARCHAR', ['VARCHAR'], '_ZN4palo19EncryptionFunctions11from_base64EPN8palo_udf' '15FunctionContextERKNS1_9StringValE'],