Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | // Copyright 2015 gRPC authors. |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 4 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 8 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 10 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 16 | |
| 17 | #endregion |
| 18 | |
| 19 | using System; |
| 20 | using System.Collections.Generic; |
| 21 | using System.Diagnostics; |
| 22 | using System.IO; |
Jan Tattermusch | 10e85f1 | 2016-04-09 13:16:37 -0700 | [diff] [blame] | 23 | using System.Reflection; |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 24 | using System.Text.RegularExpressions; |
| 25 | using System.Threading.Tasks; |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 26 | using Grpc.Core; |
| 27 | using Grpc.Core.Utils; |
| 28 | using NUnit.Framework; |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 29 | |
| 30 | namespace Grpc.IntegrationTesting |
| 31 | { |
| 32 | /// <summary> |
| 33 | /// SSL Credentials for testing. |
| 34 | /// </summary> |
| 35 | public static class TestCredentials |
| 36 | { |
| 37 | public const string DefaultHostOverride = "foo.test.google.fr"; |
| 38 | |
Jan Tattermusch | b323608 | 2016-04-08 17:08:57 -0700 | [diff] [blame] | 39 | public static string ClientCertAuthorityPath |
| 40 | { |
| 41 | get |
| 42 | { |
| 43 | return GetPath("data/ca.pem"); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public static string ServerCertChainPath |
| 48 | { |
| 49 | get |
| 50 | { |
| 51 | return GetPath("data/server1.pem"); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | public static string ServerPrivateKeyPath |
| 56 | { |
| 57 | get |
| 58 | { |
| 59 | return GetPath("data/server1.key"); |
| 60 | } |
| 61 | } |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 62 | |
Jan Tattermusch | beffc77 | 2015-10-22 13:28:22 -0700 | [diff] [blame] | 63 | public static SslCredentials CreateSslCredentials() |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 64 | { |
Jan Tattermusch | beffc77 | 2015-10-22 13:28:22 -0700 | [diff] [blame] | 65 | return new SslCredentials(File.ReadAllText(ClientCertAuthorityPath)); |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Jan Tattermusch | beffc77 | 2015-10-22 13:28:22 -0700 | [diff] [blame] | 68 | public static SslServerCredentials CreateSslServerCredentials() |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 69 | { |
| 70 | var keyCertPair = new KeyCertificatePair( |
| 71 | File.ReadAllText(ServerCertChainPath), |
| 72 | File.ReadAllText(ServerPrivateKeyPath)); |
Jan Tattermusch | eea5955 | 2015-07-23 22:05:32 -0700 | [diff] [blame] | 73 | return new SslServerCredentials(new[] { keyCertPair }); |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 74 | } |
Jan Tattermusch | b323608 | 2016-04-08 17:08:57 -0700 | [diff] [blame] | 75 | |
| 76 | private static string GetPath(string relativePath) |
| 77 | { |
Jan Tattermusch | 317b8ac | 2016-06-16 09:36:11 -0700 | [diff] [blame] | 78 | var assemblyDir = Path.GetDirectoryName(typeof(TestCredentials).GetTypeInfo().Assembly.Location); |
Jan Tattermusch | 10e85f1 | 2016-04-09 13:16:37 -0700 | [diff] [blame] | 79 | return Path.Combine(assemblyDir, relativePath); |
Jan Tattermusch | b323608 | 2016-04-08 17:08:57 -0700 | [diff] [blame] | 80 | } |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 81 | } |
| 82 | } |