diff options
author | jboeuf <jboeuf@users.noreply.github.com> | 2015-02-25 12:26:53 -0800 |
---|---|---|
committer | jboeuf <jboeuf@users.noreply.github.com> | 2015-02-25 12:26:53 -0800 |
commit | 3a0e41c28d4677437a6601f69c0f8c2168b70afd (patch) | |
tree | 2f0ea5e852b57b1550d1f2a50100d8c14454873b /src | |
parent | ad6017751913a701a840e78661e63cdbde25de98 (diff) | |
parent | deb49dd1aa4a12003cc445f08b55f3f95859fe67 (diff) |
Merge pull request #801 from ctiller/sec-wtf
Strip port in peer name check
Diffstat (limited to 'src')
-rw-r--r-- | src/core/security/security_context.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c index 60064dc83d..0dc37fa73c 100644 --- a/src/core/security/security_context.c +++ b/src/core/security/security_context.c @@ -338,6 +338,24 @@ static grpc_security_status ssl_server_create_handshaker( return ssl_create_handshaker(c->handshaker_factory, 0, NULL, handshaker); } +static int ssl_host_matches_name(const tsi_peer *peer, + const char *peer_name) { + char *allocated_name = NULL; + int r; + + if (strchr(peer_name, ':') != NULL) { + char *ignored_port; + gpr_split_host_port(peer_name, &allocated_name, &ignored_port); + gpr_free(ignored_port); + peer_name = allocated_name; + if (!peer_name) return 0; + } + + r = tsi_ssl_peer_matches_name(peer, peer_name); + gpr_free(allocated_name); + return r; +} + static grpc_security_status ssl_check_peer(const char *peer_name, const tsi_peer *peer) { /* Check the ALPN. */ @@ -359,10 +377,11 @@ static grpc_security_status ssl_check_peer(const char *peer_name, /* Check the peer name if specified. */ if (peer_name != NULL && - !tsi_ssl_peer_matches_name(peer, peer_name)) { + !ssl_host_matches_name(peer, peer_name)) { gpr_log(GPR_ERROR, "Peer name %s is not in peer certificate", peer_name); return GRPC_SECURITY_ERROR; } + return GRPC_SECURITY_OK; } @@ -398,7 +417,7 @@ static grpc_security_status ssl_channel_check_call_host( grpc_ssl_channel_security_context *c = (grpc_ssl_channel_security_context *)ctx; - if (tsi_ssl_peer_matches_name(&c->peer, host)) return GRPC_SECURITY_OK; + if (ssl_host_matches_name(&c->peer, host)) return GRPC_SECURITY_OK; /* If the target name was overridden, then the original target_name was 'checked' transitively during the previous peer check at the end of the |