blob: 69651700feb8429a024e29075bbadadee82845cf [file] [log] [blame]
yang-g7d2a3e12016-02-18 15:41:56 -08001
2/*
3 *
4 * Copyright 2016, Google Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following disclaimer
15 * in the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Google Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35#include "test/cpp/util/test_credentials_provider.h"
36
37#include "test/core/end2end/data/ssl_test_data.h"
38
39namespace grpc {
40namespace testing {
41
42std::shared_ptr<ChannelCredentials> GetChannelCredentials(
yang-g17197dd2016-02-19 00:04:22 -080043 const grpc::string& type, ChannelArguments* args) {
44 if (type == kInsecureCredentialsType) {
yang-g7d2a3e12016-02-18 15:41:56 -080045 return InsecureChannelCredentials();
yang-g17197dd2016-02-19 00:04:22 -080046 } else if (type == kTlsCredentialsType) {
yang-g7d2a3e12016-02-18 15:41:56 -080047 SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
48 args->SetSslTargetNameOverride("foo.test.google.fr");
49 return SslCredentials(ssl_opts);
50 } else {
yang-g17197dd2016-02-19 00:04:22 -080051 gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
yang-g7d2a3e12016-02-18 15:41:56 -080052 }
53 return nullptr;
54}
55
56std::shared_ptr<ServerCredentials> GetServerCredentials(
yang-g17197dd2016-02-19 00:04:22 -080057 const grpc::string& type) {
58 if (type == kInsecureCredentialsType) {
yang-g7d2a3e12016-02-18 15:41:56 -080059 return InsecureServerCredentials();
yang-g17197dd2016-02-19 00:04:22 -080060 } else if (type == kTlsCredentialsType) {
yang-g7d2a3e12016-02-18 15:41:56 -080061 SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key,
62 test_server1_cert};
63 SslServerCredentialsOptions ssl_opts;
64 ssl_opts.pem_root_certs = "";
65 ssl_opts.pem_key_cert_pairs.push_back(pkcp);
66 return SslServerCredentials(ssl_opts);
67 } else {
yang-g17197dd2016-02-19 00:04:22 -080068 gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
yang-g7d2a3e12016-02-18 15:41:56 -080069 }
70 return nullptr;
71}
72
yang-g4c8aed32016-02-19 00:19:39 -080073std::vector<grpc::string> GetSecureCredentialsTypeList() {
74 std::vector<grpc::string> types;
75 types.push_back(kTlsCredentialsType);
76 return types;
77}
78
yang-g7d2a3e12016-02-18 15:41:56 -080079} // namespace testing
80} // namespace grpc