diff options
Diffstat (limited to 'lib/vtls/openssl.c')
| -rw-r--r-- | lib/vtls/openssl.c | 90 | 
1 files changed, 48 insertions, 42 deletions
| diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 5f3cfe375..50f6dbf2d 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -1679,7 +1679,6 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)    char *ciphers;    struct SessionHandle *data = conn->data;    SSL_METHOD_QUAL SSL_METHOD *req_method = NULL; -  void *ssl_sessionid = NULL;    X509_LOOKUP *lookup = NULL;    curl_socket_t sockfd = conn->sock[sockindex];    struct ssl_connect_data *connssl = &conn->ssl[sockindex]; @@ -2095,19 +2094,23 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)  #endif    /* Check if there's a cached ID we can/should use here! */ -  Curl_ssl_sessionid_lock(conn); -  if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL)) { -    /* we got a session id, use it! */ -    if(!SSL_set_session(connssl->handle, ssl_sessionid)) { -      Curl_ssl_sessionid_unlock(conn); -      failf(data, "SSL: SSL_set_session failed: %s", -            ERR_error_string(ERR_get_error(), NULL)); -      return CURLE_SSL_CONNECT_ERROR; +  if(conn->ssl_config.sessionid) { +    void *ssl_sessionid = NULL; + +    Curl_ssl_sessionid_lock(conn); +    if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL)) { +      /* we got a session id, use it! */ +      if(!SSL_set_session(connssl->handle, ssl_sessionid)) { +        Curl_ssl_sessionid_unlock(conn); +        failf(data, "SSL: SSL_set_session failed: %s", +              ERR_error_string(ERR_get_error(), NULL)); +        return CURLE_SSL_CONNECT_ERROR; +      } +      /* Informational message */ +      infof (data, "SSL re-using session ID\n");      } -    /* Informational message */ -    infof (data, "SSL re-using session ID\n"); +    Curl_ssl_sessionid_unlock(conn);    } -  Curl_ssl_sessionid_unlock(conn);    /* pass the raw socket into the SSL layers */    if(!SSL_set_fd(connssl->handle, (int)sockfd)) { @@ -2823,47 +2826,50 @@ static CURLcode servercert(struct connectdata *conn,  static CURLcode ossl_connect_step3(struct connectdata *conn, int sockindex)  {    CURLcode result = CURLE_OK; -  void *old_ssl_sessionid = NULL;    struct SessionHandle *data = conn->data;    struct ssl_connect_data *connssl = &conn->ssl[sockindex]; -  bool incache; -  SSL_SESSION *our_ssl_sessionid;    DEBUGASSERT(ssl_connect_3 == connssl->connecting_state); -  our_ssl_sessionid = SSL_get1_session(connssl->handle); +  if(conn->ssl_config.sessionid) { +    bool incache; +    SSL_SESSION *our_ssl_sessionid; +    void *old_ssl_sessionid = NULL; -  /* SSL_get1_session() will increment the reference count and the session -     will stay in memory until explicitly freed with SSL_SESSION_free(3), -     regardless of its state. */ +    our_ssl_sessionid = SSL_get1_session(connssl->handle); -  Curl_ssl_sessionid_lock(conn); -  incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL)); -  if(incache) { -    if(old_ssl_sessionid != our_ssl_sessionid) { -      infof(data, "old SSL session ID is stale, removing\n"); -      Curl_ssl_delsessionid(conn, old_ssl_sessionid); -      incache = FALSE; +    /* SSL_get1_session() will increment the reference count and the session +        will stay in memory until explicitly freed with SSL_SESSION_free(3), +        regardless of its state. */ + +    Curl_ssl_sessionid_lock(conn); +    incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL)); +    if(incache) { +      if(old_ssl_sessionid != our_ssl_sessionid) { +        infof(data, "old SSL session ID is stale, removing\n"); +        Curl_ssl_delsessionid(conn, old_ssl_sessionid); +        incache = FALSE; +      }      } -  } -  if(!incache) { -    result = Curl_ssl_addsessionid(conn, our_ssl_sessionid, -                                   0 /* unknown size */); -    if(result) { -      Curl_ssl_sessionid_unlock(conn); -      failf(data, "failed to store ssl session"); -      return result; +    if(!incache) { +      result = Curl_ssl_addsessionid(conn, our_ssl_sessionid, +                                      0 /* unknown size */); +      if(result) { +        Curl_ssl_sessionid_unlock(conn); +        failf(data, "failed to store ssl session"); +        return result; +      }      } +    else { +      /* Session was incache, so refcount already incremented earlier. +        * Avoid further increments with each SSL_get1_session() call. +        * This does not free the session as refcount remains > 0 +        */ +      SSL_SESSION_free(our_ssl_sessionid); +    } +    Curl_ssl_sessionid_unlock(conn);    } -  else { -    /* Session was incache, so refcount already incremented earlier. -     * Avoid further increments with each SSL_get1_session() call. -     * This does not free the session as refcount remains > 0 -     */ -    SSL_SESSION_free(our_ssl_sessionid); -  } -  Curl_ssl_sessionid_unlock(conn);    /*     * We check certificates to authenticate the server; otherwise we risk | 
