libfreerdp: certificate: Add key_clone
authorkubistika <kmizrachi18@gmail.com>
Tue, 16 Jul 2019 10:26:26 +0000 (13:26 +0300)
committerakallabeth <akallabeth@users.noreply.github.com>
Tue, 16 Jul 2019 11:47:35 +0000 (13:47 +0200)
libfreerdp/core/certificate.c
libfreerdp/core/certificate.h

index 4b4d1cb..9139856 100644 (file)
@@ -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)
index c5dd4ee..ece4fbe 100644 (file)
@@ -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