From 8acea82288b1e099c03faaaa2c9ec7b0ae27ecd1 Mon Sep 17 00:00:00 2001 From: kubistika Date: Tue, 16 Jul 2019 13:26:26 +0300 Subject: [PATCH] libfreerdp: certificate: Add key_clone --- libfreerdp/core/certificate.c | 38 ++++++++++++++++++++++++++++++++++++++ libfreerdp/core/certificate.h | 1 + 2 files changed, 39 insertions(+) diff --git a/libfreerdp/core/certificate.c b/libfreerdp/core/certificate.c index 4b4d1cb..9139856 100644 --- a/libfreerdp/core/certificate.c +++ b/libfreerdp/core/certificate.c @@ -826,6 +826,44 @@ out_free: return NULL; } +rdpRsaKey* key_clone(const rdpRsaKey* key) +{ + rdpRsaKey* _key = (rdpRsaKey*) calloc(1, sizeof(rdpRsaKey)); + + if (!_key) + return NULL; + + CopyMemory(_key, key, sizeof(rdpRsaKey)); + + if (key->Modulus) + { + _key->Modulus = (BYTE*) malloc(key->ModulusLength); + + if (!_key->Modulus) + goto out_fail; + + CopyMemory(_key->Modulus, key->Modulus, key->ModulusLength); + } + + if (key->PrivateExponent) + { + _key->PrivateExponent = (BYTE*) malloc(key->PrivateExponentLength); + + if (!_key->PrivateExponent) + goto out_fail; + + CopyMemory(_key->PrivateExponent, key->PrivateExponent, key->PrivateExponentLength); + } + + return _key; +out_fail: + free(_key->Modulus); + free(_key->PrivateExponent); + free(_key); + return NULL; +} + + void key_free(rdpRsaKey* key) { if (!key) diff --git a/libfreerdp/core/certificate.h b/libfreerdp/core/certificate.h index c5dd4ee..ece4fbe 100644 --- a/libfreerdp/core/certificate.h +++ b/libfreerdp/core/certificate.h @@ -57,6 +57,7 @@ FREERDP_LOCAL rdpRsaKey* key_new(const char* keyfile); FREERDP_LOCAL rdpRsaKey* key_new_from_content(const char* keycontent, const char* keyfile); FREERDP_LOCAL void key_free(rdpRsaKey* key); +FREERDP_LOCAL rdpRsaKey* key_clone(const rdpRsaKey* key); #define CERTIFICATE_TAG FREERDP_TAG("core.certificate") #ifdef WITH_DEBUG_CERTIFICATE -- 2.7.4