blob: f8380cdb65a47bf2ded0c2f41a88537fd62e7208 [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(
43 const grpc::string& type, ChannelArguments* args) {
44 if (type == kInsecureCredentialsType) {
45 return InsecureChannelCredentials();
46 } else if (type == kTlsCredentialsType) {
47 SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
48 args->SetSslTargetNameOverride("foo.test.google.fr");
49 return SslCredentials(ssl_opts);
50 } else {
51 gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
52 }
53 return nullptr;
54}
55
56std::shared_ptr<ServerCredentials> GetServerCredentials(
57 const grpc::string& type) {
58 if (type == kInsecureCredentialsType) {
59 return InsecureServerCredentials();
60 } else if (type == kTlsCredentialsType) {
61 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 {
68 gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
69 }
70 return nullptr;
71}
72
73} // namespace testing
74} // namespace grpc