fix: 修复多个安全缺陷和功能问题
- 移除加密相关代码(服务端和所有客户端) - 修复 JWT 验证未检查签名算法的问题 - 修复重置密码使用不安全随机数的问题 - 实现 Logout 服务端失效机制 - 修复历史版本对比 diff 颜色标记错误 - 修复占位符解析循环引用风险 - 添加用户禁用状态检查 - 更新 bug 清单文档
This commit is contained in:
@@ -2,15 +2,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <curl/curl.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MAX_CONFIGS 256
|
||||
#define MAX_KEY_LEN 256
|
||||
#define MAX_VAL_LEN 4096
|
||||
#define CRYPT_PREFIX "{Cipher}"
|
||||
|
||||
typedef struct {
|
||||
char baseUrl[512];
|
||||
@@ -36,8 +32,6 @@ typedef struct {
|
||||
typedef struct {
|
||||
Config config;
|
||||
ConfigMap configs;
|
||||
char secret[256];
|
||||
char globalSecret[256];
|
||||
long lastTime;
|
||||
void (*onChange)(const char *key, const char *value);
|
||||
} ConfigClient;
|
||||
@@ -59,62 +53,6 @@ static size_t write_callback(void *contents, size_t size, size_t nmemb, void *us
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
static void md5_hex(const char *input, char *output) {
|
||||
unsigned char digest[MD5_DIGEST_LENGTH];
|
||||
MD5((unsigned char *)input, strlen(input), digest);
|
||||
for (int i = 0; i < MD5_DIGEST_LENGTH; i++)
|
||||
sprintf(output + i * 2, "%02x", digest[i]);
|
||||
output[32] = 0;
|
||||
}
|
||||
|
||||
static int base64_decode(const char *src, unsigned char *dst) {
|
||||
BIO *b64 = BIO_new(BIO_f_base64());
|
||||
BIO *mem = BIO_new_mem_buf((void *)src, strlen(src));
|
||||
mem = BIO_push(b64, mem);
|
||||
BIO_set_flags(mem, BIO_FLAGS_BASE64_NO_NL);
|
||||
int len = BIO_read(mem, dst, strlen(src));
|
||||
BIO_free_all(mem);
|
||||
return len;
|
||||
}
|
||||
|
||||
static void decrypt_with_aes(const char *key, const char *data, char *output) {
|
||||
char md5Hash[33];
|
||||
md5_hex(key, md5Hash);
|
||||
unsigned char aesKey[16];
|
||||
memcpy(aesKey, md5Hash + 16, 16);
|
||||
|
||||
unsigned char *cipherText = malloc(strlen(data) * 2);
|
||||
int cipherLen = base64_decode(data, cipherText);
|
||||
|
||||
unsigned char iv[16] = {0};
|
||||
unsigned char plainText[4096];
|
||||
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, aesKey, iv);
|
||||
EVP_CIPHER_CTX_set_padding(ctx, 0);
|
||||
int len = 0, totalLen = 0;
|
||||
EVP_DecryptUpdate(ctx, plainText, &len, cipherText, cipherLen);
|
||||
totalLen = len;
|
||||
EVP_DecryptFinal_ex(ctx, plainText + len, &len);
|
||||
totalLen += len;
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
|
||||
int padding = plainText[totalLen - 1];
|
||||
totalLen -= padding;
|
||||
memcpy(output, plainText, totalLen);
|
||||
output[totalLen] = 0;
|
||||
|
||||
free(cipherText);
|
||||
}
|
||||
|
||||
static void decrypt_config(const char *secret, const char *data, char *output) {
|
||||
if (strncmp(data, CRYPT_PREFIX, strlen(CRYPT_PREFIX)) != 0) {
|
||||
strcpy(output, data);
|
||||
return;
|
||||
}
|
||||
decrypt_with_aes(secret, data + strlen(CRYPT_PREFIX), output);
|
||||
}
|
||||
|
||||
static char *http_post_json(const char *url, const char *jsonBody) {
|
||||
CURL *curl = curl_easy_init();
|
||||
if (!curl) return NULL;
|
||||
@@ -144,8 +82,6 @@ static char *http_post_json(const char *url, const char *jsonBody) {
|
||||
void config_client_init(ConfigClient *client, Config *config) {
|
||||
client->config = *config;
|
||||
client->configs.count = 0;
|
||||
client->secret[0] = 0;
|
||||
client->globalSecret[0] = 0;
|
||||
client->lastTime = 0;
|
||||
client->onChange = NULL;
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
Reference in New Issue
Block a user