[Spice-devel] [PATCH 3/9] Move RSA key generation for ticket to a helper function
Marc-André Lureau
mlureau at redhat.com
Wed Mar 12 12:17:32 PDT 2014
----- Original Message -----
> ---
> 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)
ack,
(since I don't really see why this key pair couldn't be used for other things than the ticket, it could just be called reds_rsa_generate_key()? just some thoughts)
> +{
> + 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 at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
>
More information about the Spice-devel
mailing list