• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <string.h>
20 
21 #include <grpc/grpc.h>
22 #include <grpc/grpc_security.h>
23 #include <grpc/support/log.h>
24 
25 #include "src/core/ext/transport/chttp2/alpn/alpn.h"
26 #include "src/core/lib/gpr/useful.h"
27 #include "test/core/bad_ssl/server_common.h"
28 #include "test/core/end2end/data/ssl_test_data.h"
29 
30 /* This test starts a server that is configured to advertise (via alpn and npn)
31  * a protocol that the connecting client does not support. It does this by
32  * overriding the functions declared in alpn.c from the core library. */
33 
34 static const char* const fake_versions[] = {"not-h2"};
35 
grpc_chttp2_is_alpn_version_supported(const char * version,size_t size)36 int grpc_chttp2_is_alpn_version_supported(const char* version, size_t size) {
37   size_t i;
38   for (i = 0; i < GPR_ARRAY_SIZE(fake_versions); i++) {
39     if (!strncmp(version, fake_versions[i], size)) return 1;
40   }
41   return 0;
42 }
43 
grpc_chttp2_num_alpn_versions(void)44 size_t grpc_chttp2_num_alpn_versions(void) {
45   return GPR_ARRAY_SIZE(fake_versions);
46 }
47 
grpc_chttp2_get_alpn_version_index(size_t i)48 const char* grpc_chttp2_get_alpn_version_index(size_t i) {
49   GPR_ASSERT(i < GPR_ARRAY_SIZE(fake_versions));
50   return fake_versions[i];
51 }
52 
main(int argc,char ** argv)53 int main(int argc, char** argv) {
54   const char* addr = bad_ssl_addr(argc, argv);
55   grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {test_server1_key,
56                                                   test_server1_cert};
57   grpc_server_credentials* ssl_creds;
58   grpc_server* server;
59 
60   grpc_init();
61   ssl_creds = grpc_ssl_server_credentials_create(nullptr, &pem_key_cert_pair, 1,
62                                                  0, nullptr);
63   server = grpc_server_create(nullptr, nullptr);
64   GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, ssl_creds));
65   grpc_server_credentials_release(ssl_creds);
66 
67   bad_ssl_run(server);
68   grpc_shutdown();
69 
70   return 0;
71 }
72