Craig Tiller | abd20f3 | 2015-12-13 11:48:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | abd20f3 | 2015-12-13 11:48:59 -0800 | [diff] [blame] | 4 | * 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 Tiller | c7762a8 | 2016-03-28 10:13:08 -0700 | [diff] [blame] | 41 | #include "src/core/ext/transport/chttp2/transport/alpn.h" |
Craig Tiller | 732a875 | 2016-02-22 15:59:19 -0800 | [diff] [blame] | 42 | #include "test/core/bad_ssl/server_common.h" |
Craig Tiller | abd20f3 | 2015-12-13 11:48:59 -0800 | [diff] [blame] | 43 | #include "test/core/end2end/data/ssl_test_data.h" |
| 44 | |
Craig Tiller | 172895c | 2015-12-14 15:23:46 -0800 | [diff] [blame] | 45 | /* 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 Tiller | 3a186e7 | 2015-12-14 16:01:41 -0800 | [diff] [blame] | 49 | static const char *const fake_versions[] = {"not-h2"}; |
Craig Tiller | abd20f3 | 2015-12-13 11:48:59 -0800 | [diff] [blame] | 50 | |
| 51 | int 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 | |
| 59 | size_t grpc_chttp2_num_alpn_versions(void) { |
| 60 | return GPR_ARRAY_SIZE(fake_versions); |
| 61 | } |
| 62 | |
| 63 | const 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 | |
| 68 | int 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 Tiller | 7d40848 | 2015-12-14 15:12:34 -0800 | [diff] [blame] | 72 | grpc_server_credentials *ssl_creds; |
| 73 | grpc_server *server; |
Craig Tiller | abd20f3 | 2015-12-13 11:48:59 -0800 | [diff] [blame] | 74 | |
Craig Tiller | 7d40848 | 2015-12-14 15:12:34 -0800 | [diff] [blame] | 75 | grpc_init(); |
| 76 | ssl_creds = |
| 77 | grpc_ssl_server_credentials_create(NULL, &pem_key_cert_pair, 1, 0, NULL); |
Craig Tiller | abd20f3 | 2015-12-13 11:48:59 -0800 | [diff] [blame] | 78 | 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 | } |