blob: 98dcd1c0ca66a868556caadc387e733751d67362 [file] [log] [blame]
Craig Tillerabd20f32015-12-13 11:48:59 -08001/*
2 *
Craig Tiller19fa5402016-02-23 08:19:39 -08003 * Copyright 2015-2016, Google Inc.
Craig Tillerabd20f32015-12-13 11:48:59 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include <string.h>
35
36#include <grpc/grpc.h>
37#include <grpc/grpc_security.h>
38#include <grpc/support/log.h>
39#include <grpc/support/useful.h>
40
Craig Tiller9533d042016-03-25 17:11:06 -070041#include "src/core/lib/transport/chttp2/alpn.h"
Craig Tiller732a8752016-02-22 15:59:19 -080042#include "test/core/bad_ssl/server_common.h"
Craig Tillerabd20f32015-12-13 11:48:59 -080043#include "test/core/end2end/data/ssl_test_data.h"
44
Craig Tiller172895c2015-12-14 15:23:46 -080045/* This test starts a server that is configured to advertise (via alpn and npn)
46 * a protocol that the connecting client does not support. It does this by
47 * overriding the functions declared in alpn.c from the core library. */
48
Craig Tiller3a186e72015-12-14 16:01:41 -080049static const char *const fake_versions[] = {"not-h2"};
Craig Tillerabd20f32015-12-13 11:48:59 -080050
51int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size) {
52 size_t i;
53 for (i = 0; i < GPR_ARRAY_SIZE(fake_versions); i++) {
54 if (!strncmp(version, fake_versions[i], size)) return 1;
55 }
56 return 0;
57}
58
59size_t grpc_chttp2_num_alpn_versions(void) {
60 return GPR_ARRAY_SIZE(fake_versions);
61}
62
63const char *grpc_chttp2_get_alpn_version_index(size_t i) {
64 GPR_ASSERT(i < GPR_ARRAY_SIZE(fake_versions));
65 return fake_versions[i];
66}
67
68int main(int argc, char **argv) {
69 const char *addr = bad_ssl_addr(argc, argv);
70 grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {test_server1_key,
71 test_server1_cert};
Craig Tiller7d408482015-12-14 15:12:34 -080072 grpc_server_credentials *ssl_creds;
73 grpc_server *server;
Craig Tillerabd20f32015-12-13 11:48:59 -080074
Craig Tiller7d408482015-12-14 15:12:34 -080075 grpc_init();
76 ssl_creds =
77 grpc_ssl_server_credentials_create(NULL, &pem_key_cert_pair, 1, 0, NULL);
Craig Tillerabd20f32015-12-13 11:48:59 -080078 server = grpc_server_create(NULL, NULL);
79 GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, ssl_creds));
80 grpc_server_credentials_release(ssl_creds);
81
82 bad_ssl_run(server);
83 grpc_shutdown();
84
85 return 0;
86}