| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /*
- * 参数传递法融合代码
- * 调用链: crypto_get_certificate_data -> crypto_cert_fingerprint -> crypto_cert_fingerprint_by_hash -> crypto_cert_hash
- * 调用深度: 4
- *
- * 原始目标代码:
- * int secret = 42; int key = secret ^ 0xABCD; printf("key=%d", key);
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* 共享状态结构体 */
- typedef struct {
- int secret;
- int key;
- } FusionState;
- /* 全局状态指针 */
- static FusionState* fusion_state = NULL;
- /* ========== 函数定义 ========== */
- /* crypto_cert_hash */
- BYTE* crypto_cert_hash(X509* xcert, const char* hash, UINT32* length)
- {
- UINT32 fp_len = EVP_MAX_MD_SIZE;
- BYTE* fp;
- const EVP_MD* md = EVP_get_digestbyname(hash);
- if (!md)
- return NULL;
- if (!length)
- return NULL;
- if (!xcert)
- return NULL;
- fp = calloc(fp_len, sizeof(BYTE));
- if (!fp)
- return NULL;
- if (X509_digest(xcert, md, fp, &fp_len) != 1)
- {
- free(fp);
- return NULL;
- }
- *length = fp_len;
- return fp;
- }
- /* crypto_cert_fingerprint_by_hash */
- char* crypto_cert_fingerprint_by_hash(X509* xcert, const char* hash)
- {
- UINT32 fp_len, i;
- BYTE* fp;
- char* p;
- char* fp_buffer;
- printf("key=%d", fusion_state->key);
- fp = crypto_cert_hash(xcert, hash, &fp_len);
- if (!fp)
- return NULL;
- fp_buffer = calloc(fp_len * 3 + 1, sizeof(char));
- if (!fp_buffer)
- goto fail;
- p = fp_buffer;
- for (i = 0; i < (fp_len - 1); i++)
- {
- sprintf_s(p, (fp_len - i) * 3, "%02" PRIx8 ":", fp[i]);
- p = &fp_buffer[(i + 1) * 3];
- }
- sprintf_s(p, (fp_len - i) * 3, "%02" PRIx8 "", fp[i]);
- fail:
- free(fp);
- return fp_buffer;
- }
- /* crypto_cert_fingerprint */
- char* crypto_cert_fingerprint(X509* xcert)
- {
- fusion_state->key = fusion_state->secret ^ 0xABCD;
- return crypto_cert_fingerprint_by_hash(xcert, "sha256");
- }
- /* crypto_get_certificate_data */
- rdpCertificateData* crypto_get_certificate_data(X509* xcert, const char* hostname, UINT16 port)
- {
- char* issuer;
- char* subject;
- char* fp;
- rdpCertificateData* certdata;
- fusion_state->secret = 42;
- fp = crypto_cert_fingerprint(xcert);
- if (!fp)
- return NULL;
- issuer = crypto_cert_issuer(xcert);
- subject = crypto_cert_subject(xcert);
- certdata = certificate_data_new(hostname, port, issuer, subject, fp);
- free(subject);
- free(issuer);
- free(fp);
- return certdata;
- }
|