server_ssl.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 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 <arpa/inet.h>
20 #include <string.h>
21 #include <sys/socket.h>
22 #include <unistd.h>
23 
24 #include <openssl/err.h>
25 #include <openssl/ssl.h>
26 
27 #include <grpc/grpc.h>
28 #include <grpc/grpc_security.h>
29 #include <grpc/support/alloc.h>
30 #include <grpc/support/log.h>
32 #include <grpc/support/sync.h>
33 
36 #include "test/core/util/port.h"
38 
39 int main(int argc, char* argv[]) {
41  // Handshake succeeeds when the client supplies the standard ALPN list.
42  const char* full_alpn_list[] = {"grpc-exp", "h2"};
43  GPR_ASSERT(server_ssl_test(full_alpn_list, 2, "grpc-exp"));
44  // Handshake succeeeds when the client supplies only h2 as the ALPN list. This
45  // covers legacy gRPC clients which don't support grpc-exp.
46  const char* h2_only_alpn_list[] = {"h2"};
47  GPR_ASSERT(server_ssl_test(h2_only_alpn_list, 1, "h2"));
48  // Handshake succeeds when the client supplies superfluous ALPN entries and
49  // also when h2 precedes gprc-exp.
50  const char* extra_alpn_list[] = {"foo", "h2", "bar", "grpc-exp"};
51  GPR_ASSERT(server_ssl_test(extra_alpn_list, 4, "h2"));
52  // Handshake fails when the client uses a fake protocol as its only ALPN
53  // preference. This validates the server is correctly validating ALPN
54  // and sanity checks the server_ssl_test.
55  const char* fake_alpn_list[] = {"foo"};
56  GPR_ASSERT(!server_ssl_test(fake_alpn_list, 1, "foo"));
58  return 0;
59 }
log.h
port.h
generate.env
env
Definition: generate.py:37
load_file.h
string.h
grpc_security.h
string_util.h
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
main
int main(int argc, char *argv[])
Definition: server_ssl.cc:39
grpc.h
err.h
ssl.h
test_config.h
alloc.h
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
server_ssl_common.h
server_ssl_test
bool server_ssl_test(const char *alpn_list[], unsigned int alpn_list_len, const char *alpn_expected)
Definition: server_ssl_common.cc:170
sync.h
CleanupSslLibrary
void CleanupSslLibrary()
Definition: server_ssl_common.cc:283


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:17