yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 1 | |
| 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 | |
| 39 | namespace grpc { |
| 40 | namespace testing { |
| 41 | |
| 42 | std::shared_ptr<ChannelCredentials> GetChannelCredentials( |
yang-g | 17197dd | 2016-02-19 00:04:22 -0800 | [diff] [blame] | 43 | const grpc::string& type, ChannelArguments* args) { |
| 44 | if (type == kInsecureCredentialsType) { |
yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 45 | return InsecureChannelCredentials(); |
yang-g | 17197dd | 2016-02-19 00:04:22 -0800 | [diff] [blame] | 46 | } else if (type == kTlsCredentialsType) { |
yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 47 | SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; |
| 48 | args->SetSslTargetNameOverride("foo.test.google.fr"); |
| 49 | return SslCredentials(ssl_opts); |
| 50 | } else { |
yang-g | 17197dd | 2016-02-19 00:04:22 -0800 | [diff] [blame] | 51 | gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); |
yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 52 | } |
| 53 | return nullptr; |
| 54 | } |
| 55 | |
| 56 | std::shared_ptr<ServerCredentials> GetServerCredentials( |
yang-g | 17197dd | 2016-02-19 00:04:22 -0800 | [diff] [blame] | 57 | const grpc::string& type) { |
| 58 | if (type == kInsecureCredentialsType) { |
yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 59 | return InsecureServerCredentials(); |
yang-g | 17197dd | 2016-02-19 00:04:22 -0800 | [diff] [blame] | 60 | } else if (type == kTlsCredentialsType) { |
yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 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 { |
yang-g | 17197dd | 2016-02-19 00:04:22 -0800 | [diff] [blame] | 68 | gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); |
yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 69 | } |
| 70 | return nullptr; |
| 71 | } |
| 72 | |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame^] | 73 | std::vector<grpc::string> GetSecureCredentialsTypeList() { |
| 74 | std::vector<grpc::string> types; |
| 75 | types.push_back(kTlsCredentialsType); |
| 76 | return types; |
| 77 | } |
| 78 | |
yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 79 | } // namespace testing |
| 80 | } // namespace grpc |