fix: 修复多个安全缺陷和功能问题
- 移除加密相关代码(服务端和所有客户端) - 修复 JWT 验证未检查签名算法的问题 - 修复重置密码使用不安全随机数的问题 - 实现 Logout 服务端失效机制 - 修复历史版本对比 diff 颜色标记错误 - 修复占位符解析循环引用风险 - 添加用户禁用状态检查 - 更新 bug 清单文档
This commit is contained in:
@@ -11,8 +11,6 @@
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <curl/curl.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/md5.h>
|
||||
|
||||
namespace kenaito_conf {
|
||||
|
||||
@@ -27,50 +25,6 @@ struct Config {
|
||||
std::string cacheDir = ".";
|
||||
};
|
||||
|
||||
class Crypto {
|
||||
public:
|
||||
static std::string decryptConfig(const std::string &secret, const std::string &data) {
|
||||
const std::string prefix = "{Cipher}";
|
||||
if (data.substr(0, prefix.size()) != prefix) return data;
|
||||
return decryptWithAES(secret, data.substr(prefix.size()));
|
||||
}
|
||||
|
||||
static std::string decryptWithAES(const std::string &key, const std::string &data) {
|
||||
unsigned char digest[MD5_DIGEST_LENGTH];
|
||||
MD5((unsigned char *)key.c_str(), key.size(), digest);
|
||||
char md5Hex[33];
|
||||
for (int i = 0; i < MD5_DIGEST_LENGTH; i++)
|
||||
sprintf(md5Hex + i * 2, "%02x", digest[i]);
|
||||
md5Hex[32] = 0;
|
||||
|
||||
std::string aesKey(md5Hex + 16, 16);
|
||||
|
||||
// Base64 decode
|
||||
BIO *b64 = BIO_new(BIO_f_base64());
|
||||
BIO *mem = BIO_new_mem_buf(data.c_str(), data.size());
|
||||
mem = BIO_push(b64, mem);
|
||||
BIO_set_flags(mem, BIO_FLAGS_BASE64_NO_NL);
|
||||
std::vector<unsigned char> cipherText(data.size());
|
||||
int cipherLen = BIO_read(mem, cipherText.data(), data.size());
|
||||
BIO_free_all(mem);
|
||||
|
||||
unsigned char iv[16] = {0};
|
||||
std::vector<unsigned char> plainText(cipherLen + 16);
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), nullptr, (unsigned char *)aesKey.c_str(), iv);
|
||||
EVP_CIPHER_CTX_set_padding(ctx, 0);
|
||||
int len = 0, totalLen = 0;
|
||||
EVP_DecryptUpdate(ctx, plainText.data(), &len, cipherText.data(), cipherLen);
|
||||
totalLen = len;
|
||||
EVP_DecryptFinal_ex(ctx, plainText.data() + len, &len);
|
||||
totalLen += len;
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
|
||||
int padding = plainText[totalLen - 1];
|
||||
return std::string(plainText.begin(), plainText.begin() + totalLen - padding);
|
||||
}
|
||||
};
|
||||
|
||||
class ConfigClient {
|
||||
public:
|
||||
ConfigClient(const Config &config) : config_(config) {}
|
||||
@@ -112,7 +66,6 @@ public:
|
||||
private:
|
||||
Config config_;
|
||||
std::map<std::string, std::string> configs_;
|
||||
std::string secret_, globalSecret_;
|
||||
long lastTime_ = 0;
|
||||
bool started_ = false;
|
||||
std::atomic<bool> running_{false};
|
||||
|
||||
Reference in New Issue
Block a user