Skip to content

Commit

Permalink
vtls: reinstantiate engine on duplicated handles
Browse files Browse the repository at this point in the history
Handles created with curl_easy_duphandle do not use the SSL engine set
up in the original handle. This fixes the issue by storing the engine
name in the internal url state and setting the engine from its name
inside curl_easy_duphandle.

Reported-by: Anton Gerasimov
Signed-of-by: Laurent Bonnans
Closes curl#2829
  • Loading branch information
lbonn committed Aug 6, 2018
1 parent 81be254 commit 7e0ec92
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/easy.c
Expand Up @@ -958,6 +958,12 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
outcurl->change.referer_alloc = TRUE;
}

/* Reinitialize an SSL engine for the new handle */
if(data->state.engine_name) {
if(Curl_ssl_set_engine(outcurl, data->state.engine_name))
goto fail;
}

/* Clone the resolver handle, if present, for the new handle */
if(Curl_resolver_duphandle(&outcurl->state.resolver,
data->state.resolver))
Expand Down
1 change: 1 addition & 0 deletions lib/urldata.h
Expand Up @@ -1268,6 +1268,7 @@ struct UrlState {
void *resolver; /* resolver state, if it is used in the URL state -
ares_channel f.e. */

char *engine_name;
#if defined(USE_OPENSSL)
/* void instead of ENGINE to avoid bleeding OpenSSL into this header */
void *engine;
Expand Down
14 changes: 12 additions & 2 deletions lib/vtls/vtls.c
Expand Up @@ -49,6 +49,7 @@
#endif

#include "urldata.h"
#include "setopt.h"

#include "vtls.h" /* generic SSL protos etc */
#include "slist.h"
Expand Down Expand Up @@ -570,14 +571,23 @@ CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex)
*/
CURLcode Curl_ssl_set_engine(struct Curl_easy *data, const char *engine)
{
return Curl_ssl->set_engine(data, engine);
CURLcode result = Curl_ssl->set_engine(data, engine);
if(result)
return result;

/* store engine name, to be reinstanced on copied handles */
return Curl_setstropt(&data->state.engine_name, engine);
}

/* Selects the default SSL crypto engine
*/
CURLcode Curl_ssl_set_engine_default(struct Curl_easy *data)
{
return Curl_ssl->set_engine_default(data);
CURLcode result = Curl_ssl->set_engine_default(data);
if(result)
return result;

return Curl_setstropt(&data->state.engine_name, NULL);
}

/* Return list of OpenSSL crypto engine names. */
Expand Down

0 comments on commit 7e0ec92

Please sign in to comment.