• 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 <grpc/credentials.h>
20 #include <grpc/grpc.h>
21 #include <grpc/grpc_security.h>
22 #include <grpc/slice.h>
23 
24 #include "absl/log/check.h"
25 #include "src/core/lib/iomgr/error.h"
26 #include "test/core/bad_ssl/server_common.h"
27 #include "test/core/test_util/tls_utils.h"
28 
29 // This server will present an untrusted cert to the connecting client,
30 // causing the SSL handshake to fail
31 
main(int argc,char ** argv)32 int main(int argc, char** argv) {
33   const char* addr = bad_ssl_addr(argc, argv);
34   grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
35   grpc_server_credentials* ssl_creds;
36   grpc_server* server;
37 
38   grpc_init();
39 
40   std::string cert = grpc_core::testing::GetFileContents(
41       "src/core/tsi/test_creds/badserver.pem");
42   std::string key = grpc_core::testing::GetFileContents(
43       "src/core/tsi/test_creds/badserver.key");
44   pem_key_cert_pair.private_key = key.c_str();
45   pem_key_cert_pair.cert_chain = cert.c_str();
46 
47   ssl_creds = grpc_ssl_server_credentials_create(nullptr, &pem_key_cert_pair, 1,
48                                                  0, nullptr);
49   server = grpc_server_create(nullptr, nullptr);
50   CHECK(grpc_server_add_http2_port(server, addr, ssl_creds));
51   grpc_server_credentials_release(ssl_creds);
52 
53   bad_ssl_run(server);
54   grpc_shutdown();
55 
56   return 0;
57 }
58