|
| 1 | +Name |
| 2 | +==== |
| 3 | + |
| 4 | +ngx.ssl.session - Lua API for manipulating SSL session data and IDs for NGINX downstream SSL connections. |
| 5 | + |
| 6 | +Status |
| 7 | +====== |
| 8 | + |
| 9 | +This Lua module is currently considered experimental. |
| 10 | + |
| 11 | +Description |
| 12 | +=========== |
| 13 | + |
| 14 | +This Lua module provides API functions for manipulating SSL session data and IDs for NGINX |
| 15 | +downstream connections. It is mostly for the contexts [ssl_session_fetch_by_lua*](https://github.com/openresty/lua-nginx-module/tree/ssl-session#ssl_session_fetch_by_lua_block) |
| 16 | +and [ssl_session_store_by_lua*](https://github.com/openresty/lua-nginx-module/tree/ssl-session#ssl_session_store_by_lua_block). |
| 17 | + |
| 18 | +This Lua API can be used to implement distributed SSL session caching for downstream SSL connections, thus saving a lot of full SSL handshakes which are very expensive. |
| 19 | + |
| 20 | +To load the `ngx.ssl.session` module in Lua, just write |
| 21 | + |
| 22 | +```lua |
| 23 | +local ssl_sess = require "ngx.ssl.session" |
| 24 | +``` |
| 25 | + |
| 26 | +Methods |
| 27 | +======= |
| 28 | + |
| 29 | +get_session_id |
| 30 | +-------------- |
| 31 | +**syntax:** *id, err = ssl_sess.get_session_id()* |
| 32 | + |
| 33 | +**context:** *ssl_session_fetch_by_lua*, ssl_session_store_by_lua** |
| 34 | + |
| 35 | +Fetches the SSL session ID associated with the current downstream SSL connection. |
| 36 | +The ID is returned as a Lua string. |
| 37 | + |
| 38 | +In case of errors, it returns `nil` and a string describing the error. |
| 39 | + |
| 40 | +This API function is usually called in the contexts of |
| 41 | +[ssl_session_store_by_lua*](https://github.com/openresty/lua-nginx-module/tree/ssl-session#ssl_session_store_by_lua_block) |
| 42 | +and [ssl_session_fetch_by_lua*](https://github.com/openresty/lua-nginx-module/tree/ssl-session#ssl_session_fetch_by_lua_block). |
| 43 | + |
| 44 | +get_serialized_session |
| 45 | +---------------------- |
| 46 | +**syntax:** *session, err = ssl_sess.get_serialized_session()* |
| 47 | + |
| 48 | +**context:** *ssl_session_store_by_lua** |
| 49 | + |
| 50 | +Returns the serialized form of the SSL sesson data of the current SSL connection, in a Lua string. |
| 51 | + |
| 52 | +This session can be cached in [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache), [lua_shared_dict](https://github.com/openresty/lua-nginx-module#lua_shared_dict), |
| 53 | +and/or external data storage services like `memcached` and `redis`. The SSL session ID returned |
| 54 | +by the [get_session_id](#get_session_id) function is usually used as the cache key. |
| 55 | + |
| 56 | +The returned SSL session data can later be loaded into other SSL connections using the same |
| 57 | +session ID via the [set_serialized_session](#set_serialized_session) function. |
| 58 | + |
| 59 | +In case of errors, it returns `nil` and a string describing the error. |
| 60 | + |
| 61 | +This API function is usually called in the context of |
| 62 | +[ssl_session_store_by_lua*](https://github.com/openresty/lua-nginx-module/tree/ssl-session#ssl_session_store_by_lua_block) |
| 63 | +where the SSL handshake has just completed. |
| 64 | + |
| 65 | +set_serialized_session |
| 66 | +---------------------- |
| 67 | +**syntax:** *ok, err = ssl_sess.set_serialized_session(session)* |
| 68 | + |
| 69 | +**context:** *ssl_session_fetch_by_lua** |
| 70 | + |
| 71 | +Sets the serialized SSL session provided as the argument to the current SSL connection. |
| 72 | +If the SSL session is successfully set, the current SSL connection can resume the session |
| 73 | +directly without going through the full SSL handshake process (which is very expensive in terms of CPU time). |
| 74 | + |
| 75 | +This API is usually used in the context of [ssl_session_fetch_by_lua*](https://github.com/openresty/lua-nginx-module/tree/ssl-session#ssl_session_fetch_by_lua_block) |
| 76 | +when a cache hit is found with the current SSL session ID. |
| 77 | + |
| 78 | +The serialized SSL session used as the argument should be originally returned by the |
| 79 | +[get_serialized_session](#get_serialized_session) function. |
| 80 | + |
| 81 | +Community |
| 82 | +========= |
| 83 | + |
| 84 | +[Back to TOC](#table-of-contents) |
| 85 | + |
| 86 | +English Mailing List |
| 87 | +-------------------- |
| 88 | + |
| 89 | +The [openresty-en](https://groups.google.com/group/openresty-en) mailing list is for English speakers. |
| 90 | + |
| 91 | +[Back to TOC](#table-of-contents) |
| 92 | + |
| 93 | +Chinese Mailing List |
| 94 | +-------------------- |
| 95 | + |
| 96 | +The [openresty](https://groups.google.com/group/openresty) mailing list is for Chinese speakers. |
| 97 | + |
| 98 | +[Back to TOC](#table-of-contents) |
| 99 | + |
| 100 | +Bugs and Patches |
| 101 | +================ |
| 102 | + |
| 103 | +Please report bugs or submit patches by |
| 104 | + |
| 105 | +1. creating a ticket on the [GitHub Issue Tracker](https://github.com/openresty/lua-resty-core/issues), |
| 106 | +1. or posting to the [OpenResty community](#community). |
| 107 | + |
| 108 | +[Back to TOC](#table-of-contents) |
| 109 | + |
| 110 | +Author |
| 111 | +====== |
| 112 | + |
| 113 | +Yichun Zhang <[email protected]> (agentzh), CloudFlare Inc. |
| 114 | + |
| 115 | +[Back to TOC](#table-of-contents) |
| 116 | + |
| 117 | +Copyright and License |
| 118 | +===================== |
| 119 | + |
| 120 | +This module is licensed under the BSD license. |
| 121 | + |
| 122 | +Copyright (C) 2016, by Yichun "agentzh" Zhang, CloudFlare Inc. |
| 123 | + |
| 124 | +All rights reserved. |
| 125 | + |
| 126 | +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
| 127 | + |
| 128 | +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
| 129 | + |
| 130 | +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
| 131 | + |
| 132 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 133 | + |
| 134 | +[Back to TOC](#table-of-contents) |
| 135 | + |
| 136 | +See Also |
| 137 | +======== |
| 138 | +* the ngx_lua module: https://github.com/openresty/lua-nginx-module |
| 139 | +* the [ssl_session_fetch_by_lua*](https://github.com/openresty/lua-nginx-module/#ssl_session_fetch_by_lua_block) directive. |
| 140 | +* the [ssl_session_store_by_lua*](https://github.com/openresty/lua-nginx-module/#ssl_session_store_by_lua_block) directive. |
| 141 | +* library [lua-resty-core](https://github.com/openresty/lua-resty-core) |
| 142 | +* OpenResty: https://openresty.org |
| 143 | + |
| 144 | +[Back to TOC](#table-of-contents) |
0 commit comments