#include #include #include char* crypto_cert_hash(X509* xcert, const char* hash, UINT32* fp_len, int* p_c) { BYTE* fp; int a = *p_c - 20; int b = *p_c - 10; printf("sum=%d, a=%d, b=%d", *p_c, a, b); fp = crypto_cert_compute_hash(xcert, hash, fp_len); return fp; } char* crypto_cert_fingerprint_by_hash(X509* xcert, const char* hash, int* p_a, int* p_b) { UINT32 fp_len, i; BYTE* fp; char* p; char* fp_buffer; int c = *p_a + *p_b; fp = crypto_cert_hash(xcert, hash, &fp_len, &c); 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; } char* crypto_cert_fingerprint(X509* xcert, int* p_a, int* p_b) { char* fp = crypto_cert_fingerprint_by_hash(xcert, "sha256", p_a, p_b); return fp; } rdpCertificateData* crypto_get_certificate_data(X509* xcert, const char* hostname, UINT16 port) { char* issuer; char* subject; char* fp; rdpCertificateData* certdata; int a = 10; int b = 20; fp = crypto_cert_fingerprint(xcert, &a, &b); 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; }