forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add encryption * add doc * add doc * fix bug
- Loading branch information
1 parent
11ce2f4
commit ab49b41
Showing
32 changed files
with
1,865 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed 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. | ||
|
||
SET(OPENSSL_URL_PREFIX "https://bj.bcebos.com/paddlex/tools") | ||
IF(CMAKE_SYSTEM_NAME MATCHES "Windows") | ||
set(OPENSSL_FILENAME "windows_openssl-1.1.0k") | ||
set(COMPRESSED_SUFFIX ".zip") | ||
add_definitions(-DWIN32) | ||
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Linux") | ||
set(OPENSSL_FILENAME "openssl-1.1.0k") | ||
set(COMPRESSED_SUFFIX ".tar.gz") | ||
add_definitions(-DLINUX) | ||
ENDIF() | ||
set(OPENSSL_URL ${OPENSSL_URL_PREFIX}/${OPENSSL_FILENAME}${COMPRESSED_SUFFIX}) | ||
if(THIRD_PARTY_PATH) | ||
SET(OPENSSL_INSTALL_DIR ${THIRD_PARTY_PATH}) | ||
SET(OPENSSL_ROOT_DIR ${THIRD_PARTY_PATH}/openssl-1.1.0k/install-${CMAKE_SYSTEM_PROCESSOR}) | ||
else() | ||
SET(OPENSSL_INSTALL_DIR ${FASTDEPLOY_INSTALL_DIR}/installed_fastdeploy/cmake) | ||
SET(OPENSSL_ROOT_DIR ${FASTDEPLOY_INSTALL_DIR}/installed_fastdeploy/cmake/openssl-1.1.0k/install-${CMAKE_SYSTEM_PROCESSOR}) | ||
endif() | ||
download_and_decompress(${OPENSSL_URL} ${CMAKE_CURRENT_BINARY_DIR}/${OPENSSL_FILENAME}${COMPRESSED_SUFFIX} ${OPENSSL_INSTALL_DIR}) | ||
SET(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include" CACHE PATH "openssl include directory." FORCE) | ||
include_directories(${OPENSSL_INCLUDE_DIR}) | ||
IF(CMAKE_SYSTEM_NAME MATCHES "Windows") | ||
set(OPENSSL_LIBRARIES | ||
"${OPENSSL_ROOT_DIR}/lib/libssl_static.lib" | ||
"${OPENSSL_ROOT_DIR}/lib/libcrypto_static.lib" | ||
${GFLAGS_LIBRARIES} | ||
shlwapi | ||
CACHE FILEPATH "OPENSSL_LIBRARIES" FORCE) | ||
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux") | ||
set(OPENSSL_LIBRARIES | ||
"${OPENSSL_ROOT_DIR}/lib/libssl.a" | ||
"${OPENSSL_ROOT_DIR}/lib/libcrypto.a" | ||
${GFLAGS_LIBRARIES} | ||
-ldl -lpthread | ||
CACHE FILEPATH "OPENSSL_LIBRARIES" FORCE) | ||
ENDIF() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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. | ||
#pragma once | ||
|
||
#include "fastdeploy/core/config.h" | ||
#ifdef ENABLE_ENCRYPTION | ||
#include "fastdeploy/encryption/include/decrypt.h" | ||
#include "fastdeploy/encryption/include/encrypt.h" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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 "fastdeploy/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
|
||
void BindEncryption(pybind11::module& m) { | ||
m.def("encrypt", [](const std::string& input, const std::string& key) { | ||
return Encrypt(input, key); | ||
}); | ||
m.def("decrypt", [](const std::string& cipher, const std::string& key) { | ||
return Decrypt(cipher, key); | ||
}); | ||
m.def("generate_key", []() { | ||
return GenerateRandomKey(); | ||
}); | ||
} | ||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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. | ||
#pragma once | ||
|
||
#include <stdio.h> | ||
#include <string> | ||
|
||
#include "fastdeploy/utils/utils.h" | ||
|
||
#ifndef PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_DECRYPT_H | ||
#define PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_DECRYPT_H | ||
namespace fastdeploy { | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** \brief check stream is encrypted or not | ||
* | ||
* \param[in] cipher_stream The encrypted stream | ||
* \return 0 if stream is encrypted. | ||
*/ | ||
FASTDEPLOY_DECL int CheckStreamEncrypted(std::istream& cipher_stream); | ||
|
||
|
||
/** \brief decrypt an encrypted stream | ||
* | ||
* \param[in] cipher_stream The encrypted stream | ||
* \param[in] plain_stream The decrypted stream | ||
* \param[in] key_base64 The key for decryption | ||
* \return 0 if decrypt success. | ||
*/ | ||
FASTDEPLOY_DECL int DecryptStream(std::istream& cipher_stream, | ||
std::ostream& plain_stream, | ||
const std::string& key_base64); | ||
|
||
|
||
/** \brief decrypt an encrypted string | ||
* | ||
* \param[in] cipher The encrypted string | ||
* \param[in] key The key for decryption | ||
* \return The decrypted string | ||
*/ | ||
FASTDEPLOY_DECL std::string Decrypt(const std::string& cipher, | ||
const std::string& key); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
} // namespace fastdeploy | ||
#endif // PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_DECRYPT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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. | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
#include "fastdeploy/utils/utils.h" | ||
|
||
#ifndef PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H | ||
#define PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H | ||
namespace fastdeploy { | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** \brief generate a random key(base64-32bytes) for an encrypted model | ||
* | ||
* \return std::string key | ||
*/ | ||
FASTDEPLOY_DECL std::string GenerateRandomKey(); | ||
|
||
/** \brief encrypt a std::istream with key | ||
* | ||
* \param[in] keydata The key(base64-32bytes) for encryption | ||
* \param[in] in_stream The plain stream | ||
* \param[in] out_stream The ecrypted stream | ||
* \return true if encrypt successed, otherwise false | ||
*/ | ||
FASTDEPLOY_DECL int EncryptStream(const std::string &keydata, | ||
std::istream& in_stream, | ||
std::ostream& out_stream); | ||
|
||
/** \brief encrypt a string with key | ||
* | ||
* \param[in] input The input string for encryption | ||
* \param[in] key If not given by user, generate key automatically. | ||
* \return std::vector<std::string> [encrypted string, key] | ||
*/ | ||
FASTDEPLOY_DECL std::vector<std::string> Encrypt(const std::string& input, | ||
const std::string& key = GenerateRandomKey()); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
} // namespace fastdeploy | ||
#endif // PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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. | ||
#pragma once | ||
|
||
#ifndef DYGRAPH_DEPLOY_CPP_ENCRYPTION_INCLUDE_MODEL_CODE_H_ | ||
#define DYGRAPH_DEPLOY_CPP_ENCRYPTION_INCLUDE_MODEL_CODE_H_ | ||
namespace fastdeploy { | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
enum { | ||
CODE_OK = 0, | ||
CODE_OPEN_FAILED = 100, | ||
CODE_READ_FILE_PTR_IS_NULL = 101, | ||
CODE_AES_GCM_ENCRYPT_FIALED = 102, | ||
CODE_AES_GCM_DECRYPT_FIALED = 103, | ||
CODE_KEY_NOT_MATCH = 104, | ||
CODE_KEY_LENGTH_ABNORMAL = 105, | ||
CODE_NOT_EXIST_DIR = 106, | ||
CODE_FILES_EMPTY_WITH_DIR = 107, | ||
CODE_MODEL_FILE_NOT_EXIST = 108, | ||
CODE_PARAMS_FILE_NOT_EXIST = 109, | ||
CODE_MODEL_YML_FILE_NOT_EXIST = 110, | ||
CODE_MKDIR_FAILED = 111 | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
} // namespace fastdeploy | ||
#endif // DYGRAPH_DEPLOY_CPP_ENCRYPTION_INCLUDE_MODEL_CODE_H_ |
Oops, something went wrong.