Allow creating security handshaker without adding it to handshake manager.

pull/8979/head
Mark D. Roth 8 years ago
parent 5335cd62b6
commit d095340897
  1. 4
      src/core/lib/http/httpcli_security_connector.c
  2. 31
      src/core/lib/security/transport/security_connector.c
  3. 17
      src/core/lib/security/transport/security_handshaker.c
  4. 13
      src/core/lib/security/transport/security_handshaker.h

@ -74,7 +74,9 @@ static void httpcli_ssl_add_handshakers(grpc_exec_ctx *exec_ctx,
tsi_result_to_string(result));
}
}
grpc_security_add_handshakers(exec_ctx, handshaker, &sc->base, handshake_mgr);
grpc_handshake_manager_add(
handshake_mgr,
grpc_security_handshaker_create(exec_ctx, handshaker, &sc->base));
}
static void httpcli_ssl_check_peer(grpc_exec_ctx *exec_ctx,

@ -43,6 +43,7 @@
#include <grpc/support/string_util.h>
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/credentials/credentials.h"
@ -288,17 +289,21 @@ static void fake_channel_check_call_host(grpc_exec_ctx *exec_ctx,
static void fake_channel_add_handshakers(
grpc_exec_ctx *exec_ctx, grpc_channel_security_connector *sc,
grpc_handshake_manager *handshake_mgr) {
grpc_security_add_handshakers(
exec_ctx, tsi_create_fake_handshaker(true /* is_client */), &sc->base,
handshake_mgr);
grpc_handshake_manager_add(
handshake_mgr,
grpc_security_handshaker_create(
exec_ctx, tsi_create_fake_handshaker(true /* is_client */),
&sc->base));
}
static void fake_server_add_handshakers(grpc_exec_ctx *exec_ctx,
grpc_server_security_connector *sc,
grpc_handshake_manager *handshake_mgr) {
grpc_security_add_handshakers(
exec_ctx, tsi_create_fake_handshaker(false /* is_client */), &sc->base,
handshake_mgr);
static void fake_server_create_handshakers(
grpc_exec_ctx *exec_ctx, grpc_server_security_connector *sc,
grpc_handshake_manager *handshake_mgr) {
grpc_handshake_manager_add(
handshake_mgr,
grpc_security_handshaker_create(
exec_ctx, tsi_create_fake_handshaker(false /* is_client */),
&sc->base));
}
static grpc_security_connector_vtable fake_channel_vtable = {
@ -395,7 +400,9 @@ static void ssl_channel_add_handshakers(grpc_exec_ctx *exec_ctx,
: c->target_name,
&tsi_hs);
// Create handshakers.
grpc_security_add_handshakers(exec_ctx, tsi_hs, &sc->base, handshake_mgr);
grpc_handshake_manager_add(
handshake_mgr,
grpc_security_handshaker_create(exec_ctx, tsi_hs, &sc->base));
}
static void ssl_server_add_handshakers(grpc_exec_ctx *exec_ctx,
@ -408,7 +415,9 @@ static void ssl_server_add_handshakers(grpc_exec_ctx *exec_ctx,
ssl_create_handshaker(c->handshaker_factory, false /* is_client */,
NULL /* peer_name */, &tsi_hs);
// Create handshakers.
grpc_security_add_handshakers(exec_ctx, tsi_hs, &sc->base, handshake_mgr);
grpc_handshake_manager_add(
handshake_mgr,
grpc_security_handshaker_create(exec_ctx, tsi_hs, &sc->base));
}
static int ssl_host_matches_name(const tsi_peer *peer, const char *peer_name) {

@ -434,17 +434,14 @@ static grpc_handshaker *fail_handshaker_create() {
// exported functions
//
void grpc_security_add_handshakers(grpc_exec_ctx *exec_ctx,
tsi_handshaker *handshaker,
grpc_security_connector *connector,
grpc_handshake_manager *handshake_mgr) {
// If no TSI handshaker was created, add a handshaker that always fails.
// Otherwise, add a real security handshaker.
grpc_handshaker *grpc_security_handshaker_create(
grpc_exec_ctx *exec_ctx, tsi_handshaker *handshaker,
grpc_security_connector *connector) {
// If no TSI handshaker was created, return a handshaker that always fails.
// Otherwise, return a real security handshaker.
if (handshaker == NULL) {
grpc_handshake_manager_add(handshake_mgr, fail_handshaker_create());
return fail_handshaker_create();
} else {
grpc_handshake_manager_add(
handshake_mgr,
security_handshaker_create(exec_ctx, handshaker, connector));
return security_handshaker_create(exec_ctx, handshaker, connector);
}
}

@ -34,14 +34,13 @@
#ifndef GRPC_CORE_LIB_SECURITY_TRANSPORT_SECURITY_HANDSHAKER_H
#define GRPC_CORE_LIB_SECURITY_TRANSPORT_SECURITY_HANDSHAKER_H
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/security/transport/security_connector.h"
/// Creates any necessary security handshakers and adds them to
/// \a handshake_mgr.
void grpc_security_add_handshakers(grpc_exec_ctx *exec_ctx,
tsi_handshaker *handshaker,
grpc_security_connector *connector,
grpc_handshake_manager *handshake_mgr);
/// Creates a security handshaker using \a handshaker.
grpc_handshaker *grpc_security_handshaker_create(
grpc_exec_ctx *exec_ctx, tsi_handshaker *handshaker,
grpc_security_connector *connector);
#endif /* GRPC_CORE_LIB_SECURITY_TRANSPORT_SECURITY_HANDSHAKER_H */

Loading…
Cancel
Save