~ubuntu-branches/debian/sid/haproxy/sid

« back to all changes in this revision

Viewing changes to src/ssl_sock.c

  • Committer: Package Import Robot
  • Author(s): Vincent Bernat
  • Date: 2014-12-07 11:11:21 UTC
  • Revision ID: package-import@ubuntu.com-20141207111121-qgifv7nl6eoi3lek
Tags: 1.5.8-2
* Cherry-pick the following patches from 1.5.9 release:
    - 8a0b93bde77e BUG/MAJOR: sessions: unlink session from list on out
                              of memory
    - bae03eaad40a BUG/MEDIUM: pattern: don't load more than once a pattern
                               list.
    - 93637b6e8503 BUG/MEDIUM: connection: sanitize PPv2 header length before
                               parsing address information
    - 8ba50128832b BUG/MAJOR: frontend: initialize capture pointers earlier
    - 1f96a87c4e14 BUG/MEDIUM: checks: fix conflicts between agent checks and
                               ssl healthchecks
    - 9bcc01ae2598 BUG/MEDIUM: ssl: force a full GC in case of memory shortage
    - 909514970089 BUG/MEDIUM: ssl: fix bad ssl context init can cause
                               segfault in case of OOM.
* Cherry-pick the following patches from future 1.5.10 release:
    - 1e89acb6be9b BUG/MEDIUM: payload: ensure that a request channel is
                               available
    - bad3c6f1b6d7 BUG/MEDIUM: patterns: previous fix was incomplete

Show diffs side-by-side

added added

removed removed

Lines of Context:
1812
1812
        if (srv->use_ssl)
1813
1813
                srv->xprt = &ssl_sock;
1814
1814
        if (srv->check.use_ssl)
1815
 
                srv->check_common.xprt = &ssl_sock;
 
1815
                srv->check.xprt = &ssl_sock;
1816
1816
 
1817
1817
        srv->ssl_ctx.ctx = SSL_CTX_new(SSLv23_client_method());
1818
1818
        if (!srv->ssl_ctx.ctx) {
2033
2033
        /* If it is in client mode initiate SSL session
2034
2034
           in connect state otherwise accept state */
2035
2035
        if (objt_server(conn->target)) {
 
2036
                int may_retry = 1;
 
2037
 
 
2038
        retry_connect:
2036
2039
                /* Alloc a new SSL session ctx */
2037
2040
                conn->xprt_ctx = SSL_new(objt_server(conn->target)->ssl_ctx.ctx);
2038
2041
                if (!conn->xprt_ctx) {
 
2042
                        if (may_retry--) {
 
2043
                                pool_gc2();
 
2044
                                goto retry_connect;
 
2045
                        }
 
2046
                        conn->err_code = CO_ER_SSL_NO_MEM;
 
2047
                        return -1;
 
2048
                }
 
2049
 
 
2050
                /* set fd on SSL session context */
 
2051
                if (!SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd)) {
 
2052
                        SSL_free(conn->xprt_ctx);
 
2053
                        conn->xprt_ctx = NULL;
 
2054
                        if (may_retry--) {
 
2055
                                pool_gc2();
 
2056
                                goto retry_connect;
 
2057
                        }
 
2058
                        conn->err_code = CO_ER_SSL_NO_MEM;
 
2059
                        return -1;
 
2060
                }
 
2061
 
 
2062
                /* set connection pointer */
 
2063
                if (!SSL_set_app_data(conn->xprt_ctx, conn)) {
 
2064
                        SSL_free(conn->xprt_ctx);
 
2065
                        conn->xprt_ctx = NULL;
 
2066
                        if (may_retry--) {
 
2067
                                pool_gc2();
 
2068
                                goto retry_connect;
 
2069
                        }
2039
2070
                        conn->err_code = CO_ER_SSL_NO_MEM;
2040
2071
                        return -1;
2041
2072
                }
2042
2073
 
2043
2074
                SSL_set_connect_state(conn->xprt_ctx);
2044
 
                if (objt_server(conn->target)->ssl_ctx.reused_sess)
2045
 
                        SSL_set_session(conn->xprt_ctx, objt_server(conn->target)->ssl_ctx.reused_sess);
2046
 
 
2047
 
                /* set fd on SSL session context */
2048
 
                SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);
2049
 
 
2050
 
                /* set connection pointer */
2051
 
                SSL_set_app_data(conn->xprt_ctx, conn);
 
2075
                if (objt_server(conn->target)->ssl_ctx.reused_sess) {
 
2076
                        if(!SSL_set_session(conn->xprt_ctx, objt_server(conn->target)->ssl_ctx.reused_sess)) {
 
2077
                                SSL_SESSION_free(objt_server(conn->target)->ssl_ctx.reused_sess);
 
2078
                                objt_server(conn->target)->ssl_ctx.reused_sess = NULL;
 
2079
                        }
 
2080
                }
2052
2081
 
2053
2082
                /* leave init state and start handshake */
2054
2083
                conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN;
2058
2087
                return 0;
2059
2088
        }
2060
2089
        else if (objt_listener(conn->target)) {
 
2090
                int may_retry = 1;
 
2091
 
 
2092
        retry_accept:
2061
2093
                /* Alloc a new SSL session ctx */
2062
2094
                conn->xprt_ctx = SSL_new(objt_listener(conn->target)->bind_conf->default_ctx);
2063
2095
                if (!conn->xprt_ctx) {
 
2096
                        if (may_retry--) {
 
2097
                                pool_gc2();
 
2098
                                goto retry_accept;
 
2099
                        }
 
2100
                        conn->err_code = CO_ER_SSL_NO_MEM;
 
2101
                        return -1;
 
2102
                }
 
2103
 
 
2104
                /* set fd on SSL session context */
 
2105
                if (!SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd)) {
 
2106
                        SSL_free(conn->xprt_ctx);
 
2107
                        conn->xprt_ctx = NULL;
 
2108
                        if (may_retry--) {
 
2109
                                pool_gc2();
 
2110
                                goto retry_accept;
 
2111
                        }
 
2112
                        conn->err_code = CO_ER_SSL_NO_MEM;
 
2113
                        return -1;
 
2114
                }
 
2115
 
 
2116
                /* set connection pointer */
 
2117
                if (!SSL_set_app_data(conn->xprt_ctx, conn)) {
 
2118
                        SSL_free(conn->xprt_ctx);
 
2119
                        conn->xprt_ctx = NULL;
 
2120
                        if (may_retry--) {
 
2121
                                pool_gc2();
 
2122
                                goto retry_accept;
 
2123
                        }
2064
2124
                        conn->err_code = CO_ER_SSL_NO_MEM;
2065
2125
                        return -1;
2066
2126
                }
2067
2127
 
2068
2128
                SSL_set_accept_state(conn->xprt_ctx);
2069
2129
 
2070
 
                /* set fd on SSL session context */
2071
 
                SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);
2072
 
 
2073
 
                /* set connection pointer */
2074
 
                SSL_set_app_data(conn->xprt_ctx, conn);
2075
 
 
2076
2130
                /* leave init state and start handshake */
2077
2131
                conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN;
2078
2132