From: kubistika Date: Tue, 16 Jul 2019 10:26:26 +0000 (+0300) Subject: libfreerdp: certificate: Add key_clone X-Git-Tag: 2.0.0~423 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8acea82288b1e099c03faaaa2c9ec7b0ae27ecd1;p=platform%2Fupstream%2Ffreerdp.git libfreerdp: certificate: Add key_clone --- 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