[PATCH 3/9] Move RSA key generation for ticket to a helper function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 server/reds.c | 68 +++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 41 insertions(+), 27 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 1e169ad..19a3298 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1327,6 +1327,46 @@ static void reds_channel_init_auth_caps(RedLinkInfo *link, RedChannel *channel)
 }
 
 
+static int reds_generate_ticket_pubkey(RedLinkInfo *link, SpiceLinkReply *ack)
+{
+    BUF_MEM *bmBuf;
+    BIO *bio = NULL;
+    bool ret = FALSE;
+
+    if (!(link->tiTicketing.rsa = RSA_new())) {
+        spice_warning("RSA new failed");
+        goto end;
+    }
+
+    if (!(bio = BIO_new(BIO_s_mem()))) {
+        spice_warning("BIO new failed");
+        goto end;
+    }
+
+    if (RSA_generate_key_ex(link->tiTicketing.rsa,
+                            SPICE_TICKET_KEY_PAIR_LENGTH,
+                            link->tiTicketing.bn,
+                            NULL) != 1) {
+        spice_warning("Failed to generate %d bits RSA key: %s",
+                      SPICE_TICKET_KEY_PAIR_LENGTH,
+                      ERR_error_string(ERR_get_error(), NULL));
+        goto end;
+    }
+    link->tiTicketing.rsa_size = RSA_size(link->tiTicketing.rsa);
+
+    i2d_RSA_PUBKEY_bio(bio, link->tiTicketing.rsa);
+    BIO_get_mem_ptr(bio, &bmBuf);
+    memcpy(ack->pub_key, bmBuf->data, sizeof(ack->pub_key));
+    ret = TRUE;
+
+end:
+    if (bio != NULL) {
+        BIO_free(bio);
+    }
+    return ret;
+}
+
+
 static bool test_link_capability(RedLinkInfo *link, uint32_t cap)
 {
     uint32_t *caps = (uint32_t *)((uint8_t *)link->link_mess + link->link_mess->caps_offset);
@@ -1341,8 +1381,6 @@ static int reds_send_link_ack(RedLinkInfo *link)
     SpiceLinkReply ack;
     RedChannel *channel;
     RedChannelCapabilities *channel_caps;
-    BUF_MEM *bmBuf;
-    BIO *bio;
     int ret = FALSE;
 
     header.magic = SPICE_MAGIC;
@@ -1366,31 +1404,8 @@ static int reds_send_link_ack(RedLinkInfo *link)
     ack.num_channel_caps = channel_caps->num_caps;
     header.size += (ack.num_common_caps + ack.num_channel_caps) * sizeof(uint32_t);
     ack.caps_offset = sizeof(SpiceLinkReply);
-
-    if (!(link->tiTicketing.rsa = RSA_new())) {
-        spice_warning("RSA new failed");
-        return FALSE;
-    }
-
-    if (!(bio = BIO_new(BIO_s_mem()))) {
-        spice_warning("BIO new failed");
-        return FALSE;
-    }
-
-    if (RSA_generate_key_ex(link->tiTicketing.rsa,
-                            SPICE_TICKET_KEY_PAIR_LENGTH,
-                            link->tiTicketing.bn,
-                            NULL) != 1) {
-        spice_warning("Failed to generate %d bits RSA key: %s",
-                      SPICE_TICKET_KEY_PAIR_LENGTH,
-                      ERR_error_string(ERR_get_error(), NULL));
+    if (!reds_generate_ticket_pubkey(link, &ack))
         goto end;
-    }
-    link->tiTicketing.rsa_size = RSA_size(link->tiTicketing.rsa);
-
-    i2d_RSA_PUBKEY_bio(bio, link->tiTicketing.rsa);
-    BIO_get_mem_ptr(bio, &bmBuf);
-    memcpy(ack.pub_key, bmBuf->data, sizeof(ack.pub_key));
 
     if (!reds_stream_write_all(link->stream, &header, sizeof(header)))
         goto end;
@@ -1404,7 +1419,6 @@ static int reds_send_link_ack(RedLinkInfo *link)
     ret = TRUE;
 
 end:
-    BIO_free(bio);
     return ret;
 }
 
-- 
1.8.5.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]