Skip to content

Commit

Permalink
delete src/common/encryption src/common/base/stringunorderedmap (veso…
Browse files Browse the repository at this point in the history
…ft-inc#600)

* delete src/common/encryption src/common/base/stringunorderedmap (vesoft-inc#3867)

* delete src/common/encryption

* encryption format code

* delete base64.h line

* base64decode

* base64decode

* base64decode

* base64decode

* revert cmakefiles

* revert storage cmakelist.txt

* revert tools cmakelists.txt

* revert simple kv verify

* revert CMakeLists.txt

Co-authored-by: yuehua.jia <3423893+jiayuehua@users.noreply.github.com>
  • Loading branch information
nebula-bots and jiayuehua authored Feb 17, 2022
1 parent 1e8ba56 commit 86ec1f3
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 264 deletions.
2 changes: 1 addition & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ nebula_add_subdirectory(network)
nebula_add_subdirectory(thrift)
nebula_add_subdirectory(fs)
nebula_add_subdirectory(concurrent)
nebula_add_subdirectory(encryption)
nebula_add_subdirectory(thread)
nebula_add_subdirectory(process)
nebula_add_subdirectory(hdfs)
nebula_add_subdirectory(http)
nebula_add_subdirectory(stats)
nebula_add_subdirectory(charset)
nebula_add_subdirectory(algorithm)
nebula_add_subdirectory(encryption)
nebula_add_subdirectory(datatypes)
nebula_add_subdirectory(conf)
nebula_add_subdirectory(meta)
Expand Down
133 changes: 0 additions & 133 deletions src/common/base/StringUnorderedMap.h

This file was deleted.

25 changes: 0 additions & 25 deletions src/common/encryption/Base64.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions src/common/encryption/Base64.h

This file was deleted.

2 changes: 0 additions & 2 deletions src/common/encryption/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

nebula_add_library(
encryption_obj OBJECT
MD5Utils.cpp
Base64.cpp
License.cpp
)
31 changes: 22 additions & 9 deletions src/common/encryption/License.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
#include "common/encryption/License.h"

#include <folly/json.h>
#include <proxygen/lib/utils/Base64.h>
#include <proxygen/lib/utils/CryptUtil.h>

#include <bitset>
#include <chrono>
#include <csignal>
#include <iomanip>
#include <string>
#include <string_view>

#include "common/base/Status.h"
#include "common/base/StatusOr.h"
#include "common/encryption/Base64.h"
#include "common/time/TimeUtils.h"

namespace nebula {
Expand All @@ -22,11 +25,11 @@ namespace encryption {
// AES key/block size
const unsigned int kKeySize = 32;
const unsigned int kBlockSize = 16;
const char kAesKeyBase64[] = "241IYjd0+MKVhiXc0PWFetV7RhmsjTCJpZslOCPC5n8=";
const char kAesIvBase64[] = "rjJJOkaaueQmwFTVtzBAxw==";
constexpr std::string_view kAesKeyBase64 = "241IYjd0+MKVhiXc0PWFetV7RhmsjTCJpZslOCPC5n8=";
constexpr std::string_view kAesIvBase64 = "rjJJOkaaueQmwFTVtzBAxw==";

// RSA public key
const char kPubKeyBase64[] =
constexpr std::string_view kPubKeyBase64 =
"LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQTNGR0NvSW44VHZvYVNEYmx4RmJvL0l1VitxTF"
"l6U0IwU2QrdGkvYzJZWm9SWkJ3c0ZuTTkKNUhWYXN6UlJ5cmZw"
"ZlFTdFdMdThUcFlkc1l4ZkxUbmo1eWlYenlRMXluZzNnbytsZmozMXlidFNKVHNVU2pmRAo2RVNTRHlET3hvT0tRUlp1Wm"
Expand Down Expand Up @@ -262,13 +265,21 @@ Status License::checkContent(const std::string& licensePath) {
// Extract AES cipher and RSA signature from licenseKey
const size_t licenseKeySize = licenseKey.size();
std::string aesCipherBase64 = licenseKey.substr(0, licenseKeySize - kSigSize);
auto aesCipherText = Base64::decode(aesCipherBase64);
auto aesCipherBase64paddingSz =
aesCipherBase64.size() - (aesCipherBase64.find_last_not_of('=') + 1);
auto aesCipherText = proxygen::Base64::decode(aesCipherBase64, aesCipherBase64paddingSz);

std::string rsaSigBase64 = licenseKey.substr(licenseKeySize - kSigSize);
auto rsaSig = Base64::decode(rsaSigBase64);
auto rsaSigBase64paddingSz = rsaSigBase64.size() - (rsaSigBase64.find_last_not_of('=') + 1);
auto rsaSig = proxygen::Base64::decode(rsaSigBase64, rsaSigBase64paddingSz);

// Calculate message digest of AES256 encrypted license content
const std::string aesKey = Base64::decode(std::string(kAesKeyBase64));
const std::string aesIv = Base64::decode(std::string(kAesIvBase64));
auto kAesKeyBase64paddingSz = kAesKeyBase64.size() - (kAesKeyBase64.find_last_not_of('=') + 1);
const std::string aesKey =
proxygen::Base64::decode(std::string(kAesKeyBase64), kAesKeyBase64paddingSz);
auto kAesIvBase64paddingSz = kAesIvBase64.size() - (kAesIvBase64.find_last_not_of('=') + 1);
const std::string aesIv =
proxygen::Base64::decode(std::string(kAesIvBase64), kAesIvBase64paddingSz);
std::string encryptedBody = "";
NG_RETURN_IF_ERROR(aes256Encrypt(reinterpret_cast<const unsigned char*>(aesKey.c_str()),
reinterpret_cast<const unsigned char*>(aesIv.c_str()),
Expand All @@ -278,7 +289,9 @@ Status License::checkContent(const std::string& licensePath) {
NG_RETURN_IF_ERROR(computeSha256Digest(encryptedBody, digestBuf));

// Validate rsa signature
const std::string pubKey = Base64::decode(kPubKeyBase64);
auto kPubKeyBase64paddingSz = kPubKeyBase64.size() - (kPubKeyBase64.find_last_not_of('=') + 1);
const std::string pubKey =
proxygen::Base64::decode(std::string(kPubKeyBase64), kPubKeyBase64paddingSz);
NG_RETURN_IF_ERROR(VerifyRsaSign(const_cast<char*>(rsaSig.c_str()), 256, pubKey, digestBuf));

// Decrypt license content
Expand Down
1 change: 0 additions & 1 deletion src/common/encryption/License.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "common/base/Base.h"
#include "common/base/Status.h"
#include "common/encryption/Base64.h"
#include "common/fs/FileUtils.h"

namespace nebula {
Expand Down
16 changes: 0 additions & 16 deletions src/common/encryption/MD5Utils.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions src/common/encryption/MD5Utils.h

This file was deleted.

1 change: 0 additions & 1 deletion src/common/expression/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
set(expression_test_common_libs
$<TARGET_OBJECTS:parser_obj>
$<TARGET_OBJECTS:expression_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:stats_obj>
Expand Down
12 changes: 6 additions & 6 deletions src/common/plugin/fulltext/FTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#ifndef COMMON_PLUGIN_FULLTEXT_UTILS_H_
#define COMMON_PLUGIN_FULLTEXT_UTILS_H_

#include <proxygen/lib/utils/CryptUtil.h>

#include <boost/algorithm/string/replace.hpp>
#include <iomanip>

#include "common/base/Base.h"
#include "common/base/CommonMacro.h"
#include "common/datatypes/HostAddr.h"
#include "common/encryption/Base64.h"
#include "common/encryption/MD5Utils.h"

#define CURL "/usr/bin/curl"
#define XPUT " -XPUT"
Expand Down Expand Up @@ -141,7 +141,7 @@ struct DocIDTraits {

static std::string column(const std::string& col) {
// normalized column name is 32 bytes
return encryption::MD5Utils::md5Encode(col);
return proxygen::md5Encode(folly::StringPiece(col));
}

static std::string val(const std::string& v) {
Expand All @@ -158,9 +158,9 @@ struct DocIDTraits {
// docId structure : partId(10bytes) + schemaId(10Bytes) +
// columnName(32bytes) + encoded_val(max 344bytes)
// the max length of docId is 512 bytes, still have about 100 bytes reserved
auto encoded = encryption::Base64::encode((item.val.size() > MAX_INDEX_TYPE_LENGTH)
? item.val.substr(0, MAX_INDEX_TYPE_LENGTH)
: item.val);
auto encoded = proxygen::base64Encode(folly::StringPiece(
(item.val.size() > MAX_INDEX_TYPE_LENGTH) ? item.val.substr(0, MAX_INDEX_TYPE_LENGTH)
: item.val));
std::replace(encoded.begin(), encoded.end(), '/', '_');
std::stringstream ss;
ss << id(item.part) << column(item.column) << encoded;
Expand Down
1 change: 0 additions & 1 deletion src/common/plugin/fulltext/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ nebula_add_test(
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:ft_es_storage_adapter_obj>
$<TARGET_OBJECTS:ft_es_graph_adapter_obj>
Expand Down
1 change: 0 additions & 1 deletion src/common/plugin/fulltext/test/FulltextPluginTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <gtest/gtest.h>

#include "common/base/Base.h"
#include "common/encryption/MD5Utils.h"
#include "common/network/NetworkUtils.h"
#include "common/plugin/fulltext/FTUtils.h"
#include "common/plugin/fulltext/elasticsearch/ESGraphAdapter.h"
Expand Down
1 change: 0 additions & 1 deletion src/common/utils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ nebula_add_test(
$<TARGET_OBJECTS:datatypes_obj>
$<TARGET_OBJECTS:wkt_wkb_io_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:encryption_obj>
$<TARGET_OBJECTS:ft_es_storage_adapter_obj>
LIBRARIES
${THRIFT_LIBRARIES}
Expand Down
Loading

0 comments on commit 86ec1f3

Please sign in to comment.