Skip to content

Commit

Permalink
nghttpx: Add mruby env.tls_handshake_finished
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Sep 9, 2018
1 parent 5b42815 commit ed7c9db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/nghttpx.h2r
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ respectively.

Return ALPN identifier negotiated in this connection.

.. rb:attr_reader:: tls_handshake_finished

Return true if SSL/TLS handshake has finished. If it returns
false in the request phase hook, the request is received in
TLSv1.3 early data (0-RTT) and might be vulnerable to the
replay attack. nghttpx will send Early-Data header field to
backend servers to indicate this.

.. rb:class:: Request

Object to represent request from client. The modification to
Expand Down
14 changes: 14 additions & 0 deletions src/shrpx_mruby_module_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ mrb_value env_get_alpn(mrb_state *mrb, mrb_value self) {
}
} // namespace

namespace {
mrb_value env_get_tls_handshake_finished(mrb_state *mrb, mrb_value self) {
auto data = static_cast<MRubyAssocData *>(mrb->ud);
auto downstream = data->downstream;
auto upstream = downstream->get_upstream();
auto handler = upstream->get_client_handler();
auto conn = handler->get_connection();
return SSL_is_init_finished(conn->tls.ssl) ? mrb_true_value()
: mrb_false_value();
}
} // namespace

void init_env_class(mrb_state *mrb, RClass *module) {
auto env_class =
mrb_define_class_under(mrb, module, "Env", mrb->object_class);
Expand Down Expand Up @@ -439,6 +451,8 @@ void init_env_class(mrb_state *mrb, RClass *module) {
mrb_define_method(mrb, env_class, "tls_session_reused",
env_get_tls_session_reused, MRB_ARGS_NONE());
mrb_define_method(mrb, env_class, "alpn", env_get_alpn, MRB_ARGS_NONE());
mrb_define_method(mrb, env_class, "tls_handshake_finished",
env_get_tls_handshake_finished, MRB_ARGS_NONE());
}

} // namespace mruby
Expand Down

0 comments on commit ed7c9db

Please sign in to comment.